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
e5dce641
Unverified
Commit
e5dce641
authored
Oct 21, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
💚
added tests #1198
Test every prefix of Unicode sequences against the different dump functions.
parent
c5821d91
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
0 deletions
+122
-0
serializer.hpp
include/nlohmann/detail/output/serializer.hpp
+1
-0
json.hpp
single_include/nlohmann/json.hpp
+1
-0
unit-unicode.cpp
test/src/unit-unicode.cpp
+120
-0
No files found.
include/nlohmann/detail/output/serializer.hpp
View file @
e5dce641
...
...
@@ -442,6 +442,7 @@ class serializer
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'd'
;
bytes_after_last_accept
=
bytes
;
}
// continue processing the string
...
...
single_include/nlohmann/json.hpp
View file @
e5dce641
...
...
@@ -10394,6 +10394,7 @@ class serializer
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'f'
;
string_buffer
[
bytes
++
]
=
'd'
;
bytes_after_last_accept
=
bytes
;
}
// continue processing the string
...
...
test/src/unit-unicode.cpp
View file @
e5dce641
...
...
@@ -39,6 +39,79 @@ using nlohmann::json;
extern
size_t
calls
;
size_t
calls
=
0
;
void
check_utf8dump
(
bool
success_expected
,
int
byte1
,
int
byte2
,
int
byte3
,
int
byte4
);
void
check_utf8dump
(
bool
success_expected
,
int
byte1
,
int
byte2
=
-
1
,
int
byte3
=
-
1
,
int
byte4
=
-
1
)
{
std
::
string
json_string
;
CAPTURE
(
byte1
);
CAPTURE
(
byte2
);
CAPTURE
(
byte3
);
CAPTURE
(
byte4
);
json_string
+=
std
::
string
(
1
,
static_cast
<
char
>
(
byte1
));
if
(
byte2
!=
-
1
)
{
json_string
+=
std
::
string
(
1
,
static_cast
<
char
>
(
byte2
));
}
if
(
byte3
!=
-
1
)
{
json_string
+=
std
::
string
(
1
,
static_cast
<
char
>
(
byte3
));
}
if
(
byte4
!=
-
1
)
{
json_string
+=
std
::
string
(
1
,
static_cast
<
char
>
(
byte4
));
}
CAPTURE
(
json_string
);
// store the string in a JSON value
json
j
=
json_string
;
json
j2
=
"abc"
+
json_string
+
"xyz"
;
// dumping with ignore/replace must not throw in any case
auto
s_ignored
=
j
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
ignore
);
auto
s_ignored2
=
j2
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
ignore
);
auto
s_replaced
=
j
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
replace
);
auto
s_replaced2
=
j2
.
dump
(
-
1
,
' '
,
false
,
json
::
error_handler_t
::
replace
);
if
(
success_expected
)
{
// strict mode must not throw if success is expected
auto
s_strict
=
j
.
dump
();
// all dumps should agree on the string
CHECK
(
s_strict
==
s_ignored
);
CHECK
(
s_strict
==
s_replaced
);
// check that ignore/replace string does not contain a replacement character
CHECK
(
s_ignored
.
find
(
"
\\
ufffd"
)
==
std
::
string
::
npos
);
CHECK
(
s_replaced
.
find
(
"
\\
ufffd"
)
==
std
::
string
::
npos
);
}
else
{
// strict mode must throw if success is not expected
CHECK_THROWS_AS
(
j
.
dump
(),
json
::
type_error
&
);
// ignore and replace must create different dumps
CHECK
(
s_ignored
!=
s_replaced
);
// check that ignore string does not contain a replacement character
CHECK
(
s_ignored
.
find
(
"
\\
ufffd"
)
==
std
::
string
::
npos
);
// check that replace string contains a replacement character
CHECK
(
s_replaced
.
find
(
"
\\
ufffd"
)
!=
std
::
string
::
npos
);
}
// check that prefix and suffix are preserved
CHECK
(
s_ignored2
.
substr
(
1
,
3
)
==
"abc"
);
CHECK
(
s_ignored2
.
substr
(
s_ignored2
.
size
()
-
4
,
3
)
==
"xyz"
);
CHECK
(
s_replaced2
.
substr
(
1
,
3
)
==
"abc"
);
CHECK
(
s_replaced2
.
substr
(
s_replaced2
.
size
()
-
4
,
3
)
==
"xyz"
);
}
void
check_utf8string
(
bool
success_expected
,
int
byte1
,
int
byte2
,
int
byte3
,
int
byte4
);
// create and check a JSON string with up to four UTF-8 bytes
...
...
@@ -115,11 +188,13 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte1
=
0x80
;
byte1
<=
0xC1
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
for
(
int
byte1
=
0xF5
;
byte1
<=
0xFF
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
}
...
...
@@ -152,6 +227,7 @@ TEST_CASE("Unicode", "[hide]")
// all other characters are OK
check_utf8string
(
true
,
byte1
);
check_utf8dump
(
true
,
byte1
);
}
}
}
...
...
@@ -165,6 +241,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte2
=
0x80
;
byte2
<=
0xBF
;
++
byte2
)
{
check_utf8string
(
true
,
byte1
,
byte2
);
check_utf8dump
(
true
,
byte1
,
byte2
);
}
}
}
...
...
@@ -174,6 +251,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte1
=
0xC2
;
byte1
<=
0xDF
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
}
...
...
@@ -190,6 +268,7 @@ TEST_CASE("Unicode", "[hide]")
}
check_utf8string
(
false
,
byte1
,
byte2
);
check_utf8dump
(
false
,
byte1
,
byte2
);
}
}
}
...
...
@@ -206,6 +285,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
true
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
true
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -216,6 +296,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte1
=
0xE0
;
byte1
<=
0xE0
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
}
...
...
@@ -226,6 +307,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte2
=
0xA0
;
byte2
<=
0xBF
;
++
byte2
)
{
check_utf8string
(
false
,
byte1
,
byte2
);
check_utf8dump
(
false
,
byte1
,
byte2
);
}
}
}
...
...
@@ -245,6 +327,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -265,6 +348,7 @@ TEST_CASE("Unicode", "[hide]")
}
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -282,6 +366,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
true
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
true
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -292,6 +377,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte1
=
0xE1
;
byte1
<=
0xEC
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
}
...
...
@@ -302,6 +388,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte2
=
0x80
;
byte2
<=
0xBF
;
++
byte2
)
{
check_utf8string
(
false
,
byte1
,
byte2
);
check_utf8dump
(
false
,
byte1
,
byte2
);
}
}
}
...
...
@@ -321,6 +408,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -341,6 +429,7 @@ TEST_CASE("Unicode", "[hide]")
}
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -358,6 +447,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
true
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
true
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -368,6 +458,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte1
=
0xED
;
byte1
<=
0xED
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
}
...
...
@@ -378,6 +469,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte2
=
0x80
;
byte2
<=
0x9F
;
++
byte2
)
{
check_utf8string
(
false
,
byte1
,
byte2
);
check_utf8dump
(
false
,
byte1
,
byte2
);
}
}
}
...
...
@@ -397,6 +489,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -417,6 +510,7 @@ TEST_CASE("Unicode", "[hide]")
}
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -434,6 +528,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
true
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
true
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -444,6 +539,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte1
=
0xEE
;
byte1
<=
0xEF
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
}
...
...
@@ -454,6 +550,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte2
=
0x80
;
byte2
<=
0xBF
;
++
byte2
)
{
check_utf8string
(
false
,
byte1
,
byte2
);
check_utf8dump
(
false
,
byte1
,
byte2
);
}
}
}
...
...
@@ -473,6 +570,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -493,6 +591,7 @@ TEST_CASE("Unicode", "[hide]")
}
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -512,6 +611,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte4
=
0x80
;
byte4
<=
0xBF
;
++
byte4
)
{
check_utf8string
(
true
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
true
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -523,6 +623,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte1
=
0xF0
;
byte1
<=
0xF0
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
}
...
...
@@ -533,6 +634,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte2
=
0x90
;
byte2
<=
0xBF
;
++
byte2
)
{
check_utf8string
(
false
,
byte1
,
byte2
);
check_utf8dump
(
false
,
byte1
,
byte2
);
}
}
}
...
...
@@ -546,6 +648,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -568,6 +671,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte4
=
0x80
;
byte4
<=
0xBF
;
++
byte4
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -591,6 +695,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte4
=
0x80
;
byte4
<=
0xBF
;
++
byte4
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -614,6 +719,7 @@ TEST_CASE("Unicode", "[hide]")
}
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -634,6 +740,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte4
=
0x80
;
byte4
<=
0xBF
;
++
byte4
)
{
check_utf8string
(
true
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
true
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -645,6 +752,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte1
=
0xF1
;
byte1
<=
0xF3
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
}
...
...
@@ -655,6 +763,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte2
=
0x80
;
byte2
<=
0xBF
;
++
byte2
)
{
check_utf8string
(
false
,
byte1
,
byte2
);
check_utf8dump
(
false
,
byte1
,
byte2
);
}
}
}
...
...
@@ -668,6 +777,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -690,6 +800,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte4
=
0x80
;
byte4
<=
0xBF
;
++
byte4
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -713,6 +824,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte4
=
0x80
;
byte4
<=
0xBF
;
++
byte4
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -736,6 +848,7 @@ TEST_CASE("Unicode", "[hide]")
}
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -756,6 +869,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte4
=
0x80
;
byte4
<=
0xBF
;
++
byte4
)
{
check_utf8string
(
true
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
true
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -767,6 +881,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte1
=
0xF4
;
byte1
<=
0xF4
;
++
byte1
)
{
check_utf8string
(
false
,
byte1
);
check_utf8dump
(
false
,
byte1
);
}
}
...
...
@@ -777,6 +892,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte2
=
0x80
;
byte2
<=
0x8F
;
++
byte2
)
{
check_utf8string
(
false
,
byte1
,
byte2
);
check_utf8dump
(
false
,
byte1
,
byte2
);
}
}
}
...
...
@@ -790,6 +906,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte3
=
0x80
;
byte3
<=
0xBF
;
++
byte3
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
);
}
}
}
...
...
@@ -812,6 +929,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte4
=
0x80
;
byte4
<=
0xBF
;
++
byte4
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -835,6 +953,7 @@ TEST_CASE("Unicode", "[hide]")
for
(
int
byte4
=
0x80
;
byte4
<=
0xBF
;
++
byte4
)
{
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
@@ -858,6 +977,7 @@ TEST_CASE("Unicode", "[hide]")
}
check_utf8string
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
check_utf8dump
(
false
,
byte1
,
byte2
,
byte3
,
byte4
);
}
}
}
...
...
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