Merge branch 'feature/json_pointer_contains' into develop
This commit is contained in:
		
						commit
						104c5c1996
					
				
					 7 changed files with 338 additions and 23 deletions
				
			
		|  | @ -90,12 +90,18 @@ TEST_CASE("JSON pointers") | |||
|             // the whole document
 | ||||
|             CHECK(j[json::json_pointer()] == j); | ||||
|             CHECK(j[json::json_pointer("")] == j); | ||||
|             CHECK(j.contains(json::json_pointer())); | ||||
|             CHECK(j.contains(json::json_pointer(""))); | ||||
| 
 | ||||
|             // array access
 | ||||
|             CHECK(j[json::json_pointer("/foo")] == j["foo"]); | ||||
|             CHECK(j.contains(json::json_pointer("/foo"))); | ||||
|             CHECK(j[json::json_pointer("/foo/0")] == j["foo"][0]); | ||||
|             CHECK(j[json::json_pointer("/foo/1")] == j["foo"][1]); | ||||
|             CHECK(j["/foo/1"_json_pointer] == j["foo"][1]); | ||||
|             CHECK(j.contains(json::json_pointer("/foo/0"))); | ||||
|             CHECK(j.contains(json::json_pointer("/foo/1"))); | ||||
|             CHECK(not j.contains(json::json_pointer("/foo/-"))); | ||||
| 
 | ||||
|             // checked array access
 | ||||
|             CHECK(j.at(json::json_pointer("/foo/0")) == j["foo"][0]); | ||||
|  | @ -103,6 +109,8 @@ TEST_CASE("JSON pointers") | |||
| 
 | ||||
|             // empty string access
 | ||||
|             CHECK(j[json::json_pointer("/")] == j[""]); | ||||
|             CHECK(j.contains(json::json_pointer(""))); | ||||
|             CHECK(j.contains(json::json_pointer("/"))); | ||||
| 
 | ||||
|             // other cases
 | ||||
|             CHECK(j[json::json_pointer("/ ")] == j[" "]); | ||||
|  | @ -112,6 +120,14 @@ TEST_CASE("JSON pointers") | |||
|             CHECK(j[json::json_pointer("/i\\j")] == j["i\\j"]); | ||||
|             CHECK(j[json::json_pointer("/k\"l")] == j["k\"l"]); | ||||
| 
 | ||||
|             // contains
 | ||||
|             CHECK(j.contains(json::json_pointer("/ "))); | ||||
|             CHECK(j.contains(json::json_pointer("/c%d"))); | ||||
|             CHECK(j.contains(json::json_pointer("/e^f"))); | ||||
|             CHECK(j.contains(json::json_pointer("/g|h"))); | ||||
|             CHECK(j.contains(json::json_pointer("/i\\j"))); | ||||
|             CHECK(j.contains(json::json_pointer("/k\"l"))); | ||||
| 
 | ||||
|             // checked access
 | ||||
|             CHECK(j.at(json::json_pointer("/ ")) == j[" "]); | ||||
|             CHECK(j.at(json::json_pointer("/c%d")) == j["c%d"]); | ||||
|  | @ -123,14 +139,24 @@ TEST_CASE("JSON pointers") | |||
|             // escaped access
 | ||||
|             CHECK(j[json::json_pointer("/a~1b")] == j["a/b"]); | ||||
|             CHECK(j[json::json_pointer("/m~0n")] == j["m~n"]); | ||||
|             CHECK(j.contains(json::json_pointer("/a~1b"))); | ||||
|             CHECK(j.contains(json::json_pointer("/m~0n"))); | ||||
| 
 | ||||
|             // unescaped access
 | ||||
|             // access to nonexisting values yield object creation
 | ||||
|             CHECK(not j.contains(json::json_pointer("/a/b"))); | ||||
|             CHECK_NOTHROW(j[json::json_pointer("/a/b")] = 42); | ||||
|             CHECK(j.contains(json::json_pointer("/a/b"))); | ||||
|             CHECK(j["a"]["b"] == json(42)); | ||||
| 
 | ||||
|             CHECK(not j.contains(json::json_pointer("/a/c/1"))); | ||||
|             CHECK_NOTHROW(j[json::json_pointer("/a/c/1")] = 42); | ||||
|             CHECK(j["a"]["c"] == json({nullptr, 42})); | ||||
|             CHECK(j.contains(json::json_pointer("/a/c/1"))); | ||||
| 
 | ||||
|             CHECK(not j.contains(json::json_pointer("/a/d/-"))); | ||||
|             CHECK_NOTHROW(j[json::json_pointer("/a/d/-")] = 42); | ||||
|             CHECK(not j.contains(json::json_pointer("/a/d/-"))); | ||||
|             CHECK(j["a"]["d"] == json::array({42})); | ||||
|             // "/a/b" works for JSON {"a": {"b": 42}}
 | ||||
|             CHECK(json({{"a", {{"b", 42}}}})[json::json_pointer("/a/b")] == json(42)); | ||||
|  | @ -143,6 +169,7 @@ TEST_CASE("JSON pointers") | |||
|             CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), json::out_of_range&); | ||||
|             CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer), | ||||
|                               "[json.exception.out_of_range.404] unresolved reference token 'foo'"); | ||||
|             CHECK(not j_primitive.contains(json::json_pointer("/foo"))); | ||||
|         } | ||||
| 
 | ||||
|         SECTION("const access") | ||||
|  | @ -233,11 +260,16 @@ TEST_CASE("JSON pointers") | |||
| 
 | ||||
|             // the whole document
 | ||||
|             CHECK(j[""_json_pointer] == j); | ||||
|             CHECK(j.contains(""_json_pointer)); | ||||
| 
 | ||||
|             // array access
 | ||||
|             CHECK(j["/foo"_json_pointer] == j["foo"]); | ||||
|             CHECK(j["/foo/0"_json_pointer] == j["foo"][0]); | ||||
|             CHECK(j["/foo/1"_json_pointer] == j["foo"][1]); | ||||
|             CHECK(j.contains("/foo"_json_pointer)); | ||||
|             CHECK(j.contains("/foo/0"_json_pointer)); | ||||
|             CHECK(j.contains("/foo/1"_json_pointer)); | ||||
|             CHECK(not j.contains("/foo/-"_json_pointer)); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -278,6 +310,12 @@ TEST_CASE("JSON pointers") | |||
|             CHECK_THROWS_AS(j_const.at("/01"_json_pointer), json::parse_error&); | ||||
|             CHECK_THROWS_WITH(j_const.at("/01"_json_pointer), | ||||
|                               "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"); | ||||
|             CHECK_THROWS_AS(j.contains("/01"_json_pointer), json::parse_error&); | ||||
|             CHECK_THROWS_WITH(j.contains("/01"_json_pointer), | ||||
|                               "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"); | ||||
|             CHECK_THROWS_AS(j_const.contains("/01"_json_pointer), json::parse_error&); | ||||
|             CHECK_THROWS_WITH(j_const.contains("/01"_json_pointer), | ||||
|                               "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"); | ||||
| 
 | ||||
|             // error with incorrect numbers
 | ||||
|             CHECK_THROWS_AS(j["/one"_json_pointer] = 1, json::parse_error&); | ||||
|  | @ -294,6 +332,13 @@ TEST_CASE("JSON pointers") | |||
|             CHECK_THROWS_WITH(j_const.at("/one"_json_pointer) == 1, | ||||
|                               "[json.exception.parse_error.109] parse error: array index 'one' is not a number"); | ||||
| 
 | ||||
|             CHECK_THROWS_AS(j.contains("/one"_json_pointer), json::parse_error&); | ||||
|             CHECK_THROWS_WITH(j.contains("/one"_json_pointer), | ||||
|                               "[json.exception.parse_error.109] parse error: array index 'one' is not a number"); | ||||
|             CHECK_THROWS_AS(j_const.contains("/one"_json_pointer), json::parse_error&); | ||||
|             CHECK_THROWS_WITH(j_const.contains("/one"_json_pointer), | ||||
|                               "[json.exception.parse_error.109] parse error: array index 'one' is not a number"); | ||||
| 
 | ||||
|             CHECK_THROWS_AS(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(), json::parse_error&); | ||||
|             CHECK_THROWS_WITH(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(), | ||||
|             "[json.exception.parse_error.109] parse error: array index 'three' is not a number"); | ||||
|  | @ -306,6 +351,7 @@ TEST_CASE("JSON pointers") | |||
|             CHECK_THROWS_AS(j_const["/-"_json_pointer], json::out_of_range&); | ||||
|             CHECK_THROWS_WITH(j_const["/-"_json_pointer], | ||||
|                               "[json.exception.out_of_range.402] array index '-' (3) is out of range"); | ||||
|             CHECK(not j_const.contains("/-"_json_pointer)); | ||||
| 
 | ||||
|             // error when using "-" with at
 | ||||
|             CHECK_THROWS_AS(j.at("/-"_json_pointer), json::out_of_range&); | ||||
|  | @ -314,6 +360,7 @@ TEST_CASE("JSON pointers") | |||
|             CHECK_THROWS_AS(j_const.at("/-"_json_pointer), json::out_of_range&); | ||||
|             CHECK_THROWS_WITH(j_const.at("/-"_json_pointer), | ||||
|                               "[json.exception.out_of_range.402] array index '-' (3) is out of range"); | ||||
|             CHECK(not j_const.contains("/-"_json_pointer)); | ||||
|         } | ||||
| 
 | ||||
|         SECTION("const access") | ||||
|  | @ -329,11 +376,13 @@ TEST_CASE("JSON pointers") | |||
|             CHECK_THROWS_AS(j.at("/3"_json_pointer), json::out_of_range&); | ||||
|             CHECK_THROWS_WITH(j.at("/3"_json_pointer), | ||||
|                               "[json.exception.out_of_range.401] array index 3 is out of range"); | ||||
|             CHECK(not j.contains("/3"_json_pointer)); | ||||
| 
 | ||||
|             // assign to nonexisting index (with gap)
 | ||||
|             CHECK_THROWS_AS(j.at("/5"_json_pointer), json::out_of_range&); | ||||
|             CHECK_THROWS_WITH(j.at("/5"_json_pointer), | ||||
|                               "[json.exception.out_of_range.401] array index 5 is out of range"); | ||||
|             CHECK(not j.contains("/5"_json_pointer)); | ||||
| 
 | ||||
|             // assign to "-"
 | ||||
|             CHECK_THROWS_AS(j["/-"_json_pointer], json::out_of_range&); | ||||
|  | @ -342,8 +391,8 @@ TEST_CASE("JSON pointers") | |||
|             CHECK_THROWS_AS(j.at("/-"_json_pointer), json::out_of_range&); | ||||
|             CHECK_THROWS_WITH(j.at("/-"_json_pointer), | ||||
|                               "[json.exception.out_of_range.402] array index '-' (3) is out of range"); | ||||
|             CHECK(not j.contains("/-"_json_pointer)); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     SECTION("flatten") | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue