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
f473f74f
Unverified
Commit
f473f74f
authored
Mar 05, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
added user-defined exceptions 303-304
parent
068c7acd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
86 deletions
+84
-86
json.hpp
src/json.hpp
+14
-15
json.hpp.re2c
src/json.hpp.re2c
+14
-15
unit-element_access1.cpp
test/src/unit-element_access1.cpp
+28
-28
unit-element_access2.cpp
test/src/unit-element_access2.cpp
+28
-28
No files found.
src/json.hpp
View file @
f473f74f
...
@@ -3255,7 +3255,7 @@ class basic_json
...
@@ -3255,7 +3255,7 @@ class basic_json
@tparam ThisType will be deduced as `basic_json` or `const basic_json`
@tparam ThisType will be deduced as `basic_json` or `const basic_json`
@throw
std::domain_error
if ReferenceType does not match underlying value
@throw
type_error.303
if ReferenceType does not match underlying value
type of the current JSON
type of the current JSON
*/
*/
template
<
typename
ReferenceType
,
typename
ThisType
>
template
<
typename
ReferenceType
,
typename
ThisType
>
...
@@ -3272,8 +3272,7 @@ class basic_json
...
@@ -3272,8 +3272,7 @@ class basic_json
return
*
ptr
;
return
*
ptr
;
}
}
JSON_THROW
(
std
::
domain_error
(
"incompatible ReferenceType for get_ref, actual type is "
+
JSON_THROW
(
type_error
(
303
,
"incompatible ReferenceType for get_ref, actual type is "
+
obj
.
type_name
()));
obj
.
type_name
()));
}
}
public
:
public
:
...
@@ -3554,8 +3553,8 @@ class basic_json
...
@@ -3554,8 +3553,8 @@ class basic_json
reference type @a ReferenceType fits to the JSON value; throws
reference type @a ReferenceType fits to the JSON value; throws
std::domain_error otherwise
std::domain_error otherwise
@throw
std::domain_error in case passed type @a ReferenceType is
@throw
type_error.303 in case passed type @a ReferenceType is incompatible
incompatible
with the stored JSON value
with the stored JSON value
@complexity Constant.
@complexity Constant.
...
@@ -3646,8 +3645,8 @@ class basic_json
...
@@ -3646,8 +3645,8 @@ class basic_json
@return reference to the element at index @a idx
@return reference to the element at index @a idx
@throw
std::domain_error if the JSON value is not an array; example:
@throw
type_error.304 if the JSON value is not an array; example: `"cannot
`"cannot
use at() with string"`
use at() with string"`
@throw std::out_of_range if the index @a idx is out of range of the array;
@throw std::out_of_range if the index @a idx is out of range of the array;
that is, `idx >= size()`; example: `"array index 7 is out of range"`
that is, `idx >= size()`; example: `"array index 7 is out of range"`
...
@@ -3675,7 +3674,7 @@ class basic_json
...
@@ -3675,7 +3674,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW
(
std
::
domain_error
(
"cannot use at() with "
+
type_name
()));
JSON_THROW
(
type_error
(
304
,
"cannot use at() with "
+
type_name
()));
}
}
}
}
...
@@ -3689,8 +3688,8 @@ class basic_json
...
@@ -3689,8 +3688,8 @@ class basic_json
@return const reference to the element at index @a idx
@return const reference to the element at index @a idx
@throw
std::domain_error if the JSON value is not an array; example:
@throw
type_error.304 if the JSON value is not an array; example: `"cannot
`"cannot
use at() with string"`
use at() with string"`
@throw std::out_of_range if the index @a idx is out of range of the array;
@throw std::out_of_range if the index @a idx is out of range of the array;
that is, `idx >= size()`; example: `"array index 7 is out of range"`
that is, `idx >= size()`; example: `"array index 7 is out of range"`
...
@@ -3718,7 +3717,7 @@ class basic_json
...
@@ -3718,7 +3717,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW
(
std
::
domain_error
(
"cannot use at() with "
+
type_name
()));
JSON_THROW
(
type_error
(
304
,
"cannot use at() with "
+
type_name
()));
}
}
}
}
...
@@ -3732,7 +3731,7 @@ class basic_json
...
@@ -3732,7 +3731,7 @@ class basic_json
@return reference to the element at key @a key
@return reference to the element at key @a key
@throw
std::domain_error
if the JSON value is not an object; example:
@throw
type_error.304
if the JSON value is not an object; example:
`"cannot use at() with boolean"`
`"cannot use at() with boolean"`
@throw std::out_of_range if the key @a key is is not stored in the object;
@throw std::out_of_range if the key @a key is is not stored in the object;
that is, `find(key) == end()`; example: `"key "the fast" not found"`
that is, `find(key) == end()`; example: `"key "the fast" not found"`
...
@@ -3765,7 +3764,7 @@ class basic_json
...
@@ -3765,7 +3764,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW
(
std
::
domain_error
(
"cannot use at() with "
+
type_name
()));
JSON_THROW
(
type_error
(
304
,
"cannot use at() with "
+
type_name
()));
}
}
}
}
...
@@ -3779,7 +3778,7 @@ class basic_json
...
@@ -3779,7 +3778,7 @@ class basic_json
@return const reference to the element at key @a key
@return const reference to the element at key @a key
@throw
std::domain_error
if the JSON value is not an object; example:
@throw
type_error.304
if the JSON value is not an object; example:
`"cannot use at() with boolean"`
`"cannot use at() with boolean"`
@throw std::out_of_range if the key @a key is is not stored in the object;
@throw std::out_of_range if the key @a key is is not stored in the object;
that is, `find(key) == end()`; example: `"key "the fast" not found"`
that is, `find(key) == end()`; example: `"key "the fast" not found"`
...
@@ -3812,7 +3811,7 @@ class basic_json
...
@@ -3812,7 +3811,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW
(
std
::
domain_error
(
"cannot use at() with "
+
type_name
()));
JSON_THROW
(
type_error
(
304
,
"cannot use at() with "
+
type_name
()));
}
}
}
}
...
...
src/json.hpp.re2c
View file @
f473f74f
...
@@ -3255,7 +3255,7 @@ class basic_json
...
@@ -3255,7 +3255,7 @@ class basic_json
@tparam ThisType will be deduced as `basic_json` or `const basic_json`
@tparam ThisType will be deduced as `basic_json` or `const basic_json`
@throw
std::domain_error
if ReferenceType does not match underlying value
@throw
type_error.303
if ReferenceType does not match underlying value
type of the current JSON
type of the current JSON
*/
*/
template<typename ReferenceType, typename ThisType>
template<typename ReferenceType, typename ThisType>
...
@@ -3272,8 +3272,7 @@ class basic_json
...
@@ -3272,8 +3272,7 @@ class basic_json
return *ptr;
return *ptr;
}
}
JSON_THROW(std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
JSON_THROW(type_error(303, "incompatible ReferenceType for get_ref, actual type is " + obj.type_name()));
obj.type_name()));
}
}
public:
public:
...
@@ -3554,8 +3553,8 @@ class basic_json
...
@@ -3554,8 +3553,8 @@ class basic_json
reference type @a ReferenceType fits to the JSON value; throws
reference type @a ReferenceType fits to the JSON value; throws
std::domain_error otherwise
std::domain_error otherwise
@throw
std::domain_error in case passed type @a ReferenceType is
@throw
type_error.303 in case passed type @a ReferenceType is incompatible
incompatible
with the stored JSON value
with the stored JSON value
@complexity Constant.
@complexity Constant.
...
@@ -3646,8 +3645,8 @@ class basic_json
...
@@ -3646,8 +3645,8 @@ class basic_json
@return reference to the element at index @a idx
@return reference to the element at index @a idx
@throw
std::domain_error if the JSON value is not an array; example:
@throw
type_error.304 if the JSON value is not an array; example: `"cannot
`"cannot
use at() with string"`
use at() with string"`
@throw std::out_of_range if the index @a idx is out of range of the array;
@throw std::out_of_range if the index @a idx is out of range of the array;
that is, `idx >= size()`; example: `"array index 7 is out of range"`
that is, `idx >= size()`; example: `"array index 7 is out of range"`
...
@@ -3675,7 +3674,7 @@ class basic_json
...
@@ -3675,7 +3674,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW(
std::domain_error(
"cannot use at() with " + type_name()));
JSON_THROW(
type_error(304,
"cannot use at() with " + type_name()));
}
}
}
}
...
@@ -3689,8 +3688,8 @@ class basic_json
...
@@ -3689,8 +3688,8 @@ class basic_json
@return const reference to the element at index @a idx
@return const reference to the element at index @a idx
@throw
std::domain_error if the JSON value is not an array; example:
@throw
type_error.304 if the JSON value is not an array; example: `"cannot
`"cannot
use at() with string"`
use at() with string"`
@throw std::out_of_range if the index @a idx is out of range of the array;
@throw std::out_of_range if the index @a idx is out of range of the array;
that is, `idx >= size()`; example: `"array index 7 is out of range"`
that is, `idx >= size()`; example: `"array index 7 is out of range"`
...
@@ -3718,7 +3717,7 @@ class basic_json
...
@@ -3718,7 +3717,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW(
std::domain_error(
"cannot use at() with " + type_name()));
JSON_THROW(
type_error(304,
"cannot use at() with " + type_name()));
}
}
}
}
...
@@ -3732,7 +3731,7 @@ class basic_json
...
@@ -3732,7 +3731,7 @@ class basic_json
@return reference to the element at key @a key
@return reference to the element at key @a key
@throw
std::domain_error
if the JSON value is not an object; example:
@throw
type_error.304
if the JSON value is not an object; example:
`"cannot use at() with boolean"`
`"cannot use at() with boolean"`
@throw std::out_of_range if the key @a key is is not stored in the object;
@throw std::out_of_range if the key @a key is is not stored in the object;
that is, `find(key) == end()`; example: `"key "the fast" not found"`
that is, `find(key) == end()`; example: `"key "the fast" not found"`
...
@@ -3765,7 +3764,7 @@ class basic_json
...
@@ -3765,7 +3764,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW(
std::domain_error(
"cannot use at() with " + type_name()));
JSON_THROW(
type_error(304,
"cannot use at() with " + type_name()));
}
}
}
}
...
@@ -3779,7 +3778,7 @@ class basic_json
...
@@ -3779,7 +3778,7 @@ class basic_json
@return const reference to the element at key @a key
@return const reference to the element at key @a key
@throw
std::domain_error
if the JSON value is not an object; example:
@throw
type_error.304
if the JSON value is not an object; example:
`"cannot use at() with boolean"`
`"cannot use at() with boolean"`
@throw std::out_of_range if the key @a key is is not stored in the object;
@throw std::out_of_range if the key @a key is is not stored in the object;
that is, `find(key) == end()`; example: `"key "the fast" not found"`
that is, `find(key) == end()`; example: `"key "the fast" not found"`
...
@@ -3812,7 +3811,7 @@ class basic_json
...
@@ -3812,7 +3811,7 @@ class basic_json
}
}
else
else
{
{
JSON_THROW(
std::domain_error(
"cannot use at() with " + type_name()));
JSON_THROW(
type_error(304,
"cannot use at() with " + type_name()));
}
}
}
}
...
...
test/src/unit-element_access1.cpp
View file @
f473f74f
...
@@ -76,77 +76,77 @@ TEST_CASE("element access 1")
...
@@ -76,77 +76,77 @@ TEST_CASE("element access 1")
{
{
json
j_nonarray
(
json
::
value_t
::
null
);
json
j_nonarray
(
json
::
value_t
::
null
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"cannot use at() with null"
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with null"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"cannot use at() with null"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with null"
);
}
}
SECTION
(
"boolean"
)
SECTION
(
"boolean"
)
{
{
json
j_nonarray
(
json
::
value_t
::
boolean
);
json
j_nonarray
(
json
::
value_t
::
boolean
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"cannot use at() with boolean"
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with boolean"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"cannot use at() with boolean"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with boolean"
);
}
}
SECTION
(
"string"
)
SECTION
(
"string"
)
{
{
json
j_nonarray
(
json
::
value_t
::
string
);
json
j_nonarray
(
json
::
value_t
::
string
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"cannot use at() with string"
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with string"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"cannot use at() with string"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with string"
);
}
}
SECTION
(
"object"
)
SECTION
(
"object"
)
{
{
json
j_nonarray
(
json
::
value_t
::
object
);
json
j_nonarray
(
json
::
value_t
::
object
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"cannot use at() with object"
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with object"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"cannot use at() with object"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with object"
);
}
}
SECTION
(
"number (integer)"
)
SECTION
(
"number (integer)"
)
{
{
json
j_nonarray
(
json
::
value_t
::
number_integer
);
json
j_nonarray
(
json
::
value_t
::
number_integer
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with number"
);
}
}
SECTION
(
"number (unsigned)"
)
SECTION
(
"number (unsigned)"
)
{
{
json
j_nonarray
(
json
::
value_t
::
number_unsigned
);
json
j_nonarray
(
json
::
value_t
::
number_unsigned
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with number"
);
}
}
SECTION
(
"number (floating-point)"
)
SECTION
(
"number (floating-point)"
)
{
{
json
j_nonarray
(
json
::
value_t
::
number_float
);
json
j_nonarray
(
json
::
value_t
::
number_float
);
const
json
j_nonarray_const
(
j_nonarray
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonarray
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonarray_const
.
at
(
0
),
"
[json.exception.type_error.304]
cannot use at() with number"
);
}
}
}
}
}
}
...
...
test/src/unit-element_access2.cpp
View file @
f473f74f
...
@@ -75,70 +75,70 @@ TEST_CASE("element access 2")
...
@@ -75,70 +75,70 @@ TEST_CASE("element access 2")
{
{
json
j_nonobject
(
json
::
value_t
::
null
);
json
j_nonobject
(
json
::
value_t
::
null
);
const
json
j_nonobject_const
(
j_nonobject
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"cannot use at() with null"
);
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"
),
"cannot use at() with null"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"
[json.exception.type_error.304]
cannot use at() with null"
);
}
}
SECTION
(
"boolean"
)
SECTION
(
"boolean"
)
{
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
json
j_nonobject
(
json
::
value_t
::
boolean
);
const
json
j_nonobject_const
(
j_nonobject
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"cannot use at() with boolean"
);
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"
),
"cannot use at() with boolean"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"
[json.exception.type_error.304]
cannot use at() with boolean"
);
}
}
SECTION
(
"string"
)
SECTION
(
"string"
)
{
{
json
j_nonobject
(
json
::
value_t
::
string
);
json
j_nonobject
(
json
::
value_t
::
string
);
const
json
j_nonobject_const
(
j_nonobject
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"cannot use at() with string"
);
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"
),
"cannot use at() with string"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"
[json.exception.type_error.304]
cannot use at() with string"
);
}
}
SECTION
(
"array"
)
SECTION
(
"array"
)
{
{
json
j_nonobject
(
json
::
value_t
::
array
);
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_nonobject_const
(
j_nonobject
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"cannot use at() with array"
);
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"
),
"cannot use at() with array"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"
[json.exception.type_error.304]
cannot use at() with array"
);
}
}
SECTION
(
"number (integer)"
)
SECTION
(
"number (integer)"
)
{
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
json
j_nonobject
(
json
::
value_t
::
number_integer
);
const
json
j_nonobject_const
(
j_nonobject
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"cannot use at() with number"
);
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"
),
"cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"
[json.exception.type_error.304]
cannot use at() with number"
);
}
}
SECTION
(
"number (unsigned)"
)
SECTION
(
"number (unsigned)"
)
{
{
json
j_nonobject
(
json
::
value_t
::
number_unsigned
);
json
j_nonobject
(
json
::
value_t
::
number_unsigned
);
const
json
j_nonobject_const
(
j_nonobject
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"cannot use at() with number"
);
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"
),
"cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"
[json.exception.type_error.304]
cannot use at() with number"
);
}
}
SECTION
(
"number (floating-point)"
)
SECTION
(
"number (floating-point)"
)
{
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
json
j_nonobject
(
json
::
value_t
::
number_float
);
const
json
j_nonobject_const
(
j_nonobject
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
json
::
type
_error
);
CHECK_THROWS_WITH
(
j_nonobject
.
at
(
"foo"
),
"cannot use at() with number"
);
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"
),
"cannot use at() with number"
);
CHECK_THROWS_WITH
(
j_nonobject_const
.
at
(
"foo"
),
"
[json.exception.type_error.304]
cannot use at() with number"
);
}
}
}
}
}
}
...
...
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