From 45afc8f572dcfb54dac5b075c8c2f19b163a453c Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Fri, 4 May 2018 17:26:32 -0700 Subject: Adress review: Comments + Tests --- test/style/filter.test.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test/style/filter.test.cpp') diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp index 5fd8e234da..e770f707c8 100644 --- a/test/style/filter.test.cpp +++ b/test/style/filter.test.cpp @@ -27,6 +27,17 @@ bool filter(const char * json, return (*filter)(context); } +void invalidFilter(const char * json) { + conversion::Error error; + optional filter = conversion::convertJSON(json, error); + EXPECT_FALSE(bool(filter)); + EXPECT_NE(error.message, ""); +} + +TEST(Filter, EqualsInvalid) { + invalidFilter("[\"==\", \"foo\", null]"); + invalidFilter("[\"==\", \"foo\", [1, 2]]"); +} TEST(Filter, EqualsString) { auto f = R"(["==", "foo", "bar"])"; ASSERT_TRUE(filter(f, {{ "foo", std::string("bar") }})); @@ -52,6 +63,12 @@ TEST(Filter, EqualsType) { auto f = R"(["==", "$type", "LineString"])"; ASSERT_FALSE(filter(f, {{}}, {}, FeatureType::Point, {})); ASSERT_TRUE(filter(f, {{}}, {}, FeatureType::LineString, {})); + ASSERT_FALSE(filter(f, {{}}, {}, FeatureType::Point, {})); + + invalidFilter("[\"==\", \"$type\"]"); + invalidFilter("[\"==\", \"$type\", null]"); + invalidFilter("[\"==\", \"$type\", \"foo\", 1]"); + invalidFilter("[\"==\", \"$type\", \"foo\", \"Point\"]"); } TEST(Filter, InType) { @@ -76,6 +93,13 @@ TEST(Filter, Any) { ASSERT_TRUE(filter("[\"any\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }})); } +TEST(Filter, AnyExpression) { + ASSERT_FALSE(filter("[\"any\"]")); + ASSERT_TRUE(filter("[\"any\", true]")); + ASSERT_TRUE(filter("[\"any\",true, false]")); + ASSERT_TRUE(filter("[\"any\", true, true]")); +} + TEST(Filter, All) { ASSERT_TRUE(filter("[\"all\"]", {{}})); ASSERT_TRUE(filter("[\"all\", [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }})); @@ -83,6 +107,13 @@ TEST(Filter, All) { ASSERT_FALSE(filter("[\"all\", [\"==\", \"foo\", 0], [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }})); } +TEST(Filter, AllExpression) { + ASSERT_TRUE(filter("[\"all\"]")); + ASSERT_TRUE(filter("[\"all\", true]")); + ASSERT_FALSE(filter("[\"all\",true, false]")); + ASSERT_TRUE(filter("[\"any\", true, true]")); +} + TEST(Filter, None) { ASSERT_TRUE(filter("[\"none\"]")); ASSERT_FALSE(filter("[\"none\", [\"==\", \"foo\", 1]]", {{ std::string("foo"), int64_t(1) }})); -- cgit v1.2.1