clean up and added tests
This commit is contained in:
parent
09e9f6dcd4
commit
fb54e212b6
3 changed files with 310 additions and 122 deletions
192
test/unit.cpp
192
test/unit.cpp
|
@ -12822,6 +12822,198 @@ TEST_CASE("JSON patch")
|
|||
CHECK(doc.apply_patch(patch) == expected);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("errors")
|
||||
{
|
||||
SECTION("unknown operation")
|
||||
{
|
||||
SECTION("missing 'op'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"foo", "bar"}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation must have member 'op'");
|
||||
}
|
||||
|
||||
SECTION("non-string 'op'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", 1}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation must have string member 'op'");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("add")
|
||||
{
|
||||
SECTION("missing 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "add"}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'add' must have member 'path'");
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "add"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'add' must have string member 'path'");
|
||||
}
|
||||
|
||||
SECTION("missing 'value'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "add"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'add' must have member 'value'");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("remove")
|
||||
{
|
||||
SECTION("missing 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "remove"}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'remove' must have member 'path'");
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "remove"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'remove' must have string member 'path'");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("replace")
|
||||
{
|
||||
SECTION("missing 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "replace"}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'replace' must have member 'path'");
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "replace"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'replace' must have string member 'path'");
|
||||
}
|
||||
|
||||
SECTION("missing 'value'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "replace"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'replace' must have member 'value'");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("move")
|
||||
{
|
||||
SECTION("missing 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "move"}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'move' must have member 'path'");
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "move"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'move' must have string member 'path'");
|
||||
}
|
||||
|
||||
SECTION("missing 'from'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "move"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'move' must have member 'from'");
|
||||
}
|
||||
|
||||
SECTION("non-string 'from'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'move' must have string member 'from'");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("copy")
|
||||
{
|
||||
SECTION("missing 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "copy"}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'copy' must have member 'path'");
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "copy"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'copy' must have string member 'path'");
|
||||
}
|
||||
|
||||
SECTION("missing 'from'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "copy"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'copy' must have member 'from'");
|
||||
}
|
||||
|
||||
SECTION("non-string 'from'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'copy' must have string member 'from'");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("test")
|
||||
{
|
||||
SECTION("missing 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "test"}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'test' must have member 'path'");
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "test"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'test' must have string member 'path'");
|
||||
}
|
||||
|
||||
SECTION("missing 'value'")
|
||||
{
|
||||
json j;
|
||||
json patch = {{{"op", "test"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.apply_patch(patch), std::domain_error);
|
||||
CHECK_THROWS_WITH(j.apply_patch(patch), "operation 'test' must have member 'value'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("regression tests")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue