Skip to content

Commit 4d62d67

Browse files
committed
Improve test coverage.
1 parent 3e3180c commit 4d62d67

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

include/tao/json/internal/grammar.hh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ namespace tao
5252
struct escaped_char : one< '"', '\\', '/', 'b', 'f', 'n', 'r', 't' > {};
5353
struct escaped : sor< escaped_char, unicode > {};
5454

55-
// struct unescaped : utf8::range< 0x20, 0x10FFFF > {};
56-
// struct unescaped : plus< not_at< one< '\\', '"' > >, utf8::range< 0x20, 0x10FFFF > > {};
57-
5855
struct unescaped
5956
{
6057
using analyze_t = analysis::generic< analysis::rule_type::ANY >;
@@ -75,7 +72,7 @@ namespace tao
7572
}
7673
return result;
7774
}
78-
return result;
75+
return result; // LCOV_EXCL_LINE -- The rest of the grammar prevents this line from ever being called.
7976
}
8077
};
8178

src/test/json/create.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ namespace tao
100100
void test_int64()
101101
{
102102
test_int64< T >( 0 );
103+
test_int64< T >( 42 );
103104
test_int64< T >( std::numeric_limits< T >::min() );
104105
test_int64< T >( std::numeric_limits< T >::max() );
105106
}
@@ -320,6 +321,28 @@ namespace tao
320321
test_array_1234();
321322

322323
TEST_ASSERT( value( { "foo", "bar", "baz" } ).is_array() );
324+
325+
TEST_THROWS( from_string( "1" ).emplace_back( 2 ) );
326+
TEST_THROWS( from_string( "1" ).emplace( "foo", value( 3 ) ) );
327+
{
328+
value a;
329+
a.emplace_back( 4 );
330+
TEST_ASSERT( a.type() == type::ARRAY );
331+
TEST_ASSERT( a[ 0 ] == 4 );
332+
value b( a );
333+
TEST_ASSERT( a.get_array() == b.get_array() );
334+
} {
335+
value a;
336+
a.emplace( "foo", value( 5 ) );
337+
TEST_ASSERT( a.type() == type::OBJECT );
338+
TEST_ASSERT( a[ "foo" ] == 5 );
339+
value b( a );
340+
TEST_ASSERT( a.get_object() == b.get_object() );
341+
} {
342+
const value a( "foo" );
343+
const value b( a );
344+
TEST_ASSERT( a.get_string() == b.get_string() );
345+
}
323346
}
324347

325348
} // json

src/test/json/double.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,24 @@ namespace tao
128128
"e-308", 2.2250738585072014e-308 );
129129

130130
test_double( "30e001", 300.0 );
131+
test_double( std::string( 2000, '1' ), std::numeric_limits< double >::max() );
131132

132133
TEST_THROWS( from_string( "1.0e1234567890" ) );
133134
TEST_THROWS( from_string( std::string( 1048577, '1' ) ) );
135+
136+
{
137+
const auto a = from_string( "42.0" ).as_number< double >();
138+
TEST_ASSERT( sizeof( a ) == sizeof( double ) );
139+
TEST_ASSERT( a == 42.0 );
140+
} {
141+
const auto a = from_string( "42.3" ).as_number< short >();
142+
TEST_ASSERT( sizeof( a ) == sizeof( short ) );
143+
TEST_ASSERT( a == 42 );
144+
} {
145+
const auto a = from_string( "42" ).as_number< double >();
146+
TEST_ASSERT( sizeof( a ) == sizeof( double ) );
147+
TEST_ASSERT( a == 42.0 );
148+
}
134149
}
135150

136151
} // json

0 commit comments

Comments
 (0)