提交 10bbb774 编写于 作者: N Niels

test case for filter function

上级 1143094e
...@@ -7687,8 +7687,8 @@ TEST_CASE("parser class") ...@@ -7687,8 +7687,8 @@ TEST_CASE("parser class")
{ {
auto s_object = R"( auto s_object = R"(
{ {
"foo": true, "foo": 1,
"bar": false "bar": 2
} }
)"; )";
...@@ -7696,14 +7696,14 @@ TEST_CASE("parser class") ...@@ -7696,14 +7696,14 @@ TEST_CASE("parser class")
[1,2,3,4,5] [1,2,3,4,5]
)"; )";
SECTION("true-filter") SECTION("filter nothing")
{ {
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&) json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&)
{ {
return true; return true;
}); });
CHECK (j_object == json({{"foo", true}, {"bar", false}})); CHECK (j_object == json({{"foo", 1}, {"bar", 2}}));
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&)
{ {
...@@ -7713,7 +7713,7 @@ TEST_CASE("parser class") ...@@ -7713,7 +7713,7 @@ TEST_CASE("parser class")
CHECK (j_array == json({1, 2, 3, 4, 5})); CHECK (j_array == json({1, 2, 3, 4, 5}));
} }
SECTION("false-filter") SECTION("filter everything")
{ {
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&) json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&)
{ {
...@@ -7729,6 +7729,38 @@ TEST_CASE("parser class") ...@@ -7729,6 +7729,38 @@ TEST_CASE("parser class")
CHECK (j_array.is_discarded()); CHECK (j_array.is_discarded());
} }
SECTION("filter specific element")
{
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json & j)
{
// filter all number(2) elements
if (j == json(2))
{
return false;
}
else
{
return true;
}
});
CHECK (j_object == json({{"foo", 1}}));
json j_array = json::parse(s_array, [](int, json::parse_event_t, const json & j)
{
if (j == json(2))
{
return false;
}
else
{
return true;
}
});
CHECK (j_array == json({1, 3, 4, 5}));
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册