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
16af7712
Commit
16af7712
authored
Feb 01, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
added roundtrip test for the Big List of Naughty Strings
parent
bf8fdac9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
2 deletions
+45
-2
README.md
README.md
+1
-1
test/src/unit-testsuites.cpp
test/src/unit-testsuites.cpp
+44
-1
No files found.
README.md
View file @
16af7712
...
...
@@ -839,7 +839,7 @@ $ make json_unit -Ctest
$
./test/json_unit
"*""
===============================================================================
All tests passed (11202
052
assertions in 47 test cases)
All tests passed (11202
549
assertions in 47 test cases)
```
Alternatively, you can use
[
CMake
](
https://cmake.org
)
and run
...
...
test/src/unit-testsuites.cpp
View file @
16af7712
...
...
@@ -816,13 +816,56 @@ TEST_CASE("nst's JSONTestSuite")
}
}
// from http://stackoverflow.com/a/25829178/266378
std
::
string
trim
(
const
std
::
string
&
str
)
{
size_t
first
=
str
.
find_first_not_of
(
' '
);
if
(
std
::
string
::
npos
==
first
)
{
return
str
;
}
size_t
last
=
str
.
find_last_not_of
(
' '
);
return
str
.
substr
(
first
,
(
last
-
first
+
1
));
}
TEST_CASE
(
"Big List of Naughty Strings"
)
{
// test from https://github.com/minimaxir/big-list-of-naughty-strings
SECTION
(
"blns.json"
)
SECTION
(
"
parsing
blns.json"
)
{
std
::
ifstream
f
(
"test/data/big-list-of-naughty-strings/blns.json"
);
json
j
;
CHECK_NOTHROW
(
j
<<
f
);
}
// check if parsed strings roundtrip
// https://www.reddit.com/r/cpp/comments/5qpbie/json_form_modern_c_version_210/dd12mpq/
SECTION
(
"roundtripping"
)
{
std
::
ifstream
f
(
"test/data/big-list-of-naughty-strings/blns.json"
);
while
(
not
f
.
eof
())
{
// read line
std
::
string
line
;
getline
(
f
,
line
);
// trim whitespace
line
=
trim
(
line
);
// remove trailing comma
line
=
line
.
substr
(
0
,
line
.
find_last_of
(
","
));
// discard lines without at least two characters (quotes)
if
(
line
.
size
()
<
2
)
{
continue
;
}
// check roundtrip
CAPTURE
(
line
);
json
j
=
json
::
parse
(
line
);
CHECK
(
j
.
dump
()
==
line
);
}
}
}
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