Commit c458bf18 authored by Niels's avatar Niels

more test cases

parent 106705ed
...@@ -7687,13 +7687,15 @@ TEST_CASE("parser class") ...@@ -7687,13 +7687,15 @@ TEST_CASE("parser class")
{ {
auto s_object = R"( auto s_object = R"(
{ {
"foo": 1, "foo": 2,
"bar": 2 "bar": {
"baz": 1
}
} }
)"; )";
auto s_array = R"( auto s_array = R"(
[1,2,3,4,5] [1,2,3,4,[5]]
)"; )";
SECTION("filter nothing") SECTION("filter nothing")
...@@ -7703,14 +7705,14 @@ TEST_CASE("parser class") ...@@ -7703,14 +7705,14 @@ TEST_CASE("parser class")
return true; return true;
}); });
CHECK (j_object == json({{"foo", 1}, {"bar", 2}})); CHECK (j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}}));
json j_array = json::parse(s_array, [](int, json::parse_event_t, const json&) json j_array = json::parse(s_array, [](int, json::parse_event_t, const json&)
{ {
return true; return true;
}); });
CHECK (j_array == json({1, 2, 3, 4, 5})); CHECK (j_array == json({1, 2, 3, 4, {5}}));
} }
SECTION("filter everything") SECTION("filter everything")
...@@ -7745,7 +7747,7 @@ TEST_CASE("parser class") ...@@ -7745,7 +7747,7 @@ TEST_CASE("parser class")
} }
}); });
CHECK (j_object == json({{"foo", 1}})); CHECK (j_object == json({{"bar", {{"baz", 1}}}}));
json j_array = json::parse(s_array, [](int, json::parse_event_t, const json & j) json j_array = json::parse(s_array, [](int, json::parse_event_t, const json & j)
{ {
...@@ -7759,40 +7761,94 @@ TEST_CASE("parser class") ...@@ -7759,40 +7761,94 @@ TEST_CASE("parser class")
} }
}); });
CHECK (j_array == json({1, 3, 4, 5})); CHECK (j_array == json({1, 3, 4, {5}}));
} }
SECTION("filter specific events") SECTION("filter specific events")
{ {
json j_object = json::parse(s_object, [](int, json::parse_event_t e, const json &) SECTION("first closing event")
{ {
// filter all number(2) elements json j_object = json::parse(s_object, [](int, json::parse_event_t e, const json&)
if (e == json::parse_event_t::object_end)
{ {
return false; // filter all number(2) elements
} if (e == json::parse_event_t::object_end)
else {
return false;
}
else
{
return true;
}
});
CHECK (j_object.is_discarded());
json j_array = json::parse(s_array, [](int, json::parse_event_t e, const json&)
{ {
return true; // filter all number(2) elements
} if (e == json::parse_event_t::array_end)
}); {
return false;
CHECK (j_object.is_discarded()); }
else
{
return true;
}
});
json j_array = json::parse(s_array, [](int, json::parse_event_t e, const json &) CHECK (j_array.is_discarded());
}
SECTION("second closing event")
{ {
// filter all number(2) elements int i = 0;
if (e == json::parse_event_t::array_end) json j_object = json::parse(s_object, [&i](int, json::parse_event_t e, const json&)
{ {
return false; // filter all number(2) elements
} if (e == json::parse_event_t::object_end)
else {
if (i > 0)
{
return false;
}
else
{
++i;
return true;
}
}
else
{
return true;
}
});
CHECK (j_object.is_discarded());
i = 0;
json j_array = json::parse(s_array, [&i](int, json::parse_event_t e, const json&)
{ {
return true; // filter all number(2) elements
} if (e == json::parse_event_t::array_end)
}); {
if (i > 0)
CHECK (j_array.is_discarded()); {
return false;
}
else
{
++i;
return true;
}
}
else
{
return true;
}
});
CHECK (j_array.is_discarded());
}
} }
} }
} }
......
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