🚨 fix warnings

parent 346e9813
...@@ -819,21 +819,18 @@ class lexer ...@@ -819,21 +819,18 @@ class lexer
} }
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
JSON_HEDLEY_CONST
static void strtof(float& f, const char* str, char** endptr) noexcept static void strtof(float& f, const char* str, char** endptr) noexcept
{ {
f = std::strtof(str, endptr); f = std::strtof(str, endptr);
} }
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
JSON_HEDLEY_CONST
static void strtof(double& f, const char* str, char** endptr) noexcept static void strtof(double& f, const char* str, char** endptr) noexcept
{ {
f = std::strtod(str, endptr); f = std::strtod(str, endptr);
} }
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
JSON_HEDLEY_CONST
static void strtof(long double& f, const char* str, char** endptr) noexcept static void strtof(long double& f, const char* str, char** endptr) noexcept
{ {
f = std::strtold(str, endptr); f = std::strtold(str, endptr);
......
...@@ -1205,7 +1205,7 @@ class binary_writer ...@@ -1205,7 +1205,7 @@ class binary_writer
case value_t::number_unsigned: case value_t::number_unsigned:
{ {
if (j.m_value.number_unsigned <= (std::numeric_limits<std::int8_t>::max)()) if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
{ {
return 'i'; return 'i';
} }
...@@ -1213,11 +1213,11 @@ class binary_writer ...@@ -1213,11 +1213,11 @@ class binary_writer
{ {
return 'U'; return 'U';
} }
if (j.m_value.number_unsigned <= (std::numeric_limits<std::int16_t>::max)()) if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
{ {
return 'I'; return 'I';
} }
if (j.m_value.number_unsigned <= (std::numeric_limits<std::int32_t>::max)()) if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
{ {
return 'l'; return 'l';
} }
......
...@@ -7842,21 +7842,18 @@ class lexer ...@@ -7842,21 +7842,18 @@ class lexer
} }
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
JSON_HEDLEY_CONST
static void strtof(float& f, const char* str, char** endptr) noexcept static void strtof(float& f, const char* str, char** endptr) noexcept
{ {
f = std::strtof(str, endptr); f = std::strtof(str, endptr);
} }
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
JSON_HEDLEY_CONST
static void strtof(double& f, const char* str, char** endptr) noexcept static void strtof(double& f, const char* str, char** endptr) noexcept
{ {
f = std::strtod(str, endptr); f = std::strtod(str, endptr);
} }
JSON_HEDLEY_NON_NULL(2) JSON_HEDLEY_NON_NULL(2)
JSON_HEDLEY_CONST
static void strtof(long double& f, const char* str, char** endptr) noexcept static void strtof(long double& f, const char* str, char** endptr) noexcept
{ {
f = std::strtold(str, endptr); f = std::strtold(str, endptr);
...@@ -12316,7 +12313,7 @@ class binary_writer ...@@ -12316,7 +12313,7 @@ class binary_writer
case value_t::number_unsigned: case value_t::number_unsigned:
{ {
if (j.m_value.number_unsigned <= (std::numeric_limits<std::int8_t>::max)()) if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
{ {
return 'i'; return 'i';
} }
...@@ -12324,11 +12321,11 @@ class binary_writer ...@@ -12324,11 +12321,11 @@ class binary_writer
{ {
return 'U'; return 'U';
} }
if (j.m_value.number_unsigned <= (std::numeric_limits<std::int16_t>::max)()) if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
{ {
return 'I'; return 'I';
} }
if (j.m_value.number_unsigned <= (std::numeric_limits<std::int32_t>::max)()) if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
{ {
return 'l'; return 'l';
} }
......
...@@ -112,8 +112,9 @@ TEST_CASE("BSON") ...@@ -112,8 +112,9 @@ TEST_CASE("BSON")
0x00, 0x00,
0x00, 0x00, 0x00, 0x80 0x00, 0x00, 0x00, 0x80
}; };
CHECK_THROWS_AS(json::from_bson(v), json::parse_error&); json _;
CHECK_THROWS_WITH(json::from_bson(v), "[json.exception.parse_error.112] parse error at byte 10: syntax error while parsing BSON string: string length must be at least 1, is -2147483648"); CHECK_THROWS_AS(_ = json::from_bson(v), json::parse_error&);
CHECK_THROWS_WITH(_ = json::from_bson(v), "[json.exception.parse_error.112] parse error at byte 10: syntax error while parsing BSON string: string length must be at least 1, is -2147483648");
} }
SECTION("objects") SECTION("objects")
...@@ -692,8 +693,9 @@ TEST_CASE("Incomplete BSON Input") ...@@ -692,8 +693,9 @@ TEST_CASE("Incomplete BSON Input")
'e', 'n', 't' // unexpected EOF 'e', 'n', 't' // unexpected EOF
}; };
CHECK_THROWS_AS(json::from_bson(incomplete_bson), json::parse_error&); json _;
CHECK_THROWS_WITH(json::from_bson(incomplete_bson), CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
"[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing BSON cstring: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing BSON cstring: unexpected end of input");
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded()); CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
...@@ -710,8 +712,9 @@ TEST_CASE("Incomplete BSON Input") ...@@ -710,8 +712,9 @@ TEST_CASE("Incomplete BSON Input")
0x08, // entry: boolean, unexpected EOF 0x08, // entry: boolean, unexpected EOF
}; };
CHECK_THROWS_AS(json::from_bson(incomplete_bson), json::parse_error&); json _;
CHECK_THROWS_WITH(json::from_bson(incomplete_bson), CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing BSON cstring: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing BSON cstring: unexpected end of input");
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded()); CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
...@@ -733,8 +736,9 @@ TEST_CASE("Incomplete BSON Input") ...@@ -733,8 +736,9 @@ TEST_CASE("Incomplete BSON Input")
// missing input data... // missing input data...
}; };
CHECK_THROWS_AS(json::from_bson(incomplete_bson), json::parse_error&); json _;
CHECK_THROWS_WITH(json::from_bson(incomplete_bson), CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
"[json.exception.parse_error.110] parse error at byte 28: syntax error while parsing BSON element list: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 28: syntax error while parsing BSON element list: unexpected end of input");
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded()); CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
...@@ -749,8 +753,9 @@ TEST_CASE("Incomplete BSON Input") ...@@ -749,8 +753,9 @@ TEST_CASE("Incomplete BSON Input")
0x0D, 0x00, // size (incomplete), unexpected EOF 0x0D, 0x00, // size (incomplete), unexpected EOF
}; };
CHECK_THROWS_AS(json::from_bson(incomplete_bson), json::parse_error&); json _;
CHECK_THROWS_WITH(json::from_bson(incomplete_bson), CHECK_THROWS_AS(_ = json::from_bson(incomplete_bson), json::parse_error&);
CHECK_THROWS_WITH(_ = json::from_bson(incomplete_bson),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BSON number: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BSON number: unexpected end of input");
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded()); CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());
...@@ -791,8 +796,9 @@ TEST_CASE("Unsupported BSON input") ...@@ -791,8 +796,9 @@ TEST_CASE("Unsupported BSON input")
0x00 // end marker 0x00 // end marker
}; };
CHECK_THROWS_AS(json::from_bson(bson), json::parse_error&); json _;
CHECK_THROWS_WITH(json::from_bson(bson), CHECK_THROWS_AS(_ = json::from_bson(bson), json::parse_error&);
CHECK_THROWS_WITH(_ = json::from_bson(bson),
"[json.exception.parse_error.114] parse error at byte 5: Unsupported BSON record type 0xFF"); "[json.exception.parse_error.114] parse error at byte 5: Unsupported BSON record type 0xFF");
CHECK(json::from_bson(bson, true, false).is_discarded()); CHECK(json::from_bson(bson, true, false).is_discarded());
......
...@@ -406,8 +406,9 @@ TEST_CASE("parser class") ...@@ -406,8 +406,9 @@ TEST_CASE("parser class")
// uses an iterator range. // uses an iterator range.
std::string s = "\"1\""; std::string s = "\"1\"";
s[1] = '\0'; s[1] = '\0';
CHECK_THROWS_AS(json::parse(s.begin(), s.end()), json::parse_error&); json _;
CHECK_THROWS_WITH(json::parse(s.begin(), s.end()), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0000 (NUL) must be escaped to \\u0000; last read: '\"<U+0000>'"); CHECK_THROWS_AS(_ = json::parse(s.begin(), s.end()), json::parse_error&);
CHECK_THROWS_WITH(_ = json::parse(s.begin(), s.end()), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0000 (NUL) must be escaped to \\u0000; last read: '\"<U+0000>'");
} }
} }
...@@ -1219,19 +1220,21 @@ TEST_CASE("parser class") ...@@ -1219,19 +1220,21 @@ TEST_CASE("parser class")
} }
} }
json _;
// missing part of a surrogate pair // missing part of a surrogate pair
CHECK_THROWS_AS(json::parse("\"\\uD80C\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD80C\""), json::parse_error&);
CHECK_THROWS_WITH(json::parse("\"\\uD80C\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD80C\""),
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\"'"); "[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\"'");
// invalid surrogate pair // invalid surrogate pair
CHECK_THROWS_AS(json::parse("\"\\uD80C\\uD80C\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD80C\\uD80C\""), json::parse_error&);
CHECK_THROWS_AS(json::parse("\"\\uD80C\\u0000\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD80C\\u0000\""), json::parse_error&);
CHECK_THROWS_AS(json::parse("\"\\uD80C\\uFFFF\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD80C\\uFFFF\""), json::parse_error&);
CHECK_THROWS_WITH(json::parse("\"\\uD80C\\uD80C\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD80C\\uD80C\""),
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uD80C'"); "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uD80C'");
CHECK_THROWS_WITH(json::parse("\"\\uD80C\\u0000\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD80C\\u0000\""),
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\u0000'"); "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\u0000'");
CHECK_THROWS_WITH(json::parse("\"\\uD80C\\uFFFF\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD80C\\uFFFF\""),
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uFFFF'"); "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uFFFF'");
} }
...@@ -1679,12 +1682,13 @@ TEST_CASE("parser class") ...@@ -1679,12 +1682,13 @@ TEST_CASE("parser class")
CHECK(json::parse("{\"foo\": true:", cb, false).is_discarded()); CHECK(json::parse("{\"foo\": true:", cb, false).is_discarded());
CHECK_THROWS_AS(json::parse("{\"foo\": true:", cb), json::parse_error&); json _;
CHECK_THROWS_WITH(json::parse("{\"foo\": true:", cb), CHECK_THROWS_AS(_ = json::parse("{\"foo\": true:", cb), json::parse_error&);
CHECK_THROWS_WITH(_ = json::parse("{\"foo\": true:", cb),
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing object - unexpected ':'; expected '}'"); "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing object - unexpected ':'; expected '}'");
CHECK_THROWS_AS(json::parse("1.18973e+4932", cb), json::out_of_range&); CHECK_THROWS_AS(_ = json::parse("1.18973e+4932", cb), json::out_of_range&);
CHECK_THROWS_WITH(json::parse("1.18973e+4932", cb), CHECK_THROWS_WITH(_ = json::parse("1.18973e+4932", cb),
"[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'"); "[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'");
} }
......
...@@ -1052,9 +1052,10 @@ TEST_CASE("constructors") ...@@ -1052,9 +1052,10 @@ TEST_CASE("constructors")
SECTION("object with error") SECTION("object with error")
{ {
CHECK_THROWS_AS(json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }), json _;
CHECK_THROWS_AS(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
json::type_error&); json::type_error&);
CHECK_THROWS_WITH(json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }), CHECK_THROWS_WITH(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
"[json.exception.type_error.301] cannot create object from initializer list"); "[json.exception.type_error.301] cannot create object from initializer list");
} }
......
...@@ -269,8 +269,10 @@ TEST_CASE("deserialization") ...@@ -269,8 +269,10 @@ TEST_CASE("deserialization")
ss3 << "[\"foo\",1,2,3,false,{\"one\":1}"; ss3 << "[\"foo\",1,2,3,false,{\"one\":1}";
ss4 << "[\"foo\",1,2,3,false,{\"one\":1}"; ss4 << "[\"foo\",1,2,3,false,{\"one\":1}";
ss5 << "[\"foo\",1,2,3,false,{\"one\":1}"; ss5 << "[\"foo\",1,2,3,false,{\"one\":1}";
CHECK_THROWS_AS(json::parse(ss1), json::parse_error&);
CHECK_THROWS_WITH(json::parse(ss2), json _;
CHECK_THROWS_AS(_ = json::parse(ss1), json::parse_error&);
CHECK_THROWS_WITH(_ = json::parse(ss2),
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'"); "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'");
CHECK(not json::accept(ss3)); CHECK(not json::accept(ss3));
...@@ -293,8 +295,9 @@ TEST_CASE("deserialization") ...@@ -293,8 +295,9 @@ TEST_CASE("deserialization")
SECTION("string") SECTION("string")
{ {
json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}"; json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}";
CHECK_THROWS_AS(json::parse(s), json::parse_error&); json _;
CHECK_THROWS_WITH(json::parse(s), CHECK_THROWS_AS(_ = json::parse(s), json::parse_error&);
CHECK_THROWS_WITH(_ = json::parse(s),
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'"); "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'");
CHECK(not json::accept(s)); CHECK(not json::accept(s));
...@@ -430,7 +433,8 @@ TEST_CASE("deserialization") ...@@ -430,7 +433,8 @@ TEST_CASE("deserialization")
SECTION("empty container") SECTION("empty container")
{ {
std::vector<uint8_t> v; std::vector<uint8_t> v;
CHECK_THROWS_AS(json::parse(v), json::parse_error&); json _;
CHECK_THROWS_AS(_ = json::parse(v), json::parse_error&);
CHECK(not json::accept(v)); CHECK(not json::accept(v));
SaxEventLogger l; SaxEventLogger l;
...@@ -614,8 +618,9 @@ TEST_CASE("deserialization") ...@@ -614,8 +618,9 @@ TEST_CASE("deserialization")
SECTION("case 6") SECTION("case 6")
{ {
uint8_t v[] = {'\"', 0x7F, 0xDF, 0x7F}; uint8_t v[] = {'\"', 0x7F, 0xDF, 0x7F};
CHECK_THROWS_AS(json::parse(std::begin(v), std::end(v)), json::parse_error&); json _;
CHECK_THROWS_WITH(json::parse(std::begin(v), std::end(v)), CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK_THROWS_WITH(_ = json::parse(std::begin(v), std::end(v)),
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '\"\x7f\xdf\x7f'"); "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '\"\x7f\xdf\x7f'");
CHECK(not json::accept(std::begin(v), std::end(v))); CHECK(not json::accept(std::begin(v), std::end(v)));
...@@ -801,12 +806,13 @@ TEST_CASE("deserialization") ...@@ -801,12 +806,13 @@ TEST_CASE("deserialization")
SECTION("BOM only") SECTION("BOM only")
{ {
CHECK_THROWS_AS(json::parse(bom), json::parse_error&); json _;
CHECK_THROWS_WITH(json::parse(bom), CHECK_THROWS_AS(_ = json::parse(bom), json::parse_error&);
CHECK_THROWS_WITH(_ = json::parse(bom),
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
CHECK_THROWS_AS(json::parse(std::istringstream(bom)), json::parse_error&); CHECK_THROWS_AS(_ = json::parse(std::istringstream(bom)), json::parse_error&);
CHECK_THROWS_WITH(json::parse(std::istringstream(bom)), CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom)),
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
SaxEventLogger l; SaxEventLogger l;
...@@ -840,12 +846,13 @@ TEST_CASE("deserialization") ...@@ -840,12 +846,13 @@ TEST_CASE("deserialization")
SECTION("2 byte of BOM") SECTION("2 byte of BOM")
{ {
CHECK_THROWS_AS(json::parse(bom.substr(0, 2)), json::parse_error&); json _;
CHECK_THROWS_WITH(json::parse(bom.substr(0, 2)), CHECK_THROWS_AS(_ = json::parse(bom.substr(0, 2)), json::parse_error&);
CHECK_THROWS_WITH(_ = json::parse(bom.substr(0, 2)),
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF\xBB'"); "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF\xBB'");
CHECK_THROWS_AS(json::parse(std::istringstream(bom.substr(0, 2))), json::parse_error&); CHECK_THROWS_AS(_ = json::parse(std::istringstream(bom.substr(0, 2))), json::parse_error&);
CHECK_THROWS_WITH(json::parse(std::istringstream(bom.substr(0, 2))), CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom.substr(0, 2))),
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF\xBB'"); "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF\xBB'");
SaxEventLogger l1, l2; SaxEventLogger l1, l2;
...@@ -865,12 +872,13 @@ TEST_CASE("deserialization") ...@@ -865,12 +872,13 @@ TEST_CASE("deserialization")
SECTION("1 byte of BOM") SECTION("1 byte of BOM")
{ {
CHECK_THROWS_AS(json::parse(bom.substr(0, 1)), json::parse_error&); json _;
CHECK_THROWS_WITH(json::parse(bom.substr(0, 1)), CHECK_THROWS_AS(_ = json::parse(bom.substr(0, 1)), json::parse_error&);
CHECK_THROWS_WITH(_ = json::parse(bom.substr(0, 1)),
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF'"); "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF'");
CHECK_THROWS_AS(json::parse(std::istringstream(bom.substr(0, 1))), json::parse_error&); CHECK_THROWS_AS(_ = json::parse(std::istringstream(bom.substr(0, 1))), json::parse_error&);
CHECK_THROWS_WITH(json::parse(std::istringstream(bom.substr(0, 1))), CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom.substr(0, 1))),
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF'"); "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF'");
SaxEventLogger l1, l2; SaxEventLogger l1, l2;
...@@ -925,8 +933,9 @@ TEST_CASE("deserialization") ...@@ -925,8 +933,9 @@ TEST_CASE("deserialization")
else else
{ {
// any variation is an error // any variation is an error
CHECK_THROWS_AS(json::parse(s + "null"), json::parse_error&); json _;
CHECK_THROWS_AS(json::parse(std::istringstream(s + "null")), json::parse_error&); CHECK_THROWS_AS(_ = json::parse(s + "null"), json::parse_error&);
CHECK_THROWS_AS(_ = json::parse(std::istringstream(s + "null")), json::parse_error&);
SaxEventLogger l; SaxEventLogger l;
CHECK(not json::sax_parse(s + "null", &l)); CHECK(not json::sax_parse(s + "null", &l));
......
...@@ -79,7 +79,8 @@ TEST_CASE("compliance tests from json.org") ...@@ -79,7 +79,8 @@ TEST_CASE("compliance tests from json.org")
{ {
CAPTURE(filename) CAPTURE(filename)
std::ifstream f(filename); std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::parse_error&); json _;
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
} }
} }
...@@ -387,36 +388,36 @@ TEST_CASE("json.org examples") ...@@ -387,36 +388,36 @@ TEST_CASE("json.org examples")
SECTION("FILE 1.json") SECTION("FILE 1.json")
{ {
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/1.json", "r"), &std::fclose); std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/1.json", "r"), &std::fclose);
json j; json _;
CHECK_NOTHROW(j.parse(f.get())); CHECK_NOTHROW(_ = json::parse(f.get()));
} }
SECTION("FILE 2.json") SECTION("FILE 2.json")
{ {
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/2.json", "r"), &std::fclose); std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/2.json", "r"), &std::fclose);
json j; json _;
CHECK_NOTHROW(j.parse(f.get())); CHECK_NOTHROW(_ = json::parse(f.get()));
} }
SECTION("FILE 3.json") SECTION("FILE 3.json")
{ {
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/3.json", "r"), &std::fclose); std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/3.json", "r"), &std::fclose);
json j; json _;
CHECK_NOTHROW(j.parse(f.get())); CHECK_NOTHROW(_ = json::parse(f.get()));
} }
SECTION("FILE 4.json") SECTION("FILE 4.json")
{ {
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/4.json", "r"), &std::fclose); std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/4.json", "r"), &std::fclose);
json j; json _;
CHECK_NOTHROW(j.parse(f.get())); CHECK_NOTHROW(_ = json::parse(f.get()));
} }
SECTION("FILE 5.json") SECTION("FILE 5.json")
{ {
std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/5.json", "r"), &std::fclose); std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen("test/data/json.org/5.json", "r"), &std::fclose);
json j; json _;
CHECK_NOTHROW(j.parse(f.get())); CHECK_NOTHROW(_ = json::parse(f.get()));
} }
} }
...@@ -810,7 +811,8 @@ TEST_CASE("nst's JSONTestSuite") ...@@ -810,7 +811,8 @@ TEST_CASE("nst's JSONTestSuite")
{ {
CAPTURE(filename) CAPTURE(filename)
std::ifstream f(filename); std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::parse_error&); json _;
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
} }
} }
...@@ -1027,7 +1029,8 @@ TEST_CASE("nst's JSONTestSuite (2)") ...@@ -1027,7 +1029,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
{ {
CAPTURE(filename) CAPTURE(filename)
std::ifstream f(filename); std::ifstream f(filename);
CHECK_NOTHROW(json::parse(f)); json _;
CHECK_NOTHROW(_ = json::parse(f));
std::ifstream f2(filename); std::ifstream f2(filename);
CHECK(json::accept(f2)); CHECK(json::accept(f2));
} }
...@@ -1228,7 +1231,8 @@ TEST_CASE("nst's JSONTestSuite (2)") ...@@ -1228,7 +1231,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
{ {
CAPTURE(filename) CAPTURE(filename)
std::ifstream f(filename); std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::parse_error&); json _;
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
std::ifstream f2(filename); std::ifstream f2(filename);
CHECK(not json::accept(f2)); CHECK(not json::accept(f2));
} }
...@@ -1293,7 +1297,8 @@ TEST_CASE("nst's JSONTestSuite (2)") ...@@ -1293,7 +1297,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
{ {
CAPTURE(filename) CAPTURE(filename)
std::ifstream f(filename); std::ifstream f(filename);
CHECK_NOTHROW(json::parse(f)); json _;
CHECK_NOTHROW(_ = json::parse(f));
std::ifstream f2(filename); std::ifstream f2(filename);
CHECK(json::accept(f2)); CHECK(json::accept(f2));
} }
...@@ -1343,7 +1348,8 @@ TEST_CASE("nst's JSONTestSuite (2)") ...@@ -1343,7 +1348,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
{ {
CAPTURE(filename) CAPTURE(filename)
std::ifstream f(filename); std::ifstream f(filename);
CHECK_THROWS_AS(json::parse(f), json::exception&); // could be parse_error or out_of_range json _;
CHECK_THROWS_AS(_ = json::parse(f), json::exception&); // could be parse_error or out_of_range
std::ifstream f2(filename); std::ifstream f2(filename);
CHECK(not json::accept(f2)); CHECK(not json::accept(f2));
} }
......
...@@ -158,13 +158,14 @@ void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte ...@@ -158,13 +158,14 @@ void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte
CAPTURE(json_string) CAPTURE(json_string)
json _;
if (success_expected) if (success_expected)
{ {
CHECK_NOTHROW(json::parse(json_string)); CHECK_NOTHROW(_ = json::parse(json_string));
} }
else else
{ {
CHECK_THROWS_AS(json::parse(json_string), json::parse_error&); CHECK_THROWS_AS(_ = json::parse(json_string), json::parse_error&);
} }
} }
} }
...@@ -1051,7 +1052,8 @@ TEST_CASE("Unicode" * doctest::skip()) ...@@ -1051,7 +1052,8 @@ TEST_CASE("Unicode" * doctest::skip())
json_text += "\""; json_text += "\"";
CAPTURE(json_text) CAPTURE(json_text)
CHECK_NOTHROW(json::parse(json_text)); json _;
CHECK_NOTHROW(_ = json::parse(json_text));
} }
} }
...@@ -1059,32 +1061,34 @@ TEST_CASE("Unicode" * doctest::skip()) ...@@ -1059,32 +1061,34 @@ TEST_CASE("Unicode" * doctest::skip())
{ {
SECTION("incorrect surrogate values") SECTION("incorrect surrogate values")
{ {
CHECK_THROWS_AS(json::parse("\"\\uDC00\\uDC00\""), json::parse_error&); json _;
CHECK_THROWS_WITH(json::parse("\"\\uDC00\\uDC00\""),
CHECK_THROWS_AS(_ = json::parse("\"\\uDC00\\uDC00\""), json::parse_error&);
CHECK_THROWS_WITH(_ = json::parse("\"\\uDC00\\uDC00\""),
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uDC00'"); "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uDC00'");
CHECK_THROWS_AS(json::parse("\"\\uD7FF\\uDC00\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD7FF\\uDC00\""), json::parse_error&);
CHECK_THROWS_WITH(json::parse("\"\\uD7FF\\uDC00\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD7FF\\uDC00\""),
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uD7FF\\uDC00'"); "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uD7FF\\uDC00'");
CHECK_THROWS_AS(json::parse("\"\\uD800]\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD800]\""), json::parse_error&);
CHECK_THROWS_WITH(json::parse("\"\\uD800]\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD800]\""),
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800]'"); "[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800]'");
CHECK_THROWS_AS(json::parse("\"\\uD800\\v\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD800\\v\""), json::parse_error&);
CHECK_THROWS_WITH(json::parse("\"\\uD800\\v\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD800\\v\""),
"[json.exception.parse_error.101] parse error at line 1, column 9: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\v'"); "[json.exception.parse_error.101] parse error at line 1, column 9: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\v'");
CHECK_THROWS_AS(json::parse("\"\\uD800\\u123\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD800\\u123\""), json::parse_error&);
CHECK_THROWS_WITH(json::parse("\"\\uD800\\u123\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD800\\u123\""),
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\uD800\\u123\"'"); "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\uD800\\u123\"'");
CHECK_THROWS_AS(json::parse("\"\\uD800\\uDBFF\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD800\\uDBFF\""), json::parse_error&);
CHECK_THROWS_WITH(json::parse("\"\\uD800\\uDBFF\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD800\\uDBFF\""),
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uDBFF'"); "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uDBFF'");
CHECK_THROWS_AS(json::parse("\"\\uD800\\uE000\""), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\"\\uD800\\uE000\""), json::parse_error&);
CHECK_THROWS_WITH(json::parse("\"\\uD800\\uE000\""), CHECK_THROWS_WITH(_ = json::parse("\"\\uD800\\uE000\""),
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uE000'"); "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uE000'");
} }
} }
...@@ -1203,8 +1207,9 @@ TEST_CASE("Unicode" * doctest::skip()) ...@@ -1203,8 +1207,9 @@ TEST_CASE("Unicode" * doctest::skip())
SECTION("error for incomplete/wrong BOM") SECTION("error for incomplete/wrong BOM")
{ {
CHECK_THROWS_AS(json::parse("\xef\xbb"), json::parse_error&); json _;
CHECK_THROWS_AS(json::parse("\xef\xbb\xbb"), json::parse_error&); CHECK_THROWS_AS(_ = json::parse("\xef\xbb"), json::parse_error&);
CHECK_THROWS_AS(_ = json::parse("\xef\xbb\xbb"), json::parse_error&);
} }
} }
...@@ -1215,6 +1220,7 @@ void roundtrip(bool success_expected, const std::string& s); ...@@ -1215,6 +1220,7 @@ void roundtrip(bool success_expected, const std::string& s);
void roundtrip(bool success_expected, const std::string& s) void roundtrip(bool success_expected, const std::string& s)
{ {
CAPTURE(s) CAPTURE(s)
json _;
// create JSON string value // create JSON string value
json j = s; json j = s;
...@@ -1230,11 +1236,11 @@ void roundtrip(bool success_expected, const std::string& s) ...@@ -1230,11 +1236,11 @@ void roundtrip(bool success_expected, const std::string& s)
if (s[0] != '\0') if (s[0] != '\0')
{ {
// parsing JSON text succeeds // parsing JSON text succeeds
CHECK_NOTHROW(json::parse(ps)); CHECK_NOTHROW(_ = json::parse(ps));
} }
// roundtrip succeeds // roundtrip succeeds
CHECK_NOTHROW(json::parse(j.dump())); CHECK_NOTHROW(_ = json::parse(j.dump()));
// after roundtrip, the same string is stored // after roundtrip, the same string is stored
json jr = json::parse(j.dump()); json jr = json::parse(j.dump());
...@@ -1246,7 +1252,7 @@ void roundtrip(bool success_expected, const std::string& s) ...@@ -1246,7 +1252,7 @@ void roundtrip(bool success_expected, const std::string& s)
CHECK_THROWS_AS(j.dump(), json::type_error&); CHECK_THROWS_AS(j.dump(), json::type_error&);
// parsing JSON text fails // parsing JSON text fails
CHECK_THROWS_AS(json::parse(ps), json::parse_error&); CHECK_THROWS_AS(_ = json::parse(ps), json::parse_error&);
} }
} }
} }
......
...@@ -70,7 +70,8 @@ TEST_CASE("wide strings") ...@@ -70,7 +70,8 @@ TEST_CASE("wide strings")
if (wstring_is_utf16()) if (wstring_is_utf16())
{ {
std::wstring w = L"\"\xDBFF"; std::wstring w = L"\"\xDBFF";
CHECK_THROWS_AS(json::parse(w), json::parse_error&); json _;
CHECK_THROWS_AS(_ = json::parse(w), json::parse_error&);
} }
} }
...@@ -89,7 +90,8 @@ TEST_CASE("wide strings") ...@@ -89,7 +90,8 @@ TEST_CASE("wide strings")
if (wstring_is_utf16()) if (wstring_is_utf16())
{ {
std::u16string w = u"\"\xDBFF"; std::u16string w = u"\"\xDBFF";
CHECK_THROWS_AS(json::parse(w), json::parse_error&); json _;
CHECK_THROWS_AS(_ = json::parse(w), json::parse_error&);
} }
} }
...@@ -108,7 +110,8 @@ TEST_CASE("wide strings") ...@@ -108,7 +110,8 @@ TEST_CASE("wide strings")
if (u32string_is_utf32()) if (u32string_is_utf32())
{ {
std::u32string w = U"\"\x110000"; std::u32string w = U"\"\x110000";
CHECK_THROWS_AS(json::parse(w), json::parse_error&); json _;
CHECK_THROWS_AS(_ = json::parse(w), json::parse_error&);
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment