Skip to content

Commit

Permalink
Improve test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinH committed Apr 2, 2024
1 parent a292fc5 commit 2614b21
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 76 deletions.
26 changes: 13 additions & 13 deletions include/tao/config/internal/function_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ namespace tao::config::internal
}
};

template<>
struct function_traits< std::vector< std::byte > >
{
[[nodiscard]] static std::vector< std::byte > get( array& f, const std::size_t i )
{
const entry& e = function_traits_entry( f, i );

if( e.is_binary() ) {
return e.get_binary();
}
throw pegtl::parse_error( "invalid type for binary argument", e.get_position() );
}
};
// template<>
// struct function_traits< std::vector< std::byte > >
// {
// [[nodiscard]] static std::vector< std::byte > get( array& f, const std::size_t i )
// {
// const entry& e = function_traits_entry( f, i );

// if( e.is_binary() ) {
// return e.get_binary();
// }
// throw pegtl::parse_error( "invalid type for binary argument", e.get_position() );
// }
// };

} // namespace tao::config::internal

Expand Down
58 changes: 4 additions & 54 deletions include/tao/config/internal/phase3_remove.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,6 @@ namespace tao::config::internal
inline void phase3_remove( array& a );
inline void phase3_remove( object& o );

[[nodiscard]] inline std::string phase3_partial_type( const entry& e )
{
switch( e.kind() ) {
case entry_kind::NULL_:
return "null";
case entry_kind::BOOLEAN:
return "boolean";
case entry_kind::STRING:
return "string";
case entry_kind::BINARY:
return "binary";
case entry_kind::SIGNED:
return "signed";
case entry_kind::UNSIGNED:
return "unsigned";
case entry_kind::DOUBLE:
return "double";
case entry_kind::ARRAY:
return "array";
case entry_kind::OBJECT:
return "object";
case entry_kind::ASTERISK:
throw std::logic_error( "code should be unreachable" ); // LCOV_EXCL_LINE
case entry_kind::REFERENCE:
throw std::logic_error( "code should be unreachable" ); // LCOV_EXCL_LINE
}
throw std::logic_error( "code should be unreachable" ); // LCOV_EXCL_LINE
}

[[nodiscard]] inline pegtl::position phase3_partial_position( const entry& e )
{
switch( e.kind() ) {
case entry_kind::NULL_:
case entry_kind::BOOLEAN:
case entry_kind::STRING:
case entry_kind::BINARY:
case entry_kind::SIGNED:
case entry_kind::UNSIGNED:
case entry_kind::DOUBLE:
case entry_kind::ARRAY:
case entry_kind::OBJECT:
return e.get_position();
case entry_kind::ASTERISK:
throw std::logic_error( "code should be unreachable" ); // LCOV_EXCL_LINE
case entry_kind::REFERENCE:
throw std::logic_error( "code should be unreachable" ); // LCOV_EXCL_LINE
}
throw std::logic_error( "code should be unreachable" ); // LCOV_EXCL_LINE
}

inline void phase3_remove( concat& c )
{
for( auto& e : c.concat ) {
Expand Down Expand Up @@ -100,11 +50,11 @@ namespace tao::config::internal
}
if( c.concat.size() > 1 ) {
auto i = c.concat.begin();
const auto lt = phase3_partial_type( *i );
const auto lp = phase3_partial_position( *i );
const auto lt = to_string( i->kind() );
const auto& lp = i->get_position();
++i;
const auto rt = phase3_partial_type( *i );
const auto rp = phase3_partial_position( *i );
const auto rt = to_string( i->kind() );
const auto& rp = i->get_position();
throw pegtl::parse_error( strcat( "incompatible types ", lt, "@", lp, " and ", rt, "@", rp ), c.position );
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/test/config/failure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ namespace tao
catch( const pegtl::parse_error_base& e ) {
std::cout << ansi_text << "pegtl::parse_error: " << ansi_message << e.message() << ": " << ansi_source << e.position_string() << ansi_reset << std::endl;
}
catch( const std::exception& e ) {
std::cout << "std::exception: " << e.what() << std::endl;
}
}

} // namespace tao
Expand Down
6 changes: 1 addition & 5 deletions src/test/config/success.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,10 @@ namespace tao::config
std::cerr << "Testcase '" << path << "' failed with exception '" << e.what() << "'" << std::endl;
++failed;
}
catch( const std::string& s ) {
std::cerr << "Testcase '" << path << "' failed with error '" << s << "'" << std::endl;
++failed;
}
// LCOV_EXCL_STOP
}

} // namespace tao
} // namespace tao::config

int main()
{
Expand Down
3 changes: 2 additions & 1 deletion src/test/config/to_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace tao::config
++failed;
// LCOV_EXCL_STOP
}
} {
}
{
std::ostringstream oss;
tao::config::to_stream( oss, parsed, 3 );
const std::string string2 = oss.str();
Expand Down
18 changes: 18 additions & 0 deletions tests/jaxn.jaxn
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
foo: [
null,
true,
false,
42,
$FF,
"foo",
{
a: null,
b: true,
c: false,
d: 42,
e: $FF,
f: "foo"
}
]
}
1 change: 1 addition & 0 deletions tests/jaxn.success
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo = (jaxn "[ null, true, false, 42, $ff, 'foo', { a: null, b: true, c: false, d: 42, e: $ff, f: 'foo' } ]")
1 change: 1 addition & 0 deletions tests/string_01.failure
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo = (split 42)
1 change: 1 addition & 0 deletions tests/string_02.failure
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo = (env $ff)

0 comments on commit 2614b21

Please sign in to comment.