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
6f3bebff
Unverified
Commit
6f3bebff
authored
Jun 21, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
removed unexpect function
parent
2fd214c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
28 deletions
+28
-28
src/json.hpp
src/json.hpp
+12
-12
test/src/unit-class_parser.cpp
test/src/unit-class_parser.cpp
+7
-7
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+9
-9
No files found.
src/json.hpp
View file @
6f3bebff
...
...
@@ -11132,7 +11132,8 @@ class basic_json
name_separator
,
///< the name separator `:`
value_separator
,
///< the value separator `,`
parse_error
,
///< indicating a parse error
end_of_input
///< indicating the end of the input buffer
end_of_input
,
///< indicating the end of the input buffer
literal_or_value
///< a literal or the begin of a value (only for diagnostics)
};
/// return name of values of type token_type (only used for errors)
...
...
@@ -11170,6 +11171,8 @@ class basic_json
return
"<parse error>"
;
case
token_type
:
:
end_of_input
:
return
"end of input"
;
case
token_type
:
:
literal_or_value
:
return
"'[', '{', or a literal"
;
default:
{
// catch non-enum values
...
...
@@ -12903,10 +12906,16 @@ scan_number_done:
break
;
}
case
lexer
:
:
token_type
::
parse_error
:
{
// using "uninitialized" to avoid "expected" message
expect
(
lexer
::
token_type
::
uninitialized
);
}
default:
{
//
the last token was unexpected
unexpect
(
);
//
we expected a value
expect
(
lexer
::
token_type
::
literal_or_value
);
}
}
...
...
@@ -13060,15 +13069,6 @@ scan_number_done:
}
}
/*!
@throw parse_error.101 if unexpected token occurred
*/
void
unexpect
()
{
errored
=
true
;
throw_exception
();
}
[[
noreturn
]]
void
throw_exception
()
const
{
std
::
string
error_msg
=
"syntax error - "
;
...
...
test/src/unit-class_parser.cpp
View file @
6f3bebff
...
...
@@ -694,15 +694,15 @@ TEST_CASE("parser class")
CHECK_THROWS_AS
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"[1,]"
))).
parse
(),
json
::
parse_error
);
CHECK_THROWS_AS
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"]"
))).
parse
(),
json
::
parse_error
);
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"["
))).
parse
(),
"[json.exception.parse_error.101] parse error at 2: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 2: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"[1"
))).
parse
(),
"[json.exception.parse_error.101] parse error at 3: syntax error - unexpected end of input; expected ']'"
);
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"[1,"
))).
parse
(),
"[json.exception.parse_error.101] parse error at 4: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 4: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"[1,]"
))).
parse
(),
"[json.exception.parse_error.101] parse error at 4: syntax error - unexpected ']'"
);
"[json.exception.parse_error.101] parse error at 4: syntax error - unexpected ']'
; expected '[', '{', or a literal
"
);
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"]"
))).
parse
(),
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected ']'"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected ']'
; expected '[', '{', or a literal
"
);
// missing/unexpected end of object
CHECK_THROWS_AS
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"{"
))).
parse
(),
json
::
parse_error
);
...
...
@@ -716,13 +716,13 @@ TEST_CASE("parser class")
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"{
\"
foo
\"
"
))).
parse
(),
"[json.exception.parse_error.101] parse error at 7: syntax error - unexpected end of input; expected ':'"
);
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"{
\"
foo
\"
:"
))).
parse
(),
"[json.exception.parse_error.101] parse error at 8: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 8: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"{
\"
foo
\"
:}"
))).
parse
(),
"[json.exception.parse_error.101] parse error at 8: syntax error - unexpected '}'"
);
"[json.exception.parse_error.101] parse error at 8: syntax error - unexpected '}'
; expected '[', '{', or a literal
"
);
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"{
\"
foo
\"
:1,}"
))).
parse
(),
"[json.exception.parse_error.101] parse error at 10: syntax error - unexpected '}'; expected string literal"
);
CHECK_THROWS_WITH
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"}"
))).
parse
(),
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected '}'"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected '}'
; expected '[', '{', or a literal
"
);
// missing/unexpected end of string
CHECK_THROWS_AS
(
json
::
parser
(
json
::
input_adapter
::
create
(
std
::
string
(
"
\"
"
))).
parse
(),
json
::
parse_error
);
...
...
test/src/unit-regression.cpp
View file @
6f3bebff
...
...
@@ -597,7 +597,7 @@ TEST_CASE("regression tests")
// a parse error because of the EOF.
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
}
SECTION
(
"issue #367 - behavior of operator>> should more closely resemble that of built-in overloads"
)
...
...
@@ -608,7 +608,7 @@ TEST_CASE("regression tests")
json
j
;
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
}
SECTION
(
"(whitespace)"
)
...
...
@@ -618,7 +618,7 @@ TEST_CASE("regression tests")
json
j
;
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
}
SECTION
(
"one value"
)
...
...
@@ -631,7 +631,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
}
SECTION
(
"one value + whitespace"
)
...
...
@@ -644,7 +644,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
}
SECTION
(
"whitespace + one value"
)
...
...
@@ -657,7 +657,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
}
SECTION
(
"three values"
)
...
...
@@ -674,7 +674,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
}
SECTION
(
"literals without whitespace"
)
...
...
@@ -693,7 +693,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
}
SECTION
(
"example from #529"
)
...
...
@@ -708,7 +708,7 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS
(
ss
>>
j
,
json
::
parse_error
);
CHECK_THROWS_WITH
(
ss
>>
j
,
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input"
);
"[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input
; expected '[', '{', or a literal
"
);
}
SECTION
(
"second example from #529"
)
...
...
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