Skip to content

Commit 36c4416

Browse files
committed
More tests.
1 parent d9cceb9 commit 36c4416

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

include/tao/json/internal/value_action.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ namespace tao
7373
{
7474
static void apply( const tao_json_pegtl::input & in, number_state & result )
7575
{
76-
if ( in.size() >= ( 1 << 30 ) ) {
77-
throw tao_json_pegtl::parse_error( "json number with 1 gigabyte digits", in );
76+
if ( in.size() > ( 1 << 20 ) ) {
77+
throw tao_json_pegtl::parse_error( "json number with 1 megabyte digits", in );
7878
}
7979
const auto c = std::min( in.size(), max_mantissa_digits );
8080
std::memcpy( result.mantissa + 1, in.begin(), c );

src/test/json/compare.cc

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ namespace tao
7171
TEST_ASSERT( false == f );
7272
}
7373

74-
void test_int64()
74+
template< typename N >
75+
void test_number()
7576
{
76-
value a( 42 );
77-
value b( 43 );
78-
value c( 43 );
77+
value a( N( 42 ) );
78+
value b( N( 43 ) );
79+
value c( N( 43 ) );
7980

8081
TEST_ASSERT( a < b );
8182
TEST_ASSERT( c > a );
@@ -95,8 +96,8 @@ namespace tao
9596
TEST_ASSERT( ! ( b <= a ) );
9697
TEST_ASSERT( ! ( a >= b ) );
9798

98-
TEST_ASSERT( a == 42 );
99-
TEST_ASSERT( 42 == a );
99+
TEST_ASSERT( a == N( 42 ) );
100+
TEST_ASSERT( N( 42 ) == a );
100101

101102
// TODO
102103
}
@@ -130,13 +131,38 @@ namespace tao
130131
TEST_ASSERT( "foo" == foo );
131132
}
132133

134+
void test_array()
135+
{
136+
value a = from_string( "[ 1, 2 ]" );
137+
value b = from_string( "[ 1, 3 ]" );
138+
139+
TEST_ASSERT( a.type() == type::ARRAY );
140+
TEST_ASSERT( b.type() == type::ARRAY );
141+
142+
TEST_ASSERT( a == a );
143+
TEST_ASSERT( a != b );
144+
TEST_ASSERT( a <= a );
145+
TEST_ASSERT( a <= b );
146+
TEST_ASSERT( a >= a );
147+
TEST_ASSERT( b >= a );
148+
TEST_ASSERT( a < b );
149+
TEST_ASSERT( b > a );
150+
TEST_ASSERT( ! ( a == b ) );
151+
TEST_ASSERT( ! ( a != a ) );
152+
TEST_ASSERT( ! ( a < a ) );
153+
TEST_ASSERT( ! ( b < a ) );
154+
TEST_ASSERT( ! ( a > a ) );
155+
TEST_ASSERT( ! ( a > b ) );
156+
}
157+
133158
void unit_test()
134159
{
135160
test_null();
136161
test_bool();
137-
test_int64();
162+
test_number< int64_t >();
163+
test_number< double >();
138164
test_string();
139-
// TODO
165+
test_array();
140166
}
141167

142168
} // json

src/test/json/double.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ namespace tao
127127
"7567186443383770486037861622771738545623065874679014086723327636718751234567890123456789012345678901"
128128
"e-308", 2.2250738585072014e-308 );
129129

130+
test_double( "30e001", 300.0 );
131+
130132
TEST_THROWS( from_string( "1.0e1234567890" ) );
133+
TEST_THROWS( from_string( std::string( 1048577, '1' ) ) );
131134
}
132135

133136
} // json

src/test/json/parse.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ namespace tao
77
{
88
namespace json
99
{
10+
void test_string()
11+
{
12+
TEST_ASSERT( from_string( "\"\"" ) == value( "" ) );
13+
14+
TEST_THROWS( from_string( "\"" ) );
15+
TEST_THROWS( from_string( "\"\r\n\"" ) );
16+
17+
// TODO...
18+
}
19+
1020
void test_array()
1121
{
1222
const auto v = from_string( "[ null, true, false, 42, 43.0, \"foo\", [ 1, 2, 3 ], { \"a\" : \"b\", \"c\" : \"d\" } ]" );
@@ -68,7 +78,6 @@ namespace tao
6878
TEST_ASSERT( from_string( "false" ) == value( false ) );
6979

7080
// TODO: test_int64()
71-
// TODO: test_string()
7281
test_array();
7382
test_object();
7483
}

0 commit comments

Comments
 (0)