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
9eb19bcc
Unverified
Commit
9eb19bcc
authored
May 18, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
add more tests for binary type
parent
5dec7166
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
4 deletions
+129
-4
unit-conversions.cpp
test/src/unit-conversions.cpp
+118
-1
unit-modifiers.cpp
test/src/unit-modifiers.cpp
+4
-3
unit-udt.cpp
test/src/unit-udt.cpp
+7
-0
No files found.
test/src/unit-conversions.cpp
View file @
9eb19bcc
...
@@ -189,7 +189,6 @@ TEST_CASE("value conversion")
...
@@ -189,7 +189,6 @@ TEST_CASE("value conversion")
}
}
}
}
SECTION
(
"get an object (implicit)"
)
SECTION
(
"get an object (implicit)"
)
{
{
json
::
object_t
o_reference
=
{{
"object"
,
json
::
object
()},
json
::
object_t
o_reference
=
{{
"object"
,
json
::
object
()},
...
@@ -1259,6 +1258,124 @@ TEST_CASE("value conversion")
...
@@ -1259,6 +1258,124 @@ TEST_CASE("value conversion")
}
}
}
}
SECTION
(
"get a binary value (explicit)"
)
{
json
::
binary_t
n_reference
{{
1
,
2
,
3
}};
json
j
(
n_reference
);
SECTION
(
"binary_t"
)
{
json
::
binary_t
b
=
j
.
get
<
json
::
binary_t
>
();
CHECK
(
*
json
(
b
).
m_value
.
binary
==
*
j
.
m_value
.
binary
);
}
SECTION
(
"get_binary()"
)
{
SECTION
(
"non-const"
)
{
auto
&
b
=
j
.
get_binary
();
CHECK
(
*
json
(
b
).
m_value
.
binary
==
*
j
.
m_value
.
binary
);
}
SECTION
(
"non-const"
)
{
const
json
j_const
=
j
;
const
auto
&
b
=
j_const
.
get_binary
();
CHECK
(
*
json
(
b
).
m_value
.
binary
==
*
j
.
m_value
.
binary
);
}
}
SECTION
(
"exception in case of a non-string type"
)
{
json
j_null
(
json
::
value_t
::
null
);
json
j_object
(
json
::
value_t
::
object
);
json
j_array
(
json
::
value_t
::
array
);
json
j_string
(
json
::
value_t
::
string
);
json
j_boolean
(
json
::
value_t
::
boolean
);
const
json
j_null_const
(
json
::
value_t
::
null
);
const
json
j_object_const
(
json
::
value_t
::
object
);
const
json
j_array_const
(
json
::
value_t
::
array
);
const
json
j_string_const
(
json
::
value_t
::
string
);
const
json
j_boolean_const
(
json
::
value_t
::
boolean
);
CHECK_THROWS_WITH_AS
(
j_null
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is null"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_object
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is object"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_array
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is array"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_string
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is string"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_boolean
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is boolean"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_null_const
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is null"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_object_const
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is object"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_array_const
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is array"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_string_const
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is string"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_boolean_const
.
get
<
json
::
binary_t
>
(),
"[json.exception.type_error.302] type must be binary, but is boolean"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_null
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is null"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_object
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is object"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_array
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is array"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_string
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is string"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_boolean
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is boolean"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_null_const
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is null"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_object_const
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is object"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_array_const
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is array"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_string_const
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is string"
,
json
::
type_error
&
);
CHECK_THROWS_WITH_AS
(
j_boolean_const
.
get_binary
(),
"[json.exception.type_error.302] type must be binary, but is boolean"
,
json
::
type_error
&
);
}
}
SECTION
(
"get a binary value (implicit)"
)
{
json
::
binary_t
n_reference
{{
1
,
2
,
3
}};
json
j
(
n_reference
);
SECTION
(
"binary_t"
)
{
json
::
binary_t
b
=
j
;
CHECK
(
*
json
(
b
).
m_value
.
binary
==
*
j
.
m_value
.
binary
);
}
}
SECTION
(
"get an enum"
)
SECTION
(
"get an enum"
)
{
{
enum
c_enum
{
value_1
,
value_2
};
enum
c_enum
{
value_1
,
value_2
};
...
...
test/src/unit-modifiers.cpp
View file @
9eb19bcc
...
@@ -996,10 +996,11 @@ TEST_CASE("modifiers")
...
@@ -996,10 +996,11 @@ TEST_CASE("modifiers")
SECTION
(
"non-binary_t type"
)
SECTION
(
"non-binary_t type"
)
{
{
json
j
=
17
;
json
j
=
17
;
json
::
binary_t
s
=
{{
1
,
2
,
3
,
4
}};
json
::
binary_t
s1
=
{{
1
,
2
,
3
,
4
}};
std
::
vector
<
std
::
uint8_t
>
s2
=
{{
5
,
6
,
7
,
8
}};
CHECK_THROWS_
AS
(
j
.
swap
(
s
),
json
::
type_error
&
);
CHECK_THROWS_
WITH_AS
(
j
.
swap
(
s1
),
"[json.exception.type_error.310] cannot use swap() with number"
,
json
::
type_error
);
CHECK_THROWS_WITH
(
j
.
swap
(
s
),
"[json.exception.type_error.310] cannot use swap() with number"
);
CHECK_THROWS_WITH
_AS
(
j
.
swap
(
s2
),
"[json.exception.type_error.310] cannot use swap() with number"
,
json
::
type_error
);
}
}
}
}
}
}
...
...
test/src/unit-udt.cpp
View file @
9eb19bcc
...
@@ -763,6 +763,13 @@ TEST_CASE("different basic_json types conversions")
...
@@ -763,6 +763,13 @@ TEST_CASE("different basic_json types conversions")
CHECK
(
cj
==
"forty-two"
);
CHECK
(
cj
==
"forty-two"
);
}
}
SECTION
(
"binary"
)
{
json
j
=
json
::
binary_array
({
1
,
2
,
3
});
custom_json
cj
=
j
;
CHECK
(
cj
.
get_binary
()
==
j
.
get_binary
());
}
SECTION
(
"object"
)
SECTION
(
"object"
)
{
{
json
j
=
{{
"forty"
,
"two"
}};
json
j
=
{{
"forty"
,
"two"
}};
...
...
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