Refactor assertions in unit-deserialization.cpp
This commit is contained in:
parent
8140466217
commit
e7470de775
@ -281,20 +281,16 @@ TEST_CASE("deserialization")
|
||||
SECTION("stream")
|
||||
{
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
std::stringstream ss3;
|
||||
std::stringstream ss4;
|
||||
std::stringstream ss5;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss3 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss4 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss5 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
|
||||
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 ']'");
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(ss1), "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&);
|
||||
CHECK(!json::accept(ss3));
|
||||
|
||||
json j_error;
|
||||
@ -317,9 +313,7 @@ TEST_CASE("deserialization")
|
||||
{
|
||||
json::string_t s = R"(["foo",1,2,3,false,{"one":1})";
|
||||
json _;
|
||||
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 ']'");
|
||||
CHECK_THROWS_WITH_AS(_ = 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::parse_error&);
|
||||
CHECK(!json::accept(s));
|
||||
|
||||
json j_error;
|
||||
@ -340,33 +334,23 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("operator<<")
|
||||
{
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
std::stringstream ss;
|
||||
ss << R"(["foo",1,2,3,false,{"one":1})";
|
||||
json j;
|
||||
CHECK_THROWS_AS(j << ss1, json::parse_error&);
|
||||
CHECK_THROWS_WITH(j << ss2,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'");
|
||||
CHECK_THROWS_WITH_AS(j << ss, "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("operator>>")
|
||||
{
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
std::stringstream ss;
|
||||
ss << R"(["foo",1,2,3,false,{"one":1})";
|
||||
json j;
|
||||
CHECK_THROWS_AS(ss1 >> j, json::parse_error&);
|
||||
CHECK_THROWS_WITH(ss2 >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'");
|
||||
CHECK_THROWS_WITH_AS(ss >> j, "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("user-defined string literal")
|
||||
{
|
||||
CHECK_THROWS_AS("[\"foo\",1,2,3,false,{\"one\":1}"_json, json::parse_error&);
|
||||
CHECK_THROWS_WITH("[\"foo\",1,2,3,false,{\"one\":1}"_json,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'");
|
||||
CHECK_THROWS_WITH_AS("[\"foo\",1,2,3,false,{\"one\":1}"_json, "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@ -648,9 +632,7 @@ TEST_CASE("deserialization")
|
||||
{
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xDF, 0x7F}};
|
||||
json _;
|
||||
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'");
|
||||
CHECK_THROWS_WITH_AS(_ = 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::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
|
||||
json j_error;
|
||||
@ -846,13 +828,9 @@ TEST_CASE("deserialization")
|
||||
SECTION("BOM only")
|
||||
{
|
||||
json _;
|
||||
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");
|
||||
CHECK_THROWS_WITH_AS(_ = 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::parse_error&);
|
||||
|
||||
CHECK_THROWS_AS(_ = json::parse(std::istringstream(bom)), json::parse_error&);
|
||||
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");
|
||||
CHECK_THROWS_WITH_AS(_ = 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::parse_error&);
|
||||
|
||||
SaxEventLogger l;
|
||||
CHECK(!json::sax_parse(bom, &l));
|
||||
@ -887,13 +865,9 @@ TEST_CASE("deserialization")
|
||||
SECTION("2 byte of BOM")
|
||||
{
|
||||
json _;
|
||||
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'");
|
||||
CHECK_THROWS_WITH_AS(_ = 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::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))),
|
||||
"[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_WITH_AS(_ = 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::parse_error&);
|
||||
|
||||
SaxEventLogger l1;
|
||||
SaxEventLogger l2;
|
||||
@ -914,13 +888,9 @@ TEST_CASE("deserialization")
|
||||
SECTION("1 byte of BOM")
|
||||
{
|
||||
json _;
|
||||
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'");
|
||||
CHECK_THROWS_WITH_AS(_ = 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::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))),
|
||||
"[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_WITH_AS(_ = 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::parse_error&);
|
||||
|
||||
SaxEventLogger l1;
|
||||
SaxEventLogger l2;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user