Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
6fb82906
Commit
6fb82906
authored
Jun 14, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some maintenance
- unified used exception types - removed any camel case names
parent
bc55e496
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
224 additions
and
224 deletions
+224
-224
src/json.hpp
src/json.hpp
+58
-58
src/json.hpp.re2c
src/json.hpp.re2c
+58
-58
test/unit.cpp
test/unit.cpp
+108
-108
No files found.
src/json.hpp
View file @
6fb82906
...
...
@@ -500,7 +500,7 @@ class basic_json
// if object is wanted but impossible, throw an exception
if
(
manual_type
==
value_t
::
object
and
not
is_object
)
{
throw
std
::
logic
_error
(
"cannot create JSON object from initializer list"
);
throw
std
::
domain
_error
(
"cannot create JSON object from initializer list"
);
}
}
...
...
@@ -559,7 +559,7 @@ class basic_json
if
(
first
.
m_object
!=
last
.
m_object
or
first
.
m_object
->
m_type
!=
last
.
m_object
->
m_type
)
{
throw
std
::
runtime
_error
(
"iterators are not compatible"
);
throw
std
::
domain
_error
(
"iterators are not compatible"
);
}
// set the type
...
...
@@ -630,7 +630,7 @@ class basic_json
default:
{
throw
std
::
runtime
_error
(
"cannot use construct with iterators from "
+
first
.
m_object
->
type_name
());
throw
std
::
domain
_error
(
"cannot use construct with iterators from "
+
first
.
m_object
->
type_name
());
}
}
}
...
...
@@ -778,7 +778,7 @@ class basic_json
Python's @p json.dumps() function, and currently supports its @p indent
parameter.
@param indent
s
if indent is nonnegative, then array elements and object
@param indent if indent is nonnegative, then array elements and object
members will be pretty-printed with that indent level. An indent level of 0
will only insert newlines. -1 (the default) selects the most compact
representation
...
...
@@ -876,7 +876,7 @@ class basic_json
}
default:
{
throw
std
::
logic
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
throw
std
::
domain
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
}
}
}
...
...
@@ -892,7 +892,7 @@ class basic_json
}
default:
{
throw
std
::
logic
_error
(
"cannot cast "
+
type_name
()
+
" to object"
);
throw
std
::
domain
_error
(
"cannot cast "
+
type_name
()
+
" to object"
);
}
}
}
...
...
@@ -922,7 +922,7 @@ class basic_json
}
default:
{
throw
std
::
logic
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
throw
std
::
domain
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
}
}
}
...
...
@@ -950,7 +950,7 @@ class basic_json
}
default:
{
throw
std
::
logic
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
throw
std
::
domain
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
}
}
}
...
...
@@ -971,7 +971,7 @@ class basic_json
}
default:
{
throw
std
::
logic
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
throw
std
::
domain
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
}
}
}
...
...
@@ -986,7 +986,7 @@ class basic_json
}
default:
{
throw
std
::
logic
_error
(
"cannot cast "
+
type_name
()
+
" to array"
);
throw
std
::
domain
_error
(
"cannot cast "
+
type_name
()
+
" to array"
);
}
}
}
...
...
@@ -1006,7 +1006,7 @@ class basic_json
}
default:
{
throw
std
::
logic
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
throw
std
::
domain
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
}
}
}
...
...
@@ -1030,7 +1030,7 @@ class basic_json
}
default:
{
throw
std
::
logic
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
throw
std
::
domain
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
T
).
name
());
}
}
}
...
...
@@ -1046,7 +1046,7 @@ class basic_json
}
default:
{
throw
std
::
logic
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
boolean_t
).
name
());
throw
std
::
domain
_error
(
"cannot cast "
+
type_name
()
+
" to "
+
typeid
(
boolean_t
).
name
());
}
}
}
...
...
@@ -1078,7 +1078,7 @@ class basic_json
// at only works for arrays
if
(
m_type
!=
value_t
::
array
)
{
throw
std
::
runtime
_error
(
"cannot use at with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use at with "
+
type_name
());
}
return
m_value
.
array
->
at
(
idx
);
...
...
@@ -1090,7 +1090,7 @@ class basic_json
// at only works for arrays
if
(
m_type
!=
value_t
::
array
)
{
throw
std
::
runtime
_error
(
"cannot use at with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use at with "
+
type_name
());
}
return
m_value
.
array
->
at
(
idx
);
...
...
@@ -1102,7 +1102,7 @@ class basic_json
// at only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime
_error
(
"cannot use at with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use at with "
+
type_name
());
}
return
m_value
.
object
->
at
(
key
);
...
...
@@ -1114,7 +1114,7 @@ class basic_json
// at only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime
_error
(
"cannot use at with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use at with "
+
type_name
());
}
return
m_value
.
object
->
at
(
key
);
...
...
@@ -1135,7 +1135,7 @@ class basic_json
// [] only works for arrays
if
(
m_type
!=
value_t
::
array
)
{
throw
std
::
runtime
_error
(
"cannot use [] with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use [] with "
+
type_name
());
}
for
(
size_t
i
=
m_value
.
array
->
size
();
i
<=
idx
;
++
i
)
...
...
@@ -1152,7 +1152,7 @@ class basic_json
// at only works for arrays
if
(
m_type
!=
value_t
::
array
)
{
throw
std
::
runtime
_error
(
"cannot use [] with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use [] with "
+
type_name
());
}
return
m_value
.
array
->
operator
[](
idx
);
...
...
@@ -1173,7 +1173,7 @@ class basic_json
// [] only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime
_error
(
"cannot use [] with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use [] with "
+
type_name
());
}
return
m_value
.
object
->
operator
[](
key
);
...
...
@@ -1185,7 +1185,7 @@ class basic_json
// at only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime
_error
(
"cannot use [] with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use [] with "
+
type_name
());
}
return
m_value
.
object
->
operator
[](
key
);
...
...
@@ -1205,7 +1205,7 @@ class basic_json
// at only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime
_error
(
"cannot use [] with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use [] with "
+
type_name
());
}
return
m_value
.
object
->
operator
[](
key
);
...
...
@@ -1218,7 +1218,7 @@ class basic_json
// at only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime
_error
(
"cannot use [] with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use [] with "
+
type_name
());
}
return
m_value
.
object
->
operator
[](
key
);
...
...
@@ -1264,7 +1264,7 @@ class basic_json
// make sure iterator fits the current value
if
(
this
!=
pos
.
m_object
or
m_type
!=
pos
.
m_object
->
m_type
)
{
throw
std
::
runtime
_error
(
"iterator does not fit current value"
);
throw
std
::
domain
_error
(
"iterator does not fit current value"
);
}
T
result
=
end
();
...
...
@@ -1305,7 +1305,7 @@ class basic_json
default:
{
throw
std
::
runtime
_error
(
"cannot use erase with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use erase with "
+
type_name
());
}
}
...
...
@@ -1325,7 +1325,7 @@ class basic_json
if
(
this
!=
first
.
m_object
or
this
!=
last
.
m_object
or
m_type
!=
first
.
m_object
->
m_type
or
m_type
!=
last
.
m_object
->
m_type
)
{
throw
std
::
runtime
_error
(
"iterators do not fit current value"
);
throw
std
::
domain
_error
(
"iterators do not fit current value"
);
}
T
result
=
end
();
...
...
@@ -1368,7 +1368,7 @@ class basic_json
default:
{
throw
std
::
runtime
_error
(
"cannot use erase with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use erase with "
+
type_name
());
}
}
...
...
@@ -1381,7 +1381,7 @@ class basic_json
// this erase only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime
_error
(
"cannot use erase with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use erase with "
+
type_name
());
}
return
m_value
.
object
->
erase
(
key
);
...
...
@@ -1393,7 +1393,7 @@ class basic_json
// this erase only works for arrays
if
(
m_type
!=
value_t
::
array
)
{
throw
std
::
runtime
_error
(
"cannot use erase with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use erase with "
+
type_name
());
}
if
(
idx
>=
size
())
...
...
@@ -1716,7 +1716,7 @@ class basic_json
// push_back only works for null objects or arrays
if
(
not
(
m_type
==
value_t
::
null
or
m_type
==
value_t
::
array
))
{
throw
std
::
runtime
_error
(
"cannot add element to "
+
type_name
());
throw
std
::
domain
_error
(
"cannot add element to "
+
type_name
());
}
// transform null object into an array
...
...
@@ -1745,7 +1745,7 @@ class basic_json
// push_back only works for null objects or arrays
if
(
not
(
m_type
==
value_t
::
null
or
m_type
==
value_t
::
array
))
{
throw
std
::
runtime
_error
(
"cannot add element to "
+
type_name
());
throw
std
::
domain
_error
(
"cannot add element to "
+
type_name
());
}
// transform null object into an array
...
...
@@ -1772,7 +1772,7 @@ class basic_json
// push_back only works for null objects or objects
if
(
not
(
m_type
==
value_t
::
null
or
m_type
==
value_t
::
object
))
{
throw
std
::
runtime
_error
(
"cannot add element to "
+
type_name
());
throw
std
::
domain
_error
(
"cannot add element to "
+
type_name
());
}
// transform null object into an object
...
...
@@ -1814,7 +1814,7 @@ class basic_json
// swap only works for arrays
if
(
m_type
!=
value_t
::
array
)
{
throw
std
::
runtime
_error
(
"cannot use swap with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use swap with "
+
type_name
());
}
// swap arrays
...
...
@@ -1827,7 +1827,7 @@ class basic_json
// swap only works for objects
if
(
m_type
!=
value_t
::
object
)
{
throw
std
::
runtime
_error
(
"cannot use swap with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use swap with "
+
type_name
());
}
// swap arrays
...
...
@@ -1840,7 +1840,7 @@ class basic_json
// swap only works for strings
if
(
m_type
!=
value_t
::
string
)
{
throw
std
::
runtime
_error
(
"cannot use swap with "
+
type_name
());
throw
std
::
domain
_error
(
"cannot use swap with "
+
type_name
());
}
// swap arrays
...
...
@@ -1976,14 +1976,14 @@ class basic_json
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
o
,
const
basic_json
&
j
)
{
// read width member and use it as indentation parameter if nonzero
const
bool
pretty
P
rint
=
(
o
.
width
()
>
0
);
const
auto
indentation
=
(
pretty
P
rint
?
o
.
width
()
:
0
);
const
bool
pretty
_p
rint
=
(
o
.
width
()
>
0
);
const
auto
indentation
=
(
pretty
_p
rint
?
o
.
width
()
:
0
);
// reset width to 0 for subsequent calls to this stream
o
.
width
(
0
);
// do the actual serialization
j
.
dump
(
o
,
pretty
P
rint
,
static_cast
<
unsigned
int
>
(
indentation
));
j
.
dump
(
o
,
pretty
_p
rint
,
static_cast
<
unsigned
int
>
(
indentation
));
return
o
;
}
...
...
@@ -2169,16 +2169,16 @@ class basic_json
- integer numbers are converted implictly via operator<<
- floating-point numbers are converted to a string using "%g" format
@param o stream to write to
@param pretty
P
rint whether the output shall be pretty-printed
@param indent
S
tep the indent level
@param current
I
ndent the current indent level (only used internally)
@param o
stream to write to
@param pretty
_p
rint whether the output shall be pretty-printed
@param indent
_s
tep the indent level
@param current
_i
ndent the current indent level (only used internally)
*/
void
dump
(
std
::
ostream
&
o
,
const
bool
pretty
Print
,
const
unsigned
int
indentS
tep
,
const
unsigned
int
current
I
ndent
=
0
)
const
noexcept
void
dump
(
std
::
ostream
&
o
,
const
bool
pretty
_print
,
const
unsigned
int
indent_s
tep
,
const
unsigned
int
current
_i
ndent
=
0
)
const
noexcept
{
// variable to hold indentation for recursive calls
auto
new_indent
=
currentI
ndent
;
unsigned
int
new_indent
=
current_i
ndent
;
switch
(
m_type
)
{
...
...
@@ -2193,9 +2193,9 @@ class basic_json
o
<<
"{"
;
// increase indentation
if
(
pretty
P
rint
)
if
(
pretty
_p
rint
)
{
new_indent
+=
indent
S
tep
;
new_indent
+=
indent
_s
tep
;
o
<<
"
\n
"
;
}
...
...
@@ -2203,18 +2203,18 @@ class basic_json
{
if
(
i
!=
m_value
.
object
->
cbegin
())
{
o
<<
(
pretty
P
rint
?
",
\n
"
:
","
);
o
<<
(
pretty
_p
rint
?
",
\n
"
:
","
);
}
o
<<
string_t
(
new_indent
,
' '
)
<<
"
\"
"
;
escape_string
(
o
,
i
->
first
);
o
<<
"
\"
:"
<<
(
pretty
P
rint
?
" "
:
""
);
i
->
second
.
dump
(
o
,
pretty
Print
,
indentS
tep
,
new_indent
);
o
<<
"
\"
:"
<<
(
pretty
_p
rint
?
" "
:
""
);
i
->
second
.
dump
(
o
,
pretty
_print
,
indent_s
tep
,
new_indent
);
}
// decrease indentation
if
(
pretty
P
rint
)
if
(
pretty
_p
rint
)
{
new_indent
-=
indent
S
tep
;
new_indent
-=
indent
_s
tep
;
o
<<
"
\n
"
;
}
...
...
@@ -2233,9 +2233,9 @@ class basic_json
o
<<
"["
;
// increase indentation
if
(
pretty
P
rint
)
if
(
pretty
_p
rint
)
{
new_indent
+=
indent
S
tep
;
new_indent
+=
indent
_s
tep
;
o
<<
"
\n
"
;
}
...
...
@@ -2243,16 +2243,16 @@ class basic_json
{
if
(
i
!=
m_value
.
array
->
cbegin
())
{
o
<<
(
pretty
P
rint
?
",
\n
"
:
","
);
o
<<
(
pretty
_p
rint
?
",
\n
"
:
","
);
}
o
<<
string_t
(
new_indent
,
' '
);
i
->
dump
(
o
,
pretty
Print
,
indentS
tep
,
new_indent
);
i
->
dump
(
o
,
pretty
_print
,
indent_s
tep
,
new_indent
);
}
// decrease indentation
if
(
pretty
P
rint
)
if
(
pretty
_p
rint
)
{
new_indent
-=
indent
S
tep
;
new_indent
-=
indent
_s
tep
;
o
<<
"
\n
"
;
}
...
...
src/json.hpp.re2c
View file @
6fb82906
...
...
@@ -500,7 +500,7 @@ class basic_json
// if object is wanted but impossible, throw an exception
if (manual_type == value_t::object and not is_object)
{
throw std::
logic
_error("cannot create JSON object from initializer list");
throw std::
domain
_error("cannot create JSON object from initializer list");
}
}
...
...
@@ -559,7 +559,7 @@ class basic_json
if (first.m_object != last.m_object or
first.m_object->m_type != last.m_object->m_type)
{
throw std::
runtime
_error("iterators are not compatible");
throw std::
domain
_error("iterators are not compatible");
}
// set the type
...
...
@@ -630,7 +630,7 @@ class basic_json
default:
{
throw std::
runtime
_error("cannot use construct with iterators from " + first.m_object->type_name());
throw std::
domain
_error("cannot use construct with iterators from " + first.m_object->type_name());
}
}
}
...
...
@@ -778,7 +778,7 @@ class basic_json
Python's @p json.dumps() function, and currently supports its @p indent
parameter.
@param indent
s
if indent is nonnegative, then array elements and object
@param indent if indent is nonnegative, then array elements and object
members will be pretty-printed with that indent level. An indent level of 0
will only insert newlines. -1 (the default) selects the most compact
representation
...
...
@@ -876,7 +876,7 @@ class basic_json
}
default:
{
throw std::
logic
_error("cannot cast " + type_name() + " to " + typeid(T).name());
throw std::
domain
_error("cannot cast " + type_name() + " to " + typeid(T).name());
}
}
}
...
...
@@ -892,7 +892,7 @@ class basic_json
}
default:
{
throw std::
logic
_error("cannot cast " + type_name() + " to object");
throw std::
domain
_error("cannot cast " + type_name() + " to object");
}
}
}
...
...
@@ -922,7 +922,7 @@ class basic_json
}
default:
{
throw std::
logic
_error("cannot cast " + type_name() + " to " + typeid(T).name());
throw std::
domain
_error("cannot cast " + type_name() + " to " + typeid(T).name());
}
}
}
...
...
@@ -950,7 +950,7 @@ class basic_json
}
default:
{
throw std::
logic
_error("cannot cast " + type_name() + " to " + typeid(T).name());
throw std::
domain
_error("cannot cast " + type_name() + " to " + typeid(T).name());
}
}
}
...
...
@@ -971,7 +971,7 @@ class basic_json
}
default:
{
throw std::
logic
_error("cannot cast " + type_name() + " to " + typeid(T).name());
throw std::
domain
_error("cannot cast " + type_name() + " to " + typeid(T).name());
}
}
}
...
...
@@ -986,7 +986,7 @@ class basic_json
}
default:
{
throw std::
logic
_error("cannot cast " + type_name() + " to array");
throw std::
domain
_error("cannot cast " + type_name() + " to array");
}
}
}
...
...
@@ -1006,7 +1006,7 @@ class basic_json
}
default:
{
throw std::
logic
_error("cannot cast " + type_name() + " to " + typeid(T).name());
throw std::
domain
_error("cannot cast " + type_name() + " to " + typeid(T).name());
}
}
}
...
...
@@ -1030,7 +1030,7 @@ class basic_json
}
default:
{
throw std::
logic
_error("cannot cast " + type_name() + " to " + typeid(T).name());
throw std::
domain
_error("cannot cast " + type_name() + " to " + typeid(T).name());
}
}
}
...
...
@@ -1046,7 +1046,7 @@ class basic_json
}
default:
{
throw std::
logic
_error("cannot cast " + type_name() + " to " + typeid(boolean_t).name());
throw std::
domain
_error("cannot cast " + type_name() + " to " + typeid(boolean_t).name());
}
}
}
...
...
@@ -1078,7 +1078,7 @@ class basic_json
// at only works for arrays
if (m_type != value_t::array)
{
throw std::
runtime
_error("cannot use at with " + type_name());
throw std::
domain
_error("cannot use at with " + type_name());
}
return m_value.array->at(idx);
...
...
@@ -1090,7 +1090,7 @@ class basic_json
// at only works for arrays
if (m_type != value_t::array)
{
throw std::
runtime
_error("cannot use at with " + type_name());
throw std::
domain
_error("cannot use at with " + type_name());
}
return m_value.array->at(idx);
...
...
@@ -1102,7 +1102,7 @@ class basic_json
// at only works for objects
if (m_type != value_t::object)
{
throw std::
runtime
_error("cannot use at with " + type_name());
throw std::
domain
_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
...
...
@@ -1114,7 +1114,7 @@ class basic_json
// at only works for objects
if (m_type != value_t::object)
{
throw std::
runtime
_error("cannot use at with " + type_name());
throw std::
domain
_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
...
...
@@ -1135,7 +1135,7 @@ class basic_json
// [] only works for arrays
if (m_type != value_t::array)
{
throw std::
runtime
_error("cannot use [] with " + type_name());
throw std::
domain
_error("cannot use [] with " + type_name());
}
for (size_t i = m_value.array->size(); i <= idx; ++i)
...
...
@@ -1152,7 +1152,7 @@ class basic_json
// at only works for arrays
if (m_type != value_t::array)
{
throw std::
runtime
_error("cannot use [] with " + type_name());
throw std::
domain
_error("cannot use [] with " + type_name());
}
return m_value.array->operator[](idx);
...
...
@@ -1173,7 +1173,7 @@ class basic_json
// [] only works for objects
if (m_type != value_t::object)
{
throw std::
runtime
_error("cannot use [] with " + type_name());
throw std::
domain
_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
...
...
@@ -1185,7 +1185,7 @@ class basic_json
// at only works for objects
if (m_type != value_t::object)
{
throw std::
runtime
_error("cannot use [] with " + type_name());
throw std::
domain
_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
...
...
@@ -1205,7 +1205,7 @@ class basic_json
// at only works for objects
if (m_type != value_t::object)
{
throw std::
runtime
_error("cannot use [] with " + type_name());
throw std::
domain
_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
...
...
@@ -1218,7 +1218,7 @@ class basic_json
// at only works for objects
if (m_type != value_t::object)
{
throw std::
runtime
_error("cannot use [] with " + type_name());
throw std::
domain
_error("cannot use [] with " + type_name());
}
return m_value.object->operator[](key);
...
...
@@ -1264,7 +1264,7 @@ class basic_json
// make sure iterator fits the current value
if (this != pos.m_object or m_type != pos.m_object->m_type)
{
throw std::
runtime
_error("iterator does not fit current value");
throw std::
domain
_error("iterator does not fit current value");
}
T result = end();
...
...
@@ -1305,7 +1305,7 @@ class basic_json
default:
{
throw std::
runtime
_error("cannot use erase with " + type_name());
throw std::
domain
_error("cannot use erase with " + type_name());
}
}
...
...
@@ -1325,7 +1325,7 @@ class basic_json
if (this != first.m_object or this != last.m_object or
m_type != first.m_object->m_type or m_type != last.m_object->m_type)
{
throw std::
runtime
_error("iterators do not fit current value");
throw std::
domain
_error("iterators do not fit current value");
}
T result = end();
...
...
@@ -1368,7 +1368,7 @@ class basic_json
default:
{
throw std::
runtime
_error("cannot use erase with " + type_name());
throw std::
domain
_error("cannot use erase with " + type_name());
}
}
...
...
@@ -1381,7 +1381,7 @@ class basic_json
// this erase only works for objects
if (m_type != value_t::object)
{
throw std::
runtime
_error("cannot use erase with " + type_name());
throw std::
domain
_error("cannot use erase with " + type_name());
}
return m_value.object->erase(key);
...
...
@@ -1393,7 +1393,7 @@ class basic_json
// this erase only works for arrays
if (m_type != value_t::array)
{
throw std::
runtime
_error("cannot use erase with " + type_name());
throw std::
domain
_error("cannot use erase with " + type_name());
}
if (idx >= size())
...
...
@@ -1716,7 +1716,7 @@ class basic_json
// push_back only works for null objects or arrays
if (not(m_type == value_t::null or m_type == value_t::array))
{
throw std::
runtime
_error("cannot add element to " + type_name());
throw std::
domain
_error("cannot add element to " + type_name());
}
// transform null object into an array
...
...
@@ -1745,7 +1745,7 @@ class basic_json
// push_back only works for null objects or arrays
if (not(m_type == value_t::null or m_type == value_t::array))
{
throw std::
runtime
_error("cannot add element to " + type_name());
throw std::
domain
_error("cannot add element to " + type_name());
}
// transform null object into an array
...
...
@@ -1772,7 +1772,7 @@ class basic_json
// push_back only works for null objects or objects
if (not(m_type == value_t::null or m_type == value_t::object))
{
throw std::
runtime
_error("cannot add element to " + type_name());
throw std::
domain
_error("cannot add element to " + type_name());
}
// transform null object into an object
...
...
@@ -1814,7 +1814,7 @@ class basic_json
// swap only works for arrays
if (m_type != value_t::array)
{
throw std::
runtime
_error("cannot use swap with " + type_name());
throw std::
domain
_error("cannot use swap with " + type_name());
}
// swap arrays
...
...
@@ -1827,7 +1827,7 @@ class basic_json
// swap only works for objects
if (m_type != value_t::object)
{
throw std::
runtime
_error("cannot use swap with " + type_name());
throw std::
domain
_error("cannot use swap with " + type_name());
}
// swap arrays
...
...
@@ -1840,7 +1840,7 @@ class basic_json
// swap only works for strings
if (m_type != value_t::string)
{
throw std::
runtime
_error("cannot use swap with " + type_name());
throw std::
domain
_error("cannot use swap with " + type_name());
}
// swap arrays
...
...
@@ -1976,14 +1976,14 @@ class basic_json
friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
{
// read width member and use it as indentation parameter if nonzero
const bool pretty
P
rint = (o.width() > 0);
const auto indentation = (pretty
P
rint ? o.width() : 0);
const bool pretty
_p
rint = (o.width() > 0);
const auto indentation = (pretty
_p
rint ? o.width() : 0);
// reset width to 0 for subsequent calls to this stream
o.width(0);
// do the actual serialization
j.dump(o, pretty
P
rint, static_cast<unsigned int>(indentation));
j.dump(o, pretty
_p
rint, static_cast<unsigned int>(indentation));
return o;
}
...
...
@@ -2169,16 +2169,16 @@ class basic_json
- integer numbers are converted implictly via operator<<
- floating-point numbers are converted to a string using "%g" format
@param o stream to write to
@param pretty
P
rint whether the output shall be pretty-printed
@param indent
S
tep the indent level
@param current
I
ndent the current indent level (only used internally)
@param o
stream to write to
@param pretty
_p
rint whether the output shall be pretty-printed
@param indent
_s
tep the indent level
@param current
_i
ndent the current indent level (only used internally)
*/
void dump(std::ostream& o, const bool pretty
Print, const unsigned int indentS
tep,
const unsigned int current
I
ndent = 0) const noexcept
void dump(std::ostream& o, const bool pretty
_print, const unsigned int indent_s
tep,
const unsigned int current
_i
ndent = 0) const noexcept
{
// variable to hold indentation for recursive calls
auto new_indent = currentI
ndent;
unsigned int new_indent = current_i
ndent;
switch (m_type)
{
...
...
@@ -2193,9 +2193,9 @@ class basic_json
o << "{";
// increase indentation
if (pretty
P
rint)
if (pretty
_p
rint)
{
new_indent += indent
S
tep;
new_indent += indent
_s
tep;
o << "\n";
}
...
...
@@ -2203,18 +2203,18 @@ class basic_json
{
if (i != m_value.object->cbegin())
{
o << (pretty
P
rint ? ",\n" : ",");
o << (pretty
_p
rint ? ",\n" : ",");
}
o << string_t(new_indent, ' ') << "\"";
escape_string(o, i->first);
o << "\":" << (pretty
P
rint ? " " : "");
i->second.dump(o, pretty
Print, indentS
tep, new_indent);
o << "\":" << (pretty
_p
rint ? " " : "");
i->second.dump(o, pretty
_print, indent_s
tep, new_indent);
}
// decrease indentation
if (pretty
P
rint)
if (pretty
_p
rint)
{
new_indent -= indent
S
tep;
new_indent -= indent
_s
tep;
o << "\n";
}
...
...
@@ -2233,9 +2233,9 @@ class basic_json
o << "[";
// increase indentation
if (pretty
P
rint)
if (pretty
_p
rint)
{
new_indent += indent
S
tep;
new_indent += indent
_s
tep;
o << "\n";
}
...
...
@@ -2243,16 +2243,16 @@ class basic_json
{
if (i != m_value.array->cbegin())
{
o << (pretty
P
rint ? ",\n" : ",");
o << (pretty
_p
rint ? ",\n" : ",");
}
o << string_t(new_indent, ' ');
i->dump(o, pretty
Print, indentS
tep, new_indent);
i->dump(o, pretty
_print, indent_s
tep, new_indent);
}
// decrease indentation
if (pretty
P
rint)
if (pretty
_p
rint)
{
new_indent -= indent
S
tep;
new_indent -= indent
_s
tep;
o << "\n";
}
...
...
test/unit.cpp
View file @
6fb82906
...
...
@@ -966,14 +966,14 @@ TEST_CASE("constructors")
{
json
jobject
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17
},
{
"d"
,
false
},
{
"e"
,
true
}};
json
jobject2
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17
}};
CHECK_THROWS_AS
(
json
(
jobject
.
begin
(),
jobject2
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
jobject2
.
begin
(),
jobject
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
jobject
.
begin
(),
jobject2
.
end
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
json
(
jobject2
.
begin
(),
jobject
.
end
()),
std
::
domain
_error
);
}
{
json
jobject
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17
},
{
"d"
,
false
},
{
"e"
,
true
}};
json
jobject2
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17
}};
CHECK_THROWS_AS
(
json
(
jobject
.
cbegin
(),
jobject2
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
jobject2
.
cbegin
(),
jobject
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
jobject
.
cbegin
(),
jobject2
.
cend
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
json
(
jobject2
.
cbegin
(),
jobject
.
cend
()),
std
::
domain
_error
);
}
}
}
...
...
@@ -1027,14 +1027,14 @@ TEST_CASE("constructors")
{
json
jarray
=
{
1
,
2
,
3
,
4
};
json
jarray2
=
{
2
,
3
,
4
,
5
};
CHECK_THROWS_AS
(
json
(
jarray
.
begin
(),
jarray2
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
jarray2
.
begin
(),
jarray
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
jarray
.
begin
(),
jarray2
.
end
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
json
(
jarray2
.
begin
(),
jarray
.
end
()),
std
::
domain
_error
);
}
{
json
jarray
=
{
1
,
2
,
3
,
4
};
json
jarray2
=
{
2
,
3
,
4
,
5
};
CHECK_THROWS_AS
(
json
(
jarray
.
cbegin
(),
jarray2
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
jarray2
.
cbegin
(),
jarray
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
jarray
.
cbegin
(),
jarray2
.
cend
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
json
(
jarray2
.
cbegin
(),
jarray
.
cend
()),
std
::
domain
_error
);
}
}
}
...
...
@@ -1047,11 +1047,11 @@ TEST_CASE("constructors")
{
{
json
j
;
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
j
.
begin
(),
j
.
end
()),
std
::
domain
_error
);
}
{
json
j
;
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
json
(
j
.
cbegin
(),
j
.
cend
()),
std
::
domain
_error
);
}
}
...
...
@@ -2458,48 +2458,48 @@ TEST_CASE("element access")
{
json
j_nonarray
(
json
::
value_t
::
null
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
}
SECTION
(
"boolean"
)
{
json
j_nonarray
(
json
::
value_t
::
boolean
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
}
SECTION
(
"string"
)
{
json
j_nonarray
(
json
::
value_t
::
string
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
}
SECTION
(
"object"
)
{
json
j_nonarray
(
json
::
value_t
::
object
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
}
SECTION
(
"number (integer)"
)
{
json
j_nonarray
(
json
::
value_t
::
number_integer
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonarray
(
json
::
value_t
::
number_float
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
.
at
(
0
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
.
at
(
0
),
std
::
domain
_error
);
}
}
}
...
...
@@ -2542,7 +2542,7 @@ TEST_CASE("element access")
json
j_nonarray
(
json
::
value_t
::
null
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_NOTHROW
(
j_nonarray
[
0
]);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
}
SECTION
(
"implicit transformation to properly filled array"
)
...
...
@@ -2557,40 +2557,40 @@ TEST_CASE("element access")
{
json
j_nonarray
(
json
::
value_t
::
boolean
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
}
SECTION
(
"string"
)
{
json
j_nonarray
(
json
::
value_t
::
string
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
}
SECTION
(
"object"
)
{
json
j_nonarray
(
json
::
value_t
::
object
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
}
SECTION
(
"number (integer)"
)
{
json
j_nonarray
(
json
::
value_t
::
number_integer
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonarray
(
json
::
value_t
::
number_float
);
const
json
j_nonarray_const
(
j_nonarray
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonarray
[
0
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonarray_const
[
0
],
std
::
domain
_error
);
}
}
}
...
...
@@ -2729,18 +2729,18 @@ TEST_CASE("element access")
{
json
jarray
=
{
1
,
true
,
nullptr
,
"string"
,
42.23
,
json
::
object
(),
{
1
,
2
,
3
}};
json
jarray2
=
{
"foo"
,
"bar"
};
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
begin
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray
.
begin
(),
jarray2
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
begin
(),
jarray
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
begin
(),
jarray2
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
begin
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray
.
begin
(),
jarray2
.
end
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
begin
(),
jarray
.
end
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
begin
(),
jarray2
.
end
()),
std
::
domain
_error
);
}
{
json
jarray
=
{
1
,
true
,
nullptr
,
"string"
,
42.23
,
json
::
object
(),
{
1
,
2
,
3
}};
json
jarray2
=
{
"foo"
,
"bar"
};
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
cbegin
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray
.
cbegin
(),
jarray2
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
cbegin
(),
jarray
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
cbegin
(),
jarray2
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
cbegin
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray
.
cbegin
(),
jarray2
.
cend
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
cbegin
(),
jarray
.
cend
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jarray
.
erase
(
jarray2
.
cbegin
(),
jarray2
.
cend
()),
std
::
domain
_error
);
}
}
}
...
...
@@ -2750,37 +2750,37 @@ TEST_CASE("element access")
SECTION
(
"null"
)
{
json
j_nonobject
(
json
::
value_t
::
null
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
domain
_error
);
}
SECTION
(
"boolean"
)
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
domain
_error
);
}
SECTION
(
"string"
)
{
json
j_nonobject
(
json
::
value_t
::
string
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
domain
_error
);
}
SECTION
(
"object"
)
{
json
j_nonobject
(
json
::
value_t
::
object
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
domain
_error
);
}
SECTION
(
"number (integer)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
domain
_error
);
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
0
),
std
::
domain
_error
);
}
}
}
...
...
@@ -2824,48 +2824,48 @@ TEST_CASE("element access")
{
json
j_nonobject
(
json
::
value_t
::
null
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
}
SECTION
(
"boolean"
)
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
}
SECTION
(
"string"
)
{
json
j_nonobject
(
json
::
value_t
::
string
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
}
SECTION
(
"array"
)
{
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_nonobject_const
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
}
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"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
}
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"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
at
(
"foo"
),
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject_const
.
at
(
"foo"
),
std
::
domain
_error
);
}
}
}
...
...
@@ -2929,58 +2929,58 @@ TEST_CASE("element access")
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"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
}
SECTION
(
"boolean"
)
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
}
SECTION
(
"string"
)
{
json
j_nonobject
(
json
::
value_t
::
string
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
}
SECTION
(
"array"
)
{
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
}
SECTION
(
"number (integer)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
const
json
j_const_nonobject
(
j_nonobject
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
"foo"
],
std
::
domain
_error
);
CHECK_THROWS_AS
(
j_const_nonobject
[
json
::
object_t
::
key_type
(
"foo"
)],
std
::
domain
_error
);
}
}
}
...
...
@@ -3114,18 +3114,18 @@ TEST_CASE("element access")
{
json
jobject
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17
},
{
"d"
,
false
},
{
"e"
,
true
}};
json
jobject2
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17
}};
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject
.
begin
(),
jobject2
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
(),
jobject
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
(),
jobject2
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject
.
begin
(),
jobject2
.
end
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
(),
jobject
.
end
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
begin
(),
jobject2
.
end
()),
std
::
domain
_error
);
}
{
json
jobject
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17
},
{
"d"
,
false
},
{
"e"
,
true
}};
json
jobject2
=
{{
"a"
,
"a"
},
{
"b"
,
1
},
{
"c"
,
17
}};
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject
.
cbegin
(),
jobject2
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
(),
jobject
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
(),
jobject2
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject
.
cbegin
(),
jobject2
.
cend
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
(),
jobject
.
cend
()),
std
::
domain
_error
);
CHECK_THROWS_AS
(
jobject
.
erase
(
jobject2
.
cbegin
(),
jobject2
.
cend
()),
std
::
domain
_error
);
}
}
}
...
...
@@ -3135,37 +3135,37 @@ TEST_CASE("element access")
SECTION
(
"null"
)
{
json
j_nonobject
(
json
::
value_t
::
null
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain
_error
);
}
SECTION
(
"boolean"
)
{
json
j_nonobject
(
json
::
value_t
::
boolean
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain
_error
);
}
SECTION
(
"string"
)
{
json
j_nonobject
(
json
::
value_t
::
string
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain
_error
);
}
SECTION
(
"array"
)
{
json
j_nonobject
(
json
::
value_t
::
array
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain
_error
);
}
SECTION
(
"number (integer)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_integer
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain
_error
);
}
SECTION
(
"number (floating-point)"
)
{
json
j_nonobject
(
json
::
value_t
::
number_float
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j_nonobject
.
erase
(
"foo"
),
std
::
domain
_error
);
}
}
}
...
...
@@ -3412,11 +3412,11 @@ TEST_CASE("element access")
{
{
json
j
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
begin
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
begin
()),
std
::
domain
_error
);
}
{
json
j
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cbegin
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cbegin
()),
std
::
domain
_error
);
}
}
...
...
@@ -3542,11 +3542,11 @@ TEST_CASE("element access")
{
{
json
j
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
begin
(),
j
.
end
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
begin
(),
j
.
end
()),
std
::
domain
_error
);
}
{
json
j
;
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cbegin
(),
j
.
cend
()),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
erase
(
j
.
cbegin
(),
j
.
cend
()),
std
::
domain
_error
);
}
}
...
...
@@ -5889,7 +5889,7 @@ TEST_CASE("modifiers")
SECTION
(
"other type"
)
{
json
j
=
1
;
CHECK_THROWS_AS
(
j
.
push_back
(
"Hello"
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
push_back
(
"Hello"
),
std
::
domain
_error
);
}
}
...
...
@@ -5918,7 +5918,7 @@ TEST_CASE("modifiers")
{
json
j
=
1
;
json
k
(
"Hello"
);
CHECK_THROWS_AS
(
j
.
push_back
(
k
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
push_back
(
k
),
std
::
domain
_error
);
}
}
}
...
...
@@ -5950,7 +5950,7 @@ TEST_CASE("modifiers")
{
json
j
=
1
;
json
k
(
"Hello"
);
CHECK_THROWS_AS
(
j
.
push_back
(
json
::
object_t
::
value_type
({
"one"
,
1
})),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
push_back
(
json
::
object_t
::
value_type
({
"one"
,
1
})),
std
::
domain
_error
);
}
}
}
...
...
@@ -5981,7 +5981,7 @@ TEST_CASE("modifiers")
SECTION
(
"other type"
)
{
json
j
=
1
;
CHECK_THROWS_AS
(
j
+=
"Hello"
,
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
+=
"Hello"
,
std
::
domain
_error
);
}
}
...
...
@@ -6010,7 +6010,7 @@ TEST_CASE("modifiers")
{
json
j
=
1
;
json
k
(
"Hello"
);
CHECK_THROWS_AS
(
j
+=
k
,
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
+=
k
,
std
::
domain
_error
);
}
}
}
...
...
@@ -6042,7 +6042,7 @@ TEST_CASE("modifiers")
{
json
j
=
1
;
json
k
(
"Hello"
);
CHECK_THROWS_AS
(
j
+=
json
::
object_t
::
value_type
({
"one"
,
1
}),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
+=
json
::
object_t
::
value_type
({
"one"
,
1
}),
std
::
domain
_error
);
}
}
}
...
...
@@ -6095,7 +6095,7 @@ TEST_CASE("modifiers")
json
j
=
17
;
json
::
array_t
a
=
{
"foo"
,
"bar"
,
"baz"
};
CHECK_THROWS_AS
(
j
.
swap
(
a
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
swap
(
a
),
std
::
domain
_error
);
}
}
...
...
@@ -6120,7 +6120,7 @@ TEST_CASE("modifiers")
json
j
=
17
;
json
::
object_t
o
=
{{
"cow"
,
"Kuh"
},
{
"chicken"
,
"Huhn"
}};
CHECK_THROWS_AS
(
j
.
swap
(
o
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
swap
(
o
),
std
::
domain
_error
);
}
}
...
...
@@ -6145,7 +6145,7 @@ TEST_CASE("modifiers")
json
j
=
17
;
json
::
string_t
s
=
"Hallo Welt"
;
CHECK_THROWS_AS
(
j
.
swap
(
s
),
std
::
runtime
_error
);
CHECK_THROWS_AS
(
j
.
swap
(
s
),
std
::
domain
_error
);
}
}
}
...
...
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