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
cf4a6552
Unverified
Commit
cf4a6552
authored
May 06, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
add tests for binary serialization
parent
3cd2a977
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
0 deletions
+7
-0
test/src/unit-serialization.cpp
test/src/unit-serialization.cpp
+7
-0
No files found.
test/src/unit-serialization.cpp
View file @
cf4a6552
...
@@ -212,13 +212,16 @@ TEST_CASE("dump with binary values")
...
@@ -212,13 +212,16 @@ TEST_CASE("dump with binary values")
SECTION
(
"serialize_binary = false"
)
SECTION
(
"serialize_binary = false"
)
{
{
auto
binary
=
json
::
binary_array
({
1
,
2
,
3
,
4
});
auto
binary
=
json
::
binary_array
({
1
,
2
,
3
,
4
});
auto
binary_empty
=
json
::
binary_array
({});
json
object
=
{{
"key"
,
binary
}};
json
object
=
{{
"key"
,
binary
}};
json
array
=
{
"value"
,
1
,
binary
};
json
array
=
{
"value"
,
1
,
binary
};
CHECK_THROWS_AS
(
binary
.
dump
(),
json
::
type_error
);
CHECK_THROWS_AS
(
binary
.
dump
(),
json
::
type_error
);
CHECK_THROWS_AS
(
binary_empty
.
dump
(),
json
::
type_error
);
CHECK_THROWS_AS
(
object
.
dump
(),
json
::
type_error
);
CHECK_THROWS_AS
(
object
.
dump
(),
json
::
type_error
);
CHECK_THROWS_AS
(
array
.
dump
(),
json
::
type_error
);
CHECK_THROWS_AS
(
array
.
dump
(),
json
::
type_error
);
CHECK_THROWS_WITH
(
binary
.
dump
(),
"[json.exception.type_error.317] cannot serialize binary data to text JSON"
);
CHECK_THROWS_WITH
(
binary
.
dump
(),
"[json.exception.type_error.317] cannot serialize binary data to text JSON"
);
CHECK_THROWS_WITH
(
binary_empty
.
dump
(),
"[json.exception.type_error.317] cannot serialize binary data to text JSON"
);
CHECK_THROWS_WITH
(
object
.
dump
(),
"[json.exception.type_error.317] cannot serialize binary data to text JSON"
);
CHECK_THROWS_WITH
(
object
.
dump
(),
"[json.exception.type_error.317] cannot serialize binary data to text JSON"
);
CHECK_THROWS_WITH
(
array
.
dump
(),
"[json.exception.type_error.317] cannot serialize binary data to text JSON"
);
CHECK_THROWS_WITH
(
array
.
dump
(),
"[json.exception.type_error.317] cannot serialize binary data to text JSON"
);
}
}
...
@@ -226,10 +229,12 @@ TEST_CASE("dump with binary values")
...
@@ -226,10 +229,12 @@ TEST_CASE("dump with binary values")
SECTION
(
"serialize_binary = true"
)
SECTION
(
"serialize_binary = true"
)
{
{
auto
binary
=
json
::
binary_array
({
1
,
2
,
3
,
4
});
auto
binary
=
json
::
binary_array
({
1
,
2
,
3
,
4
});
auto
binary_empty
=
json
::
binary_array
({});
json
object
=
{{
"key"
,
binary
}};
json
object
=
{{
"key"
,
binary
}};
json
array
=
{
"value"
,
1
,
binary
};
json
array
=
{
"value"
,
1
,
binary
};
CHECK
(
binary
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"b[1,2,3,4]"
);
CHECK
(
binary
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"b[1,2,3,4]"
);
CHECK
(
binary_empty
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"b[]"
);
CHECK
(
object
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"{
\"
key
\"
:b[1,2,3,4]}"
);
CHECK
(
object
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"{
\"
key
\"
:b[1,2,3,4]}"
);
CHECK
(
array
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"[
\"
value
\"
,1,b[1,2,3,4]]"
);
CHECK
(
array
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"[
\"
value
\"
,1,b[1,2,3,4]]"
);
}
}
...
@@ -237,10 +242,12 @@ TEST_CASE("dump with binary values")
...
@@ -237,10 +242,12 @@ TEST_CASE("dump with binary values")
SECTION
(
"serialize_binary = true, pretty-printed"
)
SECTION
(
"serialize_binary = true, pretty-printed"
)
{
{
auto
binary
=
json
::
binary_array
({
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
});
auto
binary
=
json
::
binary_array
({
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
,
19
,
20
});
auto
binary_empty
=
json
::
binary_array
({});
json
object
=
{{
"key"
,
binary
}};
json
object
=
{{
"key"
,
binary
}};
json
array
=
{
"value"
,
1
,
binary
};
json
array
=
{
"value"
,
1
,
binary
};
CHECK
(
binary
.
dump
(
4
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"b[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]"
);
CHECK
(
binary
.
dump
(
4
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"b[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]"
);
CHECK
(
binary_empty
.
dump
(
4
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"b[]"
);
CHECK
(
object
.
dump
(
4
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"{
\n
"
CHECK
(
object
.
dump
(
4
,
' '
,
false
,
json
::
error_handler_t
::
strict
,
true
)
==
"{
\n
"
"
\"
key
\"
: b[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
\n
"
"
\"
key
\"
: b[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
\n
"
"}"
);
"}"
);
...
...
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