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
67c2d90a
Commit
67c2d90a
authored
Dec 22, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on #160
parent
4351698c
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
247 additions
and
35 deletions
+247
-35
README.md
README.md
+1
-1
at__object_t_key_type.cpp
doc/examples/at__object_t_key_type.cpp
+2
-2
at__object_t_key_type.link
doc/examples/at__object_t_key_type.link
+2
-2
at__object_t_key_type.output
doc/examples/at__object_t_key_type.output
+1
-1
at__size_type.cpp
doc/examples/at__size_type.cpp
+2
-2
at__size_type.link
doc/examples/at__size_type.link
+2
-2
at__size_type.output
doc/examples/at__size_type.output
+1
-1
json.hpp
src/json.hpp
+48
-12
json.hpp.re2c
src/json.hpp.re2c
+48
-12
unit.cpp
test/unit.cpp
+140
-0
No files found.
README.md
View file @
67c2d90a
...
@@ -398,7 +398,7 @@ $ make
...
@@ -398,7 +398,7 @@ $ make
$
./json_unit
"*"
$
./json_unit
"*"
===============================================================================
===============================================================================
All tests passed
(
33418
4
8 assertions
in
28
test
cases
)
All tests passed
(
33418
8
8 assertions
in
28
test
cases
)
```
```
For more information, have a look at the file
[
.travis.yml
](
https://github.com/nlohmann/json/blob/master/.travis.yml
)
.
For more information, have a look at the file
[
.travis.yml
](
https://github.com/nlohmann/json/blob/master/.travis.yml
)
.
doc/examples/at__object_t_key_type.cpp
View file @
67c2d90a
...
@@ -26,8 +26,8 @@ int main()
...
@@ -26,8 +26,8 @@ int main()
{
{
object
.
at
(
"the fast"
)
=
"il rapido"
;
object
.
at
(
"the fast"
)
=
"il rapido"
;
}
}
catch
(
std
::
out_of_range
)
catch
(
std
::
out_of_range
&
e
)
{
{
std
::
cout
<<
"out of range
"
<<
'\n'
;
std
::
cout
<<
"out of range
: "
<<
e
.
what
()
<<
'\n'
;
}
}
}
}
doc/examples/at__object_t_key_type.link
View file @
67c2d90a
<a target="_blank" href="http://melpon.org/wandbox/permlink/syN4hQrhPvlUy5AG"><b>online</b></a>
<a target="_blank" href="http://melpon.org/wandbox/permlink/3ir8W1OZ5KtbRz6r"><b>online</b></a>
\ No newline at end of file
\ No newline at end of file
doc/examples/at__object_t_key_type.output
View file @
67c2d90a
"il brutto"
"il brutto"
{"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"}
{"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"}
out of range
out of range
: key 'the fast' not found
doc/examples/at__size_type.cpp
View file @
67c2d90a
...
@@ -21,8 +21,8 @@ int main()
...
@@ -21,8 +21,8 @@ int main()
{
{
array
.
at
(
5
)
=
"sixth"
;
array
.
at
(
5
)
=
"sixth"
;
}
}
catch
(
std
::
out_of_range
)
catch
(
std
::
out_of_range
&
e
)
{
{
std
::
cout
<<
"out of range
"
<<
'\n'
;
std
::
cout
<<
"out of range
: "
<<
e
.
what
()
<<
'\n'
;
}
}
}
}
doc/examples/at__size_type.link
View file @
67c2d90a
<a target="_blank" href="http://melpon.org/wandbox/permlink/wKBBW3ORmTHPlgJV"><b>online</b></a>
<a target="_blank" href="http://melpon.org/wandbox/permlink/9Ae4DO4HJjULnq5j"><b>online</b></a>
\ No newline at end of file
\ No newline at end of file
doc/examples/at__size_type.output
View file @
67c2d90a
"third"
"third"
["first","second","third","fourth"]
["first","second","third","fourth"]
out of range
out of range
: array index 5 is out of range
src/json.hpp
View file @
67c2d90a
...
@@ -2602,9 +2602,10 @@ class basic_json
...
@@ -2602,9 +2602,10 @@ 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 JSON is not an array
@throw std::domain_error if the JSON value is not an array; example:
`"cannot 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()`
that is, `idx >= size()`
; example: `"array index 7 is out of range"`
@complexity Constant.
@complexity Constant.
...
@@ -2618,7 +2619,15 @@ class basic_json
...
@@ -2618,7 +2619,15 @@ class basic_json
// at only works for arrays
// at only works for arrays
if
(
is_array
())
if
(
is_array
())
{
{
return
m_value
.
array
->
at
(
idx
);
try
{
return
m_value
.
array
->
at
(
idx
);
}
catch
(
std
::
out_of_range
&
e
)
{
// create better exception explanation
throw
std
::
out_of_range
(
"array index "
+
std
::
to_string
(
idx
)
+
" is out of range"
);
}
}
}
else
else
{
{
...
@@ -2636,9 +2645,10 @@ class basic_json
...
@@ -2636,9 +2645,10 @@ 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 JSON is not an array
@throw std::domain_error if the JSON value is not an array; example:
`"cannot 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()`
that is, `idx >= size()`
; example: `"array index 7 is out of range"`
@complexity Constant.
@complexity Constant.
...
@@ -2652,7 +2662,15 @@ class basic_json
...
@@ -2652,7 +2662,15 @@ class basic_json
// at only works for arrays
// at only works for arrays
if
(
is_array
())
if
(
is_array
())
{
{
return
m_value
.
array
->
at
(
idx
);
try
{
return
m_value
.
array
->
at
(
idx
);
}
catch
(
std
::
out_of_range
&
e
)
{
// create better exception explanation
throw
std
::
out_of_range
(
"array index "
+
std
::
to_string
(
idx
)
+
" is out of range"
);
}
}
}
else
else
{
{
...
@@ -2670,9 +2688,10 @@ class basic_json
...
@@ -2670,9 +2688,10 @@ 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 JSON is not an object
@throw std::domain_error if the JSON value is not an object; example:
`"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()`
that is, `find(key) == end()`
; example: `"key "the fast" not found"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -2690,7 +2709,15 @@ class basic_json
...
@@ -2690,7 +2709,15 @@ class basic_json
// at only works for objects
// at only works for objects
if
(
is_object
())
if
(
is_object
())
{
{
return
m_value
.
object
->
at
(
key
);
try
{
return
m_value
.
object
->
at
(
key
);
}
catch
(
std
::
out_of_range
&
e
)
{
// create better exception explanation
throw
std
::
out_of_range
(
"key '"
+
key
+
"' not found"
);
}
}
}
else
else
{
{
...
@@ -2708,9 +2735,10 @@ class basic_json
...
@@ -2708,9 +2735,10 @@ 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 JSON is not an object
@throw std::domain_error if the JSON value is not an object; example:
`"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()`
that is, `find(key) == end()`
; example: `"key "the fast" not found"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -2728,7 +2756,15 @@ class basic_json
...
@@ -2728,7 +2756,15 @@ class basic_json
// at only works for objects
// at only works for objects
if
(
is_object
())
if
(
is_object
())
{
{
return
m_value
.
object
->
at
(
key
);
try
{
return
m_value
.
object
->
at
(
key
);
}
catch
(
std
::
out_of_range
&
e
)
{
// create better exception explanation
throw
std
::
out_of_range
(
"key '"
+
key
+
"' not found"
);
}
}
}
else
else
{
{
...
...
src/json.hpp.re2c
View file @
67c2d90a
...
@@ -2602,9 +2602,10 @@ class basic_json
...
@@ -2602,9 +2602,10 @@ 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 JSON is not an array
@throw std::domain_error if the JSON value is not an array; example:
`"cannot 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()`
that is, `idx >= size()`
; example: `"array index 7 is out of range"`
@complexity Constant.
@complexity Constant.
...
@@ -2618,7 +2619,15 @@ class basic_json
...
@@ -2618,7 +2619,15 @@ class basic_json
// at only works for arrays
// at only works for arrays
if (is_array())
if (is_array())
{
{
return m_value.array->at(idx);
try
{
return m_value.array->at(idx);
}
catch (std::out_of_range& e)
{
// create better exception explanation
throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
}
}
}
else
else
{
{
...
@@ -2636,9 +2645,10 @@ class basic_json
...
@@ -2636,9 +2645,10 @@ 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 JSON is not an array
@throw std::domain_error if the JSON value is not an array; example:
`"cannot 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()`
that is, `idx >= size()`
; example: `"array index 7 is out of range"`
@complexity Constant.
@complexity Constant.
...
@@ -2652,7 +2662,15 @@ class basic_json
...
@@ -2652,7 +2662,15 @@ class basic_json
// at only works for arrays
// at only works for arrays
if (is_array())
if (is_array())
{
{
return m_value.array->at(idx);
try
{
return m_value.array->at(idx);
}
catch (std::out_of_range& e)
{
// create better exception explanation
throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
}
}
}
else
else
{
{
...
@@ -2670,9 +2688,10 @@ class basic_json
...
@@ -2670,9 +2688,10 @@ 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 JSON is not an object
@throw std::domain_error if the JSON value is not an object; example:
`"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()`
that is, `find(key) == end()`
; example: `"key "the fast" not found"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -2690,7 +2709,15 @@ class basic_json
...
@@ -2690,7 +2709,15 @@ class basic_json
// at only works for objects
// at only works for objects
if (is_object())
if (is_object())
{
{
return m_value.object->at(key);
try
{
return m_value.object->at(key);
}
catch (std::out_of_range& e)
{
// create better exception explanation
throw std::out_of_range("key '" + key + "' not found");
}
}
}
else
else
{
{
...
@@ -2708,9 +2735,10 @@ class basic_json
...
@@ -2708,9 +2735,10 @@ 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 JSON is not an object
@throw std::domain_error if the JSON value is not an object; example:
`"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()`
that is, `find(key) == end()`
; example: `"key "the fast" not found"`
@complexity Logarithmic in the size of the container.
@complexity Logarithmic in the size of the container.
...
@@ -2728,7 +2756,15 @@ class basic_json
...
@@ -2728,7 +2756,15 @@ class basic_json
// at only works for objects
// at only works for objects
if (is_object())
if (is_object())
{
{
return m_value.object->at(key);
try
{
return m_value.object->at(key);
}
catch (std::out_of_range& e)
{
// create better exception explanation
throw std::out_of_range("key '" + key + "' not found");
}
}
}
else
else
{
{
...
...
test/unit.cpp
View file @
67c2d90a
...
@@ -2662,6 +2662,16 @@ TEST_CASE("element access")
...
@@ -2662,6 +2662,16 @@ TEST_CASE("element access")
{
{
CHECK_THROWS_AS
(
j
.
at
(
7
),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
at
(
7
),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j_const
.
at
(
7
),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j_const
.
at
(
7
),
std
::
out_of_range
);
// exception name
try
{
j
.
at
(
7
);
}
catch
(
std
::
out_of_range
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"array index 7 is out of range"
);
}
}
}
SECTION
(
"access on non-array type"
)
SECTION
(
"access on non-array type"
)
...
@@ -2672,6 +2682,16 @@ TEST_CASE("element access")
...
@@ -2672,6 +2682,16 @@ TEST_CASE("element access")
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
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
// exception name
try
{
j_nonarray
.
at
(
0
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with null"
);
}
}
}
SECTION
(
"boolean"
)
SECTION
(
"boolean"
)
...
@@ -2680,6 +2700,16 @@ TEST_CASE("element access")
...
@@ -2680,6 +2700,16 @@ TEST_CASE("element access")
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
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
// exception name
try
{
j_nonarray
.
at
(
0
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with boolean"
);
}
}
}
SECTION
(
"string"
)
SECTION
(
"string"
)
...
@@ -2688,6 +2718,16 @@ TEST_CASE("element access")
...
@@ -2688,6 +2718,16 @@ TEST_CASE("element access")
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
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
// exception name
try
{
j_nonarray
.
at
(
0
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with string"
);
}
}
}
SECTION
(
"object"
)
SECTION
(
"object"
)
...
@@ -2696,6 +2736,16 @@ TEST_CASE("element access")
...
@@ -2696,6 +2736,16 @@ TEST_CASE("element access")
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
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
// exception name
try
{
j_nonarray
.
at
(
0
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with object"
);
}
}
}
SECTION
(
"number (integer)"
)
SECTION
(
"number (integer)"
)
...
@@ -2704,6 +2754,16 @@ TEST_CASE("element access")
...
@@ -2704,6 +2754,16 @@ TEST_CASE("element access")
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
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
// exception name
try
{
j_nonarray
.
at
(
0
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with number"
);
}
}
}
SECTION
(
"number (floating-point)"
)
SECTION
(
"number (floating-point)"
)
...
@@ -2712,6 +2772,16 @@ TEST_CASE("element access")
...
@@ -2712,6 +2772,16 @@ TEST_CASE("element access")
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
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain_error
);
// exception name
try
{
j_nonarray
.
at
(
0
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with number"
);
}
}
}
}
}
}
}
...
@@ -3028,6 +3098,16 @@ TEST_CASE("element access")
...
@@ -3028,6 +3098,16 @@ TEST_CASE("element access")
{
{
CHECK_THROWS_AS
(
j
.
at
(
"foo"
),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j
.
at
(
"foo"
),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j_const
.
at
(
"foo"
),
std
::
out_of_range
);
CHECK_THROWS_AS
(
j_const
.
at
(
"foo"
),
std
::
out_of_range
);
// exception name
try
{
j
.
at
(
"foo"
);
}
catch
(
std
::
out_of_range
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"key 'foo' not found"
);
}
}
}
SECTION
(
"access on non-object type"
)
SECTION
(
"access on non-object type"
)
...
@@ -3038,6 +3118,16 @@ TEST_CASE("element access")
...
@@ -3038,6 +3118,16 @@ TEST_CASE("element access")
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"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
// exception name
try
{
j_nonobject
.
at
(
"foo"
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with null"
);
}
}
}
SECTION
(
"boolean"
)
SECTION
(
"boolean"
)
...
@@ -3046,6 +3136,16 @@ TEST_CASE("element access")
...
@@ -3046,6 +3136,16 @@ TEST_CASE("element access")
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"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
// exception name
try
{
j_nonobject
.
at
(
"foo"
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with boolean"
);
}
}
}
SECTION
(
"string"
)
SECTION
(
"string"
)
...
@@ -3054,6 +3154,16 @@ TEST_CASE("element access")
...
@@ -3054,6 +3154,16 @@ TEST_CASE("element access")
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"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
// exception name
try
{
j_nonobject
.
at
(
"foo"
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with string"
);
}
}
}
SECTION
(
"array"
)
SECTION
(
"array"
)
...
@@ -3062,6 +3172,16 @@ TEST_CASE("element access")
...
@@ -3062,6 +3172,16 @@ TEST_CASE("element access")
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"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
// exception name
try
{
j_nonobject
.
at
(
"foo"
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with array"
);
}
}
}
SECTION
(
"number (integer)"
)
SECTION
(
"number (integer)"
)
...
@@ -3070,6 +3190,16 @@ TEST_CASE("element access")
...
@@ -3070,6 +3190,16 @@ TEST_CASE("element access")
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"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
// exception name
try
{
j_nonobject
.
at
(
"foo"
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"cannot use at() with number"
);
}
}
}
SECTION
(
"number (floating-point)"
)
SECTION
(
"number (floating-point)"
)
...
@@ -3078,6 +3208,16 @@ TEST_CASE("element access")
...
@@ -3078,6 +3208,16 @@ TEST_CASE("element access")
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"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain_error
);
// exception name
try
{
j_nonobject
.
at
(
"foo"
);
}
catch
(
std
::
domain_error
&
e
)
{
CHECK
(
std
::
string
(
e
.
what
())
==
"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