Skip to content

Commit 3f9b035

Browse files
committed
Improve test coverage.
1 parent de917ac commit 3f9b035

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

include/tao/json/value.hh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ namespace tao
315315
destroy();
316316
unsafe_assign( t );
317317
}
318+
319+
void operator= ( const char * s )
320+
{
321+
destroy();
322+
unsafe_assign( s );
323+
}
324+
318325
void operator= ( std::string && s ) noexcept
319326
{
320327
destroy();
@@ -758,6 +765,18 @@ namespace tao
758765
new ( & m_union.s ) std::string( std::move( s ) );
759766
}
760767

768+
void unsafe_assign( const char * s )
769+
{
770+
m_type = json::type::STRING;
771+
new ( & m_union.s ) std::string( s );
772+
}
773+
774+
void unsafe_assign( const char * s, const std::size_t l )
775+
{
776+
m_type = json::type::STRING;
777+
new ( & m_union.s ) std::string( s, l );
778+
}
779+
761780
void unsafe_assign( const std::string & s )
762781
{
763782
m_type = json::type::STRING;
@@ -816,8 +835,6 @@ namespace tao
816835
// m_type = json::type::OBJECT;
817836
// }
818837

819-
820-
821838
private:
822839
value( const char ) = delete;
823840
value( const unsigned long ) = delete;
@@ -899,7 +916,7 @@ namespace tao
899916
new ( & m_union.o ) std::map< std::string, value >( std::move( r.m_union.o ) );
900917
return;
901918
}
902-
assert( false );
919+
assert( false ); // LCOV_EXCL_LINE
903920
}
904921

905922
void embed( const value & r )
@@ -921,7 +938,7 @@ namespace tao
921938
new ( & m_union.o ) std::map< std::string, value >( r.m_union.o );
922939
return;
923940
}
924-
assert( false );
941+
assert( false ); // LCOV_EXCL_LINE
925942
}
926943

927944
void destroy() noexcept
@@ -942,7 +959,7 @@ namespace tao
942959
m_union.o.~map();
943960
return;
944961
}
945-
assert( false );
962+
assert( false ); // LCOV_EXCL_LINE
946963
}
947964

948965
static void check_finite( const double d )

src/test/json/create.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,40 @@ namespace tao
267267
TEST_THROWS( v = b );
268268
TEST_THROWS( v = c );
269269

270+
v = nullptr;
271+
272+
TEST_ASSERT( v.type() == type::NULL_ );
273+
274+
v = true;
275+
276+
TEST_ASSERT( v.type() == type::BOOL_ );
277+
TEST_ASSERT( v.get_bool() );
278+
279+
v = 1;
280+
281+
TEST_ASSERT( v.type() == type::INT64 );
282+
TEST_ASSERT( v.get_int64() == 1 );
283+
284+
v = 2.0;
285+
286+
TEST_ASSERT( v.type() == type::DOUBLE );
287+
TEST_ASSERT( v.get_double() == 2.0 );
288+
289+
v = "hallo";
290+
291+
TEST_ASSERT( v.type() == type::STRING );
292+
TEST_ASSERT( v.get_string() == "hallo" );
293+
294+
v = std::vector< value >();
295+
296+
TEST_ASSERT( v.type() == type::ARRAY );
297+
TEST_ASSERT( v.get_array().empty() );
298+
299+
v = std::map< std::string, value >();
300+
301+
TEST_ASSERT( v.type() == type::OBJECT );
302+
TEST_ASSERT( v.get_object().empty() );
303+
270304
test_string( "" );
271305
test_string( "foo" );
272306
test_string( "abcdefghijklmnpqrstuvwxyz" );

0 commit comments

Comments
 (0)