Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
d01a6a46
Unverified
Commit
d01a6a46
authored
Mar 26, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚧
add overload for erase(std::string_view)
parent
16fb0cbb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
415 additions
and
31 deletions
+415
-31
json.hpp
include/nlohmann/json.hpp
+12
-5
json.hpp
single_include/nlohmann/json.hpp
+12
-5
unit-element_access2.cpp
test/src/unit-element_access2.cpp
+391
-21
No files found.
include/nlohmann/json.hpp
View file @
d01a6a46
...
...
@@ -3496,7 +3496,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyT
,
typename
std
::
enable_if
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
(
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
reference
at
(
KeyT
&&
key
)
...
...
@@ -3549,7 +3549,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyT
,
typename
std
::
enable_if
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
(
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
const_reference
at
(
KeyT
&&
key
)
const
...
...
@@ -3688,7 +3688,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyT
,
typename
std
::
enable_if
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
(
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
reference
operator
[](
KeyT
&&
key
)
...
...
@@ -3744,7 +3744,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyT
,
typename
std
::
enable_if
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
(
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
const_reference
operator
[](
KeyT
&&
key
)
const
...
...
@@ -4363,7 +4363,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
&&
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
size_type
erase
(
KeyT
&&
key
)
...
...
@@ -4377,6 +4377,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW
(
type_error
::
create
(
307
,
"cannot use erase() with "
+
std
::
string
(
type_name
()),
*
this
));
}
#if defined(JSON_HAS_CPP_17)
size_type
erase
(
std
::
string_view
key
)
{
return
erase
(
typename
object_t
::
key_type
(
key
.
data
(),
key
.
size
()));
}
#endif
/*!
@brief remove element from a JSON array given an index
...
...
single_include/nlohmann/json.hpp
View file @
d01a6a46
...
...
@@ -20385,7 +20385,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyT
,
typename
std
::
enable_if
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
(
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
reference
at
(
KeyT
&&
key
)
...
...
@@ -20438,7 +20438,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyT
,
typename
std
::
enable_if
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
(
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
const_reference
at
(
KeyT
&&
key
)
const
...
...
@@ -20577,7 +20577,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyT
,
typename
std
::
enable_if
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
(
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
reference
operator
[](
KeyT
&&
key
)
...
...
@@ -20633,7 +20633,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
template
<
class
KeyT
,
typename
std
::
enable_if
<
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
json_pointer
>::
value
&&
(
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
const_reference
operator
[](
KeyT
&&
key
)
const
...
...
@@ -21252,7 +21252,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
*/
template
<
class
KeyT
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyT
,
std
::
string_view
>::
value
||
!
std
::
is_same
<
typename
std
::
decay
<
KeyT
>::
type
,
std
::
string_view
>::
value
&&
#endif
std
::
is_convertible
<
KeyT
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
size_type
erase
(
KeyT
&&
key
)
...
...
@@ -21266,6 +21266,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
JSON_THROW
(
type_error
::
create
(
307
,
"cannot use erase() with "
+
std
::
string
(
type_name
()),
*
this
));
}
#if defined(JSON_HAS_CPP_17)
size_type
erase
(
std
::
string_view
key
)
{
return
erase
(
typename
object_t
::
key_type
(
key
.
data
(),
key
.
size
()));
}
#endif
/*!
@brief remove element from a JSON array given an index
...
...
test/src/unit-element_access2.cpp
View file @
d01a6a46
...
...
@@ -65,7 +65,7 @@ TEST_CASE("element access 2")
CHECK
(
j_const
.
at
(
"object"
)
==
json
::
object
());
CHECK
(
j_const
.
at
(
"array"
)
==
json
({
1
,
2
,
3
}));
#if
defined(JSON_HAS_CPP_17)
#if
def JSON_HAS_CPP_17
CHECK
(
j
.
at
(
std
::
string_view
(
"integer"
))
==
json
(
1
));
CHECK
(
j
.
at
(
std
::
string_view
(
"unsigned"
))
==
json
(
1u
));
CHECK
(
j
.
at
(
std
::
string_view
(
"boolean"
))
==
json
(
true
));
...
...
@@ -94,6 +94,15 @@ TEST_CASE("element access 2")
"[json.exception.out_of_range.403] key 'foo' not found"
);
CHECK_THROWS_WITH
(
j_const
.
at
(
"foo"
),
"[json.exception.out_of_range.403] key 'foo' not found"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j
.
at
(
std
::
string_view
(
"foo"
)),
json
::
out_of_range
&
);
CHECK_THROWS_AS
(
j_const
.
at
(
std
::
string_view
(
"foo"
)),
json
::
out_of_range
&
);
CHECK_THROWS_WITH
(
j
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.out_of_range.403] key 'foo' not found"
);
CHECK_THROWS_WITH
(
j_const
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.out_of_range.403] key 'foo' not found"
);
#endif
}
SECTION
(
"access on non-object type"
)
...
...
@@ -102,70 +111,126 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
null
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with null"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with null"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
at
(
std
::
string_view
(
std
::
string_view
(
"foo"
))),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
std
::
string_view
(
std
::
string_view
(
"foo"
))),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
std
::
string_view
(
std
::
string_view
(
"foo"
))),
"[json.exception.type_error.304] cannot use at() with null"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
std
::
string_view
(
std
::
string_view
(
"foo"
))),
"[json.exception.type_error.304] cannot use at() with null"
);
#endif
}
SECTION
(
"boolean"
)
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with boolean"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with boolean"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with boolean"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with boolean"
);
#endif
}
SECTION
(
"string"
)
{
json
j_nonobject
(
json
::
value_t
::
string
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with string"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with string"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with string"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with string"
);
#endif
}
SECTION
(
"array"
)
{
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with array"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with array"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with array"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with array"
);
#endif
}
SECTION
(
"number (integer)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with number"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with number"
);
#endif
}
SECTION
(
"number (unsigned)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_unsigned
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with number"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with number"
);
#endif
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"[json.exception.type_error.304] cannot use at() with number"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.304] cannot use at() with number"
);
#endif
}
}
}
...
...
@@ -200,6 +265,33 @@ TEST_CASE("element access 2")
CHECK
(
j_const
.
value
(
"floating"
,
12
)
==
42
);
CHECK
(
j_const
.
value
(
"object"
,
json
({{
"foo"
,
"bar"
}}))
==
json
::
object
());
CHECK
(
j_const
.
value
(
"array"
,
json
({
10
,
100
}))
==
json
({
1
,
2
,
3
}));
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
value
(
std
::
string_view
(
"integer"
),
2
)
==
1
);
CHECK
(
j
.
value
(
std
::
string_view
(
"integer"
),
1.0
)
==
Approx
(
1
));
CHECK
(
j
.
value
(
std
::
string_view
(
"unsigned"
),
2
)
==
1u
);
CHECK
(
j
.
value
(
std
::
string_view
(
"unsigned"
),
1.0
)
==
Approx
(
1u
));
CHECK
(
j
.
value
(
std
::
string_view
(
"null"
),
json
(
1
))
==
json
());
CHECK
(
j
.
value
(
std
::
string_view
(
"boolean"
),
false
)
==
true
);
CHECK
(
j
.
value
(
std
::
string_view
(
"string"
),
"bar"
)
==
"hello world"
);
CHECK
(
j
.
value
(
std
::
string_view
(
"string"
),
std
::
string
(
"bar"
))
==
"hello world"
);
CHECK
(
j
.
value
(
std
::
string_view
(
"floating"
),
12.34
)
==
Approx
(
42.23
));
CHECK
(
j
.
value
(
std
::
string_view
(
"floating"
),
12
)
==
42
);
CHECK
(
j
.
value
(
std
::
string_view
(
"object"
),
json
({{
"foo"
,
"bar"
}}))
==
json
::
object
());
CHECK
(
j
.
value
(
std
::
string_view
(
"array"
),
json
({
10
,
100
}))
==
json
({
1
,
2
,
3
}));
CHECK
(
j_const
.
value
(
std
::
string_view
(
"integer"
),
2
)
==
1
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"integer"
),
1.0
)
==
Approx
(
1
));
CHECK
(
j_const
.
value
(
std
::
string_view
(
"unsigned"
),
2
)
==
1u
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"unsigned"
),
1.0
)
==
Approx
(
1u
));
CHECK
(
j_const
.
value
(
std
::
string_view
(
"boolean"
),
false
)
==
true
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"string"
),
"bar"
)
==
"hello world"
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"string"
),
std
::
string
(
"bar"
))
==
"hello world"
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"floating"
),
12.34
)
==
Approx
(
42.23
));
CHECK
(
j_const
.
value
(
std
::
string_view
(
"floating"
),
12
)
==
42
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"object"
),
json
({{
"foo"
,
"bar"
}}))
==
json
::
object
());
CHECK
(
j_const
.
value
(
std
::
string_view
(
"array"
),
json
({
10
,
100
}))
==
json
({
1
,
2
,
3
}));
#endif
}
SECTION
(
"access non-existing value"
)
...
...
@@ -219,6 +311,24 @@ TEST_CASE("element access 2")
CHECK
(
j_const
.
value
(
"_"
,
12.34
)
==
Approx
(
12.34
));
CHECK
(
j_const
.
value
(
"_"
,
json
({{
"foo"
,
"bar"
}}))
==
json
({{
"foo"
,
"bar"
}}));
CHECK
(
j_const
.
value
(
"_"
,
json
({
10
,
100
}))
==
json
({
10
,
100
}));
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
value
(
std
::
string_view
(
"_"
),
2
)
==
2
);
CHECK
(
j
.
value
(
std
::
string_view
(
"_"
),
2u
)
==
2u
);
CHECK
(
j
.
value
(
std
::
string_view
(
"_"
),
false
)
==
false
);
CHECK
(
j
.
value
(
std
::
string_view
(
"_"
),
"bar"
)
==
"bar"
);
CHECK
(
j
.
value
(
std
::
string_view
(
"_"
),
12.34
)
==
Approx
(
12.34
));
CHECK
(
j
.
value
(
std
::
string_view
(
"_"
),
json
({{
"foo"
,
"bar"
}}))
==
json
({{
"foo"
,
"bar"
}}));
CHECK
(
j
.
value
(
std
::
string_view
(
"_"
),
json
({
10
,
100
}))
==
json
({
10
,
100
}));
CHECK
(
j_const
.
value
(
std
::
string_view
(
"_"
),
2
)
==
2
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"_"
),
2u
)
==
2u
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"_"
),
false
)
==
false
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"_"
),
"bar"
)
==
"bar"
);
CHECK
(
j_const
.
value
(
std
::
string_view
(
"_"
),
12.34
)
==
Approx
(
12.34
));
CHECK
(
j_const
.
value
(
std
::
string_view
(
"_"
),
json
({{
"foo"
,
"bar"
}}))
==
json
({{
"foo"
,
"bar"
}}));
CHECK
(
j_const
.
value
(
std
::
string_view
(
"_"
),
json
({
10
,
100
}))
==
json
({
10
,
100
}));
#endif
}
SECTION
(
"access on non-object type"
)
...
...
@@ -227,84 +337,154 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
null
);
const
json
j_nonobject_const
(
json
::
value_t
::
null
);
CHECK_THROWS_AS
(
j_nonobject
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with null"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with null"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with null"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with null"
);
#endif
}
SECTION
(
"boolean"
)
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
const
json
j_nonobject_const
(
json
::
value_t
::
boolean
);
CHECK_THROWS_AS
(
j_nonobject
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with boolean"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with boolean"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with boolean"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with boolean"
);
#endif
}
SECTION
(
"string"
)
{
json
j_nonobject
(
json
::
value_t
::
string
);
const
json
j_nonobject_const
(
json
::
value_t
::
string
);
CHECK_THROWS_AS
(
j_nonobject
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with string"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with string"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with string"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with string"
);
#endif
}
SECTION
(
"array"
)
{
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_nonobject_const
(
json
::
value_t
::
array
);
CHECK_THROWS_AS
(
j_nonobject
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with array"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with array"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with array"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with array"
);
#endif
}
SECTION
(
"number (integer)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
const
json
j_nonobject_const
(
json
::
value_t
::
number_integer
);
CHECK_THROWS_AS
(
j_nonobject
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
#endif
}
SECTION
(
"number (unsigned)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_unsigned
);
const
json
j_nonobject_const
(
json
::
value_t
::
number_unsigned
);
CHECK_THROWS_AS
(
j_nonobject
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
#endif
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
const
json
j_nonobject_const
(
json
::
value_t
::
number_float
);
CHECK_THROWS_AS
(
j_nonobject
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
"foo"
,
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
"foo"
,
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
value
(
std
::
string_view
(
"foo"
),
1
),
"[json.exception.type_error.306] cannot use value() with number"
);
#endif
}
}
}
...
...
@@ -495,6 +675,7 @@ TEST_CASE("element access 2")
json
j_nonobject
(
json
::
value_t
::
null
);
json
j_nonobject2
(
json
::
value_t
::
null
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_NOTHROW
(
j_nonobject
[
"foo"
]);
CHECK_NOTHROW
(
j_nonobject2
[
json
::
object_t
::
key_type
(
"foo"
)]);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
json
::
type_error
&
);
...
...
@@ -508,6 +689,7 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
json
::
type_error
&
);
...
...
@@ -526,6 +708,7 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
string
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
json
::
type_error
&
);
...
...
@@ -544,6 +727,7 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
json
::
type_error
&
);
...
...
@@ -561,6 +745,7 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
json
::
type_error
&
);
...
...
@@ -579,6 +764,7 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
number_unsigned
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
json
::
type_error
&
);
...
...
@@ -597,6 +783,7 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
json
::
type_error
&
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
json
::
type_error
&
);
...
...
@@ -658,6 +845,51 @@ TEST_CASE("element access 2")
CHECK
(
j
.
erase
(
"array"
)
==
0
);
}
#ifdef JSON_HAS_CPP_17
SECTION
(
"remove element by key (string_view)"
)
{
CHECK
(
j
.
find
(
std
::
string_view
(
"integer"
))
!=
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"integer"
))
==
1
);
CHECK
(
j
.
find
(
std
::
string_view
(
"integer"
))
==
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"integer"
))
==
0
);
CHECK
(
j
.
find
(
std
::
string_view
(
"unsigned"
))
!=
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"unsigned"
))
==
1
);
CHECK
(
j
.
find
(
std
::
string_view
(
"unsigned"
))
==
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"unsigned"
))
==
0
);
CHECK
(
j
.
find
(
std
::
string_view
(
"boolean"
))
!=
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"boolean"
))
==
1
);
CHECK
(
j
.
find
(
std
::
string_view
(
"boolean"
))
==
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"boolean"
))
==
0
);
CHECK
(
j
.
find
(
std
::
string_view
(
"null"
))
!=
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"null"
))
==
1
);
CHECK
(
j
.
find
(
std
::
string_view
(
"null"
))
==
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"null"
))
==
0
);
CHECK
(
j
.
find
(
std
::
string_view
(
"string"
))
!=
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"string"
))
==
1
);
CHECK
(
j
.
find
(
std
::
string_view
(
"string"
))
==
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"string"
))
==
0
);
CHECK
(
j
.
find
(
std
::
string_view
(
"floating"
))
!=
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"floating"
))
==
1
);
CHECK
(
j
.
find
(
std
::
string_view
(
"floating"
))
==
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"floating"
))
==
0
);
CHECK
(
j
.
find
(
std
::
string_view
(
"object"
))
!=
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"object"
))
==
1
);
CHECK
(
j
.
find
(
std
::
string_view
(
"object"
))
==
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"object"
))
==
0
);
CHECK
(
j
.
find
(
std
::
string_view
(
"array"
))
!=
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"array"
))
==
1
);
CHECK
(
j
.
find
(
std
::
string_view
(
"array"
))
==
j
.
end
());
CHECK
(
j
.
erase
(
std
::
string_view
(
"array"
))
==
0
);
}
#endif
SECTION
(
"remove element by iterator"
)
{
SECTION
(
"erase(begin())"
)
...
...
@@ -784,49 +1016,91 @@ TEST_CASE("element access 2")
SECTION
(
"null"
)
{
json
j_nonobject
(
json
::
value_t
::
null
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with null"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.307] cannot use erase() with null"
);
#endif
}
SECTION
(
"boolean"
)
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with boolean"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.307] cannot use erase() with boolean"
);
#endif
}
SECTION
(
"string"
)
{
json
j_nonobject
(
json
::
value_t
::
string
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with string"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.307] cannot use erase() with string"
);
#endif
}
SECTION
(
"array"
)
{
json
j_nonobject
(
json
::
value_t
::
array
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with array"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.307] cannot use erase() with array"
);
#endif
}
SECTION
(
"number (integer)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with number"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.307] cannot use erase() with number"
);
#endif
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
"foo"
),
"[json.exception.type_error.307] cannot use erase() with number"
);
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j_nonobject
.
erase
(
std
::
string_view
(
"foo"
)),
"[json.exception.type_error.307] cannot use erase() with number"
);
#endif
}
}
}
...
...
@@ -844,12 +1118,28 @@ TEST_CASE("element access 2")
CHECK
(
j_const
.
find
(
key
)
!=
j_const
.
end
());
CHECK
(
*
j_const
.
find
(
key
)
==
j_const
.
at
(
key
));
}
#ifdef JSON_HAS_CPP_17
for
(
const
std
::
string_view
key
:
{
"integer"
,
"unsigned"
,
"floating"
,
"null"
,
"string"
,
"boolean"
,
"object"
,
"array"
})
{
CHECK
(
j
.
find
(
key
)
!=
j
.
end
());
CHECK
(
*
j
.
find
(
key
)
==
j
.
at
(
key
));
CHECK
(
j_const
.
find
(
key
)
!=
j_const
.
end
());
CHECK
(
*
j_const
.
find
(
key
)
==
j_const
.
at
(
key
));
}
#endif
}
SECTION
(
"nonexisting element"
)
{
CHECK
(
j
.
find
(
"foo"
)
==
j
.
end
());
CHECK
(
j_const
.
find
(
"foo"
)
==
j_const
.
end
());
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
find
(
std
::
string_view
(
"foo"
))
==
j
.
end
());
CHECK
(
j_const
.
find
(
std
::
string_view
(
"foo"
))
==
j_const
.
end
());
#endif
}
SECTION
(
"all types"
)
...
...
@@ -858,64 +1148,112 @@ TEST_CASE("element access 2")
{
json
j_nonarray
(
json
::
value_t
::
null
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK
(
j_nonarray
.
find
(
"foo"
)
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
"foo"
)
==
j_nonarray_const
.
end
());
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonarray
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray_const
.
end
());
#endif
}
SECTION
(
"string"
)
{
json
j_nonarray
(
json
::
value_t
::
string
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK
(
j_nonarray
.
find
(
"foo"
)
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
"foo"
)
==
j_nonarray_const
.
end
());
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonarray
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray_const
.
end
());
#endif
}
SECTION
(
"object"
)
{
json
j_nonarray
(
json
::
value_t
::
object
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK
(
j_nonarray
.
find
(
"foo"
)
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
"foo"
)
==
j_nonarray_const
.
end
());
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonarray
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray_const
.
end
());
#endif
}
SECTION
(
"array"
)
{
json
j_nonarray
(
json
::
value_t
::
array
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK
(
j_nonarray
.
find
(
"foo"
)
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
"foo"
)
==
j_nonarray_const
.
end
());
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonarray
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray_const
.
end
());
#endif
}
SECTION
(
"boolean"
)
{
json
j_nonarray
(
json
::
value_t
::
boolean
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK
(
j_nonarray
.
find
(
"foo"
)
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
"foo"
)
==
j_nonarray_const
.
end
());
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonarray
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray_const
.
end
());
#endif
}
SECTION
(
"number (integer)"
)
{
json
j_nonarray
(
json
::
value_t
::
number_integer
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK
(
j_nonarray
.
find
(
"foo"
)
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
"foo"
)
==
j_nonarray_const
.
end
());
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonarray
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray_const
.
end
());
#endif
}
SECTION
(
"number (unsigned)"
)
{
json
j_nonarray
(
json
::
value_t
::
number_unsigned
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK
(
j_nonarray
.
find
(
"foo"
)
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
"foo"
)
==
j_nonarray_const
.
end
());
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonarray
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray_const
.
end
());
#endif
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonarray
(
json
::
value_t
::
number_float
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK
(
j_nonarray
.
find
(
"foo"
)
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
"foo"
)
==
j_nonarray_const
.
end
());
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonarray
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray
.
end
());
CHECK
(
j_nonarray_const
.
find
(
std
::
string_view
(
"foo"
))
==
j_nonarray_const
.
end
());
#endif
}
}
}
...
...
@@ -931,7 +1269,7 @@ TEST_CASE("element access 2")
CHECK
(
j
.
count
(
key
)
==
1
);
CHECK
(
j_const
.
count
(
key
)
==
1
);
}
#if
defined(JSON_HAS_CPP_17)
#if
def JSON_HAS_CPP_17
for
(
const
std
::
string_view
key
:
{
"integer"
,
"unsigned"
,
"floating"
,
"null"
,
"string"
,
"boolean"
,
"object"
,
"array"
})
...
...
@@ -946,7 +1284,8 @@ TEST_CASE("element access 2")
{
CHECK
(
j
.
count
(
"foo"
)
==
0
);
CHECK
(
j_const
.
count
(
"foo"
)
==
0
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
CHECK
(
j_const
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
#endif
...
...
@@ -958,9 +1297,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
null
);
const
json
j_nonobject_const
(
json
::
value_t
::
null
);
CHECK
(
j_nonobject
.
count
(
"foo"
)
==
0
);
CHECK
(
j_nonobject_const
.
count
(
"foo"
)
==
0
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
CHECK
(
j_const
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
#endif
...
...
@@ -970,9 +1311,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
string
);
const
json
j_nonobject_const
(
json
::
value_t
::
string
);
CHECK
(
j_nonobject
.
count
(
"foo"
)
==
0
);
CHECK
(
j_nonobject_const
.
count
(
"foo"
)
==
0
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
CHECK
(
j_const
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
#endif
...
...
@@ -982,9 +1325,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
object
);
const
json
j_nonobject_const
(
json
::
value_t
::
object
);
CHECK
(
j_nonobject
.
count
(
"foo"
)
==
0
);
CHECK
(
j_nonobject_const
.
count
(
"foo"
)
==
0
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
CHECK
(
j_const
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
#endif
...
...
@@ -994,9 +1339,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_nonobject_const
(
json
::
value_t
::
array
);
CHECK
(
j_nonobject
.
count
(
"foo"
)
==
0
);
CHECK
(
j_nonobject_const
.
count
(
"foo"
)
==
0
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
CHECK
(
j_const
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
#endif
...
...
@@ -1006,9 +1353,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
const
json
j_nonobject_const
(
json
::
value_t
::
boolean
);
CHECK
(
j_nonobject
.
count
(
"foo"
)
==
0
);
CHECK
(
j_nonobject_const
.
count
(
"foo"
)
==
0
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
CHECK
(
j_const
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
#endif
...
...
@@ -1018,9 +1367,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
const
json
j_nonobject_const
(
json
::
value_t
::
number_integer
);
CHECK
(
j_nonobject
.
count
(
"foo"
)
==
0
);
CHECK
(
j_nonobject_const
.
count
(
"foo"
)
==
0
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
CHECK
(
j_const
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
#endif
...
...
@@ -1030,9 +1381,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
number_unsigned
);
const
json
j_nonobject_const
(
json
::
value_t
::
number_unsigned
);
CHECK
(
j_nonobject
.
count
(
"foo"
)
==
0
);
CHECK
(
j_nonobject_const
.
count
(
"foo"
)
==
0
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
CHECK
(
j_const
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
#endif
...
...
@@ -1042,9 +1395,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
const
json
j_nonobject_const
(
json
::
value_t
::
number_float
);
CHECK
(
j_nonobject
.
count
(
"foo"
)
==
0
);
CHECK
(
j_nonobject_const
.
count
(
"foo"
)
==
0
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
CHECK
(
j_const
.
count
(
std
::
string_view
(
"foo"
))
==
0
);
#endif
...
...
@@ -1064,7 +1419,7 @@ TEST_CASE("element access 2")
CHECK
(
j_const
.
contains
(
key
)
==
true
);
}
#if
defined(JSON_HAS_CPP_17)
#if
def JSON_HAS_CPP_17
for
(
const
std
::
string_view
key
:
{
"integer"
,
"unsigned"
,
"floating"
,
"null"
,
"string"
,
"boolean"
,
"object"
,
"array"
})
...
...
@@ -1079,7 +1434,8 @@ TEST_CASE("element access 2")
{
CHECK
(
j
.
contains
(
"foo"
)
==
false
);
CHECK
(
j_const
.
contains
(
"foo"
)
==
false
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
CHECK
(
j_const
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
#endif
...
...
@@ -1091,9 +1447,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
null
);
const
json
j_nonobject_const
(
json
::
value_t
::
null
);
CHECK
(
j_nonobject
.
contains
(
"foo"
)
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
"foo"
)
==
false
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonobject
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
#endif
...
...
@@ -1103,9 +1461,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
string
);
const
json
j_nonobject_const
(
json
::
value_t
::
string
);
CHECK
(
j_nonobject
.
contains
(
"foo"
)
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
"foo"
)
==
false
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonobject
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
#endif
...
...
@@ -1115,9 +1475,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
object
);
const
json
j_nonobject_const
(
json
::
value_t
::
object
);
CHECK
(
j_nonobject
.
contains
(
"foo"
)
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
"foo"
)
==
false
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonobject
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
#endif
...
...
@@ -1127,9 +1489,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_nonobject_const
(
json
::
value_t
::
array
);
CHECK
(
j_nonobject
.
contains
(
"foo"
)
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
"foo"
)
==
false
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonobject
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
#endif
...
...
@@ -1139,9 +1503,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
const
json
j_nonobject_const
(
json
::
value_t
::
boolean
);
CHECK
(
j_nonobject
.
contains
(
"foo"
)
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
"foo"
)
==
false
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonobject
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
#endif
...
...
@@ -1151,9 +1517,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
const
json
j_nonobject_const
(
json
::
value_t
::
number_integer
);
CHECK
(
j_nonobject
.
contains
(
"foo"
)
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
"foo"
)
==
false
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonobject
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
#endif
...
...
@@ -1163,9 +1531,11 @@ TEST_CASE("element access 2")
{
json
j_nonobject
(
json
::
value_t
::
number_unsigned
);
const
json
j_nonobject_const
(
json
::
value_t
::
number_unsigned
);
CHECK
(
j_nonobject
.
contains
(
"foo"
)
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
"foo"
)
==
false
);
#if defined(JSON_HAS_CPP_17)
#ifdef JSON_HAS_CPP_17
CHECK
(
j_nonobject
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
#endif
...
...
@@ -1177,7 +1547,7 @@ TEST_CASE("element access 2")
const
json
j_nonobject_const
(
json
::
value_t
::
number_float
);
CHECK
(
j_nonobject
.
contains
(
"foo"
)
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
"foo"
)
==
false
);
#if
defined(JSON_HAS_CPP_17)
#if
def JSON_HAS_CPP_17
CHECK
(
j_nonobject
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
CHECK
(
j_nonobject_const
.
contains
(
std
::
string_view
(
"foo"
))
==
false
);
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment