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
a485aa8d
Commit
a485aa8d
authored
Aug 30, 2016
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup and improvement of branch coverage
parent
463ffb21
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
265 additions
and
291 deletions
+265
-291
src/json.hpp
src/json.hpp
+87
-131
src/json.hpp.re2c
src/json.hpp.re2c
+87
-131
test/src/unit-class_const_iterator.cpp
test/src/unit-class_const_iterator.cpp
+16
-0
test/src/unit-deserialization.cpp
test/src/unit-deserialization.cpp
+75
-29
No files found.
src/json.hpp
View file @
a485aa8d
This diff is collapsed.
Click to expand it.
src/json.hpp.re2c
View file @
a485aa8d
This diff is collapsed.
Click to expand it.
test/src/unit-class_const_iterator.cpp
View file @
a485aa8d
...
...
@@ -64,6 +64,22 @@ TEST_CASE("const_iterator class")
json
::
const_iterator
it2
(
&
j
);
it2
=
it
;
}
SECTION
(
"copy constructor from non-const iterator"
)
{
SECTION
(
"create from uninitialized iterator"
)
{
const
json
::
iterator
it
{};
json
::
const_iterator
cit
(
it
);
}
SECTION
(
"create from initialized iterator"
)
{
json
j
;
const
json
::
iterator
it
=
j
.
begin
();
json
::
const_iterator
cit
(
it
);
}
}
}
SECTION
(
"initialization"
)
...
...
test/src/unit-deserialization.cpp
View file @
a485aa8d
...
...
@@ -33,41 +33,87 @@ using nlohmann::json;
TEST_CASE
(
"deserialization"
)
{
SECTION
(
"s
tream
"
)
SECTION
(
"s
uccessful deserialization
"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
;
json
j
=
json
::
parse
(
ss
);
CHECK
(
j
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
SECTION
(
"stream"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
;
json
j
=
json
::
parse
(
ss
);
CHECK
(
j
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
SECTION
(
"string"
)
{
auto
s
=
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
;
json
j
=
json
::
parse
(
s
);
CHECK
(
j
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
SECTION
(
"string"
)
{
json
::
string_t
s
=
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
;
json
j
=
json
::
parse
(
s
);
CHECK
(
j
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
SECTION
(
"operator<<"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
;
json
j
;
j
<<
ss
;
CHECK
(
j
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
SECTION
(
"operator<<"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
;
json
j
;
j
<<
ss
;
CHECK
(
j
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
SECTION
(
"operator>>"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
;
json
j
;
ss
>>
j
;
CHECK
(
j
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
SECTION
(
"operator>>"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
;
json
j
;
ss
>>
j
;
CHECK
(
j
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
SECTION
(
"user-defined string literal"
)
{
CHECK
(
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
_json
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
}
}
SECTION
(
"
user-defined string literal
"
)
SECTION
(
"
successful deserialization
"
)
{
CHECK
(
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}]"
_json
==
json
({
"foo"
,
1
,
2
,
3
,
false
,
{{
"one"
,
1
}}}));
SECTION
(
"stream"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
CHECK_THROWS_AS
(
json
::
parse
(
ss
),
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
json
::
parse
(
ss
),
"parse error - unexpected end of input"
);
}
SECTION
(
"string"
)
{
json
::
string_t
s
=
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
CHECK_THROWS_AS
(
json
::
parse
(
s
),
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
json
::
parse
(
s
),
"parse error - unexpected end of input; expected ']'"
);
}
SECTION
(
"operator<<"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
json
j
;
CHECK_THROWS_AS
(
j
<<
ss
,
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
j
<<
ss
,
"parse error - unexpected end of input"
);
}
SECTION
(
"operator>>"
)
{
std
::
stringstream
ss
;
ss
<<
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
;
json
j
;
CHECK_THROWS_AS
(
ss
>>
j
,
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"parse error - unexpected end of input"
);
}
SECTION
(
"user-defined string literal"
)
{
CHECK_THROWS_AS
(
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
_json
,
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
"[
\"
foo
\"
,1,2,3,false,{
\"
one
\"
:1}"
_json
,
"parse error - unexpected end of input; expected ']'"
);
}
}
}
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