Skip to content

Commit f0339e5

Browse files
committed
Add tests for object operators (+= and -=)
1 parent 6dcd174 commit f0339e5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/test/json/object_operators.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2015-2016 Dr. Colin Hirsch and Daniel Frey
2+
// Please see LICENSE for license or visit https://github.com/taocpp/json/
3+
4+
#include "test.hh"
5+
6+
#include <tao/json/from_string.hh>
7+
8+
namespace tao
9+
{
10+
namespace json
11+
{
12+
void unit_test()
13+
{
14+
value v = empty_object;
15+
TEST_ASSERT( v.get_object().size() == 0 );
16+
v += {};
17+
TEST_ASSERT( v.get_object().size() == 0 );
18+
v += { { "foo", 1 } };
19+
TEST_ASSERT( v.get_object().size() == 1 );
20+
v += { { "bar", 2 }, { "baz", 3 } };
21+
TEST_ASSERT( v.get_object().size() == 3 );
22+
TEST_THROWS( v += { { "foo", 42 } } );
23+
TEST_THROWS( v -= { "what?" } );
24+
v -= {};
25+
TEST_ASSERT( v.get_object().size() == 3 );
26+
v -= { "bar" };
27+
TEST_THROWS( v -= { "bar" } );
28+
TEST_ASSERT( v.get_object().size() == 2 );
29+
v -= { "foo", "baz" };
30+
TEST_ASSERT( v.get_object().size() == 0 );
31+
TEST_THROWS( v -= { "baz" } );
32+
}
33+
34+
} // json
35+
36+
} // tao
37+
38+
#include "main.hh"

0 commit comments

Comments
 (0)