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
2a34f4cd
Unverified
Commit
2a34f4cd
authored
May 04, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
add tests for binary type
parent
48aa4416
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
86 additions
and
0 deletions
+86
-0
unit-comparison.cpp
test/src/unit-comparison.cpp
+0
-0
unit-convenience.cpp
test/src/unit-convenience.cpp
+1
-0
unit-inspection.cpp
test/src/unit-inspection.cpp
+34
-0
unit-modifiers.cpp
test/src/unit-modifiers.cpp
+51
-0
No files found.
test/src/unit-comparison.cpp
View file @
2a34f4cd
This diff is collapsed.
Click to expand it.
test/src/unit-convenience.cpp
View file @
2a34f4cd
...
...
@@ -58,6 +58,7 @@ TEST_CASE("convenience functions")
CHECK
(
std
::
string
(
json
(
json
::
value_t
::
number_integer
).
type_name
())
==
"number"
);
CHECK
(
std
::
string
(
json
(
json
::
value_t
::
number_unsigned
).
type_name
())
==
"number"
);
CHECK
(
std
::
string
(
json
(
json
::
value_t
::
number_float
).
type_name
())
==
"number"
);
CHECK
(
std
::
string
(
json
(
json
::
value_t
::
binary
).
type_name
())
==
"binary"
);
CHECK
(
std
::
string
(
json
(
json
::
value_t
::
boolean
).
type_name
())
==
"boolean"
);
CHECK
(
std
::
string
(
json
(
json
::
value_t
::
string
).
type_name
())
==
"string"
);
CHECK
(
std
::
string
(
json
(
json
::
value_t
::
discarded
).
type_name
())
==
"discarded"
);
...
...
test/src/unit-inspection.cpp
View file @
2a34f4cd
...
...
@@ -49,6 +49,7 @@ TEST_CASE("object inspection")
CHECK
(
not
j
.
is_number_integer
());
CHECK
(
not
j
.
is_number_unsigned
());
CHECK
(
not
j
.
is_number_float
());
CHECK
(
not
j
.
is_binary
());
CHECK
(
j
.
is_object
());
CHECK
(
not
j
.
is_array
());
CHECK
(
not
j
.
is_string
());
...
...
@@ -66,6 +67,7 @@ TEST_CASE("object inspection")
CHECK
(
not
j
.
is_number_integer
());
CHECK
(
not
j
.
is_number_unsigned
());
CHECK
(
not
j
.
is_number_float
());
CHECK
(
not
j
.
is_binary
());
CHECK
(
not
j
.
is_object
());
CHECK
(
j
.
is_array
());
CHECK
(
not
j
.
is_string
());
...
...
@@ -83,6 +85,7 @@ TEST_CASE("object inspection")
CHECK
(
not
j
.
is_number_integer
());
CHECK
(
not
j
.
is_number_unsigned
());
CHECK
(
not
j
.
is_number_float
());
CHECK
(
not
j
.
is_binary
());
CHECK
(
not
j
.
is_object
());
CHECK
(
not
j
.
is_array
());
CHECK
(
not
j
.
is_string
());
...
...
@@ -100,6 +103,7 @@ TEST_CASE("object inspection")
CHECK
(
not
j
.
is_number_integer
());
CHECK
(
not
j
.
is_number_unsigned
());
CHECK
(
not
j
.
is_number_float
());
CHECK
(
not
j
.
is_binary
());
CHECK
(
not
j
.
is_object
());
CHECK
(
not
j
.
is_array
());
CHECK
(
not
j
.
is_string
());
...
...
@@ -117,6 +121,7 @@ TEST_CASE("object inspection")
CHECK
(
not
j
.
is_number_integer
());
CHECK
(
not
j
.
is_number_unsigned
());
CHECK
(
not
j
.
is_number_float
());
CHECK
(
not
j
.
is_binary
());
CHECK
(
not
j
.
is_object
());
CHECK
(
not
j
.
is_array
());
CHECK
(
j
.
is_string
());
...
...
@@ -134,6 +139,7 @@ TEST_CASE("object inspection")
CHECK
(
j
.
is_number_integer
());
CHECK
(
not
j
.
is_number_unsigned
());
CHECK
(
not
j
.
is_number_float
());
CHECK
(
not
j
.
is_binary
());
CHECK
(
not
j
.
is_object
());
CHECK
(
not
j
.
is_array
());
CHECK
(
not
j
.
is_string
());
...
...
@@ -151,6 +157,7 @@ TEST_CASE("object inspection")
CHECK
(
j
.
is_number_integer
());
CHECK
(
j
.
is_number_unsigned
());
CHECK
(
not
j
.
is_number_float
());
CHECK
(
not
j
.
is_binary
());
CHECK
(
not
j
.
is_object
());
CHECK
(
not
j
.
is_array
());
CHECK
(
not
j
.
is_string
());
...
...
@@ -168,6 +175,25 @@ TEST_CASE("object inspection")
CHECK
(
not
j
.
is_number_integer
());
CHECK
(
not
j
.
is_number_unsigned
());
CHECK
(
j
.
is_number_float
());
CHECK
(
not
j
.
is_binary
());
CHECK
(
not
j
.
is_object
());
CHECK
(
not
j
.
is_array
());
CHECK
(
not
j
.
is_string
());
CHECK
(
not
j
.
is_discarded
());
CHECK
(
j
.
is_primitive
());
CHECK
(
not
j
.
is_structured
());
}
SECTION
(
"binary"
)
{
json
j
(
json
::
value_t
::
binary
);
CHECK
(
not
j
.
is_null
());
CHECK
(
not
j
.
is_boolean
());
CHECK
(
not
j
.
is_number
());
CHECK
(
not
j
.
is_number_integer
());
CHECK
(
not
j
.
is_number_unsigned
());
CHECK
(
not
j
.
is_number_float
());
CHECK
(
j
.
is_binary
());
CHECK
(
not
j
.
is_object
());
CHECK
(
not
j
.
is_array
());
CHECK
(
not
j
.
is_string
());
...
...
@@ -185,6 +211,7 @@ TEST_CASE("object inspection")
CHECK
(
not
j
.
is_number_integer
());
CHECK
(
not
j
.
is_number_unsigned
());
CHECK
(
not
j
.
is_number_float
());
CHECK
(
not
j
.
is_binary
());
CHECK
(
not
j
.
is_object
());
CHECK
(
not
j
.
is_array
());
CHECK
(
not
j
.
is_string
());
...
...
@@ -439,5 +466,12 @@ TEST_CASE("object inspection")
json
::
value_t
t
=
j
;
CHECK
(
t
==
j
.
type
());
}
SECTION
(
"binary"
)
{
json
j
=
json
::
binary_array
({});
json
::
value_t
t
=
j
;
CHECK
(
t
==
j
.
type
());
}
}
}
test/src/unit-modifiers.cpp
View file @
2a34f4cd
...
...
@@ -106,6 +106,31 @@ TEST_CASE("modifiers")
}
}
SECTION
(
"binary"
)
{
SECTION
(
"empty binary"
)
{
json
j
=
json
::
binary_array
({});
json
k
=
j
;
j
.
clear
();
CHECK
(
not
j
.
empty
());
CHECK
(
j
==
json
(
json
::
value_t
::
binary
));
CHECK
(
j
==
json
(
k
.
type
()));
}
SECTION
(
"filled binary"
)
{
json
j
=
json
::
binary_array
({
1
,
2
,
3
,
4
,
5
});
json
k
=
j
;
j
.
clear
();
CHECK
(
not
j
.
empty
());
CHECK
(
j
==
json
(
json
::
value_t
::
binary
));
CHECK
(
j
==
json
(
k
.
type
()));
}
}
SECTION
(
"number (integer)"
)
{
json
j
=
23
;
...
...
@@ -937,5 +962,31 @@ TEST_CASE("modifiers")
CHECK_THROWS_WITH
(
j
.
swap
(
s
),
"[json.exception.type_error.310] cannot use swap() with number"
);
}
}
SECTION
(
"binary_t"
)
{
SECTION
(
"binary_t type"
)
{
json
j
=
json
::
binary_array
({
1
,
2
,
3
,
4
});
json
::
binary_t
s
=
{
1
,
2
,
3
,
4
};
j
.
swap
(
s
);
CHECK
(
j
==
json
::
binary_array
({
1
,
2
,
3
,
4
}));
j
.
swap
(
s
);
CHECK
(
j
==
json
::
binary_array
({
1
,
2
,
3
,
4
}));
}
SECTION
(
"non-string_t type"
)
{
json
j
=
17
;
json
::
binary_t
s
=
{
1
,
2
,
3
,
4
};
CHECK_THROWS_AS
(
j
.
swap
(
s
),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
j
.
swap
(
s
),
"[json.exception.type_error.310] cannot use swap() with number"
);
}
}
}
}
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