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
334b7f24
Commit
334b7f24
authored
Feb 13, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more systematic test cases
parent
40a0773e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
20 deletions
+39
-20
test/unit.cpp
test/unit.cpp
+39
-20
No files found.
test/unit.cpp
View file @
334b7f24
...
...
@@ -5218,27 +5218,46 @@ TEST_CASE("parser class")
// unexpected end of string
CHECK_THROWS_AS
(
json
::
parser
(
"
\"
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
\
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
\
u
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
\
u0
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
\
u01
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
\
u012
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
"\\\"
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
"\\
u
\"
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
"\\
u0
\"
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
"\\
u01
\"
"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\
"\\
u012
\"
"
).
parse
(),
std
::
invalid_argument
);
// invalid escapes
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
!"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
#"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
["
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
]"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
."
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
0"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
a"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
c"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
e"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
g"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
m"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
o"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
q"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
s"
).
parse
(),
std
::
invalid_argument
);
CHECK_THROWS_AS
(
json
::
parser
(
"
\\
v"
).
parse
(),
std
::
invalid_argument
);
for
(
int
c
=
1
;
c
<
128
;
++
c
)
{
auto
s
=
std
::
string
(
"
\"\\
"
)
+
std
::
string
(
1
,
c
)
+
"
\"
"
;
switch
(
c
)
{
// valid escapes
case
(
'"'
):
case
(
'\\'
):
case
(
'/'
):
case
(
'b'
):
case
(
'f'
):
case
(
'n'
):
case
(
'r'
):
case
(
't'
):
{
CHECK_NOTHROW
(
json
::
parser
(
s
).
parse
());
break
;
}
// \u must be followed with four numbers, so we skip it here
case
(
'u'
):
{
break
;
}
// any other combination of backslash and character is invalid
default:
{
CHECK_THROWS_AS
(
json
::
parser
(
s
).
parse
(),
std
::
invalid_argument
);
break
;
}
}
}
}
}
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