Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor unit tests to use more convenient doctest assertion macros #3393

Merged
merged 26 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8b5abba
Add missing check
kkarbowiak Mar 16, 2022
d9d9aab
Refactor assertions in unit-algorithms.cpp
kkarbowiak Mar 17, 2022
f195887
Refactor assertions in unit-bson.cpp
kkarbowiak Mar 17, 2022
da6be70
Refactor assertions in unit-cbor.cpp
kkarbowiak Mar 17, 2022
b0646df
Refactor assertions in unit-class_const_iterator.cpp
kkarbowiak Mar 17, 2022
cd486f6
Refactor assertions in unit-class_iterator.cpp
kkarbowiak Mar 17, 2022
95e29df
Refactor assertions in unit-class_parser.cpp
kkarbowiak Mar 17, 2022
ffa5d9b
Refactor assertions in unit-constructor1.cpp
kkarbowiak Mar 17, 2022
2b37ebb
Refactor assertions in unit-convenience.cpp
kkarbowiak Mar 17, 2022
8140466
Refactor assertions in unit-conversions.cpp
kkarbowiak Mar 17, 2022
e7470de
Refactor assertions in unit-deserialization.cpp
kkarbowiak Mar 17, 2022
fc10743
Refactor assertions in unit-element_access1.cpp
kkarbowiak Mar 17, 2022
b77d802
Refactor assertions in unit-element_access2.cpp
kkarbowiak Mar 17, 2022
1c523fe
Refactor assertions in unit-iterators1.cpp
kkarbowiak Mar 17, 2022
ac8d903
Refactor assertions in unit-iterators2.cpp
kkarbowiak Mar 17, 2022
96783fd
Refactor assertions in unit-json_patch.cpp
kkarbowiak Mar 17, 2022
44d242d
Refactor assertions in unit-json_pointer.cpp
kkarbowiak Mar 17, 2022
16e9318
Refactor assertions in unit-modifiers.cpp
kkarbowiak Mar 17, 2022
3b1bdf4
Refactor assertions in unit-msgpack.cpp
kkarbowiak Mar 17, 2022
c8b8907
Refactor assertions in unit-reference_access.cpp
kkarbowiak Mar 17, 2022
b9ee1de
Refactor assertions in unit-regression1.cpp
kkarbowiak Mar 17, 2022
443d446
Refactor assertions in unit-serialization.cpp
kkarbowiak Mar 17, 2022
8c91092
Refactor assertions in unit-ubjson.cpp
kkarbowiak Mar 17, 2022
59e51e8
Refactor assertions in unit-unicode1.cpp
kkarbowiak Mar 17, 2022
4741215
Apply formatting
kkarbowiak Mar 17, 2022
bd24f68
Merge branch 'nlohmann:develop' into develop
kkarbowiak Mar 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions test/src/unit-algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ TEST_CASE("algorithms")
SECTION("sorting an object")
{
json j({{"one", 1}, {"two", 2}});
CHECK_THROWS_AS(std::sort(j.begin(), j.end()), json::invalid_iterator&);
CHECK_THROWS_WITH(std::sort(j.begin(), j.end()),
"[json.exception.invalid_iterator.209] cannot use offsets with object iterators");
CHECK_THROWS_WITH_AS(std::sort(j.begin(), j.end()), "[json.exception.invalid_iterator.209] cannot use offsets with object iterators", json::invalid_iterator&);
}
}

Expand Down
52 changes: 16 additions & 36 deletions test/src/unit-bson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,53 +44,46 @@ TEST_CASE("BSON")
SECTION("null")
{
json j = nullptr;
CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is null");
CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is null", json::type_error&);
}

SECTION("boolean")
{
SECTION("true")
{
json j = true;
CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is boolean");
CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is boolean", json::type_error&);
}

SECTION("false")
{
json j = false;
CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is boolean");
CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is boolean", json::type_error&);
}
}

SECTION("number")
{
json j = 42;
CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is number");
CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is number", json::type_error&);
}

SECTION("float")
{
json j = 4.2;
CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is number");
CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is number", json::type_error&);
}

SECTION("string")
{
json j = "not supported";
CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is string");
CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is string", json::type_error&);
}

SECTION("array")
{
json j = std::vector<int> {1, 2, 3, 4, 5, 6, 7};
CHECK_THROWS_AS(json::to_bson(j), json::type_error&);
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is array");
CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is array", json::type_error&);
}
}

Expand All @@ -100,11 +93,10 @@ TEST_CASE("BSON")
{
{ std::string("en\0try", 6), true }
};
CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&);
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.409] (/en) BSON key cannot contain code point U+0000 (at byte 2)");
CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.out_of_range.409] (/en) BSON key cannot contain code point U+0000 (at byte 2)", json::out_of_range&);
#else
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.409] BSON key cannot contain code point U+0000 (at byte 2)");
CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.out_of_range.409] BSON key cannot contain code point U+0000 (at byte 2)", json::out_of_range&);
#endif
}

Expand All @@ -119,8 +111,7 @@ TEST_CASE("BSON")
0x00, 0x00, 0x00, 0x80
};
json _;
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");
CHECK_THROWS_WITH_AS(_ = 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", json::parse_error&);
}

SECTION("objects")
Expand Down Expand Up @@ -764,9 +755,7 @@ TEST_CASE("Incomplete BSON Input")
};

json _;
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");
CHECK_THROWS_WITH_AS(_ = 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::parse_error&);

CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());

Expand All @@ -783,9 +772,7 @@ TEST_CASE("Incomplete BSON Input")
};

json _;
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");
CHECK_THROWS_WITH_AS(_ = 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::parse_error&);
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());

SaxCountdown scp(0);
Expand All @@ -807,9 +794,7 @@ TEST_CASE("Incomplete BSON Input")
};

json _;
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");
CHECK_THROWS_WITH_AS(_ = 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::parse_error&);
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());

SaxCountdown scp(1);
Expand All @@ -824,9 +809,7 @@ TEST_CASE("Incomplete BSON Input")
};

json _;
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");
CHECK_THROWS_WITH_AS(_ = 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::parse_error&);
CHECK(json::from_bson(incomplete_bson, true, false).is_discarded());

SaxCountdown scp(0);
Expand Down Expand Up @@ -872,8 +855,7 @@ TEST_CASE("Negative size of binary value")
0x00 // end marker
};
json _;
CHECK_THROWS_AS(_ = json::from_bson(input), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_bson(input), "[json.exception.parse_error.112] parse error at byte 15: syntax error while parsing BSON binary: byte array length cannot be negative, is -1");
CHECK_THROWS_WITH_AS(_ = json::from_bson(input), "[json.exception.parse_error.112] parse error at byte 15: syntax error while parsing BSON binary: byte array length cannot be negative, is -1", json::parse_error);
}

TEST_CASE("Unsupported BSON input")
Expand All @@ -887,9 +869,7 @@ TEST_CASE("Unsupported BSON input")
};

json _;
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");
CHECK_THROWS_WITH_AS(_ = json::from_bson(bson), "[json.exception.parse_error.114] parse error at byte 5: Unsupported BSON record type 0xFF", json::parse_error&);
CHECK(json::from_bson(bson, true, false).is_discarded());

SaxCountdown scp(0);
Expand Down
Loading