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
f466919e
Commit
f466919e
authored
Jun 17, 2020
by
chenguoping
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change test cases
parent
8aaa4013
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
39 deletions
+2
-39
test/src/unit-element_access2.cpp
test/src/unit-element_access2.cpp
+2
-39
No files found.
test/src/unit-element_access2.cpp
View file @
f466919e
...
...
@@ -148,45 +148,6 @@ TEST_CASE("element access 2")
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
(
"access existing value"
)
...
...
@@ -226,6 +187,7 @@ TEST_CASE("element access 2")
CHECK
(
j
.
value
(
"_"
,
12.34
)
==
Approx
(
12.34
));
CHECK
(
j
.
value
(
"_"
,
json
({{
"foo"
,
"bar"
}}))
==
json
({{
"foo"
,
"bar"
}}));
CHECK
(
j
.
value
(
"_"
,
json
({
10
,
100
}))
==
json
({
10
,
100
}));
CHECK
(
j
.
value
(
"_"
,
std
::
move
(
"default_value"
))
==
"default_value"
);
CHECK
(
j_const
.
value
(
"_"
,
2
)
==
2
);
CHECK
(
j_const
.
value
(
"_"
,
2u
)
==
2u
);
...
...
@@ -234,6 +196,7 @@ TEST_CASE("element access 2")
CHECK
(
j_const
.
value
(
"_"
,
12.34
)
==
Approx
(
12.34
));
CHECK
(
j_const
.
value
(
"_"
,
json
({{
"foo"
,
"bar"
}}))
==
json
({{
"foo"
,
"bar"
}}));
CHECK
(
j_const
.
value
(
"_"
,
json
({
10
,
100
}))
==
json
({
10
,
100
}));
CHECK
(
j_const
.
value
(
"_"
,
std
::
move
(
"default_value"
))
==
"default_value"
);
}
SECTION
(
"access on non-object type"
)
...
...
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