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
a3df26b7
Commit
a3df26b7
authored
Jun 10, 2020
by
chenguoping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some test cases
parent
71830be0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
unit-element_access2.cpp
test/src/unit-element_access2.cpp
+39
-0
No files found.
test/src/unit-element_access2.cpp
View file @
a3df26b7
...
@@ -148,6 +148,45 @@ TEST_CASE("element access 2")
...
@@ -148,6 +148,45 @@ TEST_CASE("element access 2")
SECTION
(
"access specified element with default value"
)
SECTION
(
"access specified element with default value"
)
{
{
SECTION
(
"move semantics"
)
{
SECTION
(
"json is rvalue"
)
{
json
j
=
{{
"x"
,
"123"
}};
std
::
string
defval
=
"default"
;
auto
val
=
std
::
move
(
j
).
value
(
"x"
,
defval
);
CHECK
(
j
[
"x"
]
==
""
);
CHECK
(
defval
==
"default"
);
CHECK
(
val
==
"123"
);
}
SECTION
(
"default is rvalue"
)
{
json
j
=
{{
"x"
,
"123"
}};
std
::
string
defval
=
"default"
;
auto
val
=
std
::
move
(
j
).
value
(
"y"
,
std
::
move
(
defval
));
CHECK
(
j
[
"x"
]
==
"123"
);
CHECK
(
defval
==
""
);
CHECK
(
val
==
"default"
);
}
SECTION
(
"access on non-object value"
)
{
json
j_nonobject
(
json
::
value_t
::
array
);
const
json
j_nonobject_const
(
j_nonobject
);
std
::
string
defval
=
"default"
;
CHECK_THROWS_AS
(
std
::
move
(
j_nonobject
).
value
(
"foo"
,
defval
),
json
::
type_error
&
);
CHECK_THROWS_AS
(
std
::
move
(
j_nonobject_const
).
value
(
"foo"
,
defval
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
std
::
move
(
j_nonobject
).
value
(
"foo"
,
defval
),
"[json.exception.type_error.306] cannot use value() with array"
);
CHECK_THROWS_WITH
(
std
::
move
(
j_nonobject_const
).
value
(
"foo"
,
defval
),
"[json.exception.type_error.306] cannot use value() with array"
);
}
}
SECTION
(
"given a key"
)
SECTION
(
"given a key"
)
{
{
SECTION
(
"access existing value"
)
SECTION
(
"access existing value"
)
...
...
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