diff options
author | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2018-05-04 17:26:32 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2018-05-09 16:08:50 -0700 |
commit | 45afc8f572dcfb54dac5b075c8c2f19b163a453c (patch) | |
tree | adbfe6106ee7bd287d45edb3a3245d254bf5068d /test/style/filter.test.cpp | |
parent | 5cd6b4710e93a5f7893eb6111ae62983cfc7aefe (diff) | |
download | qtlocation-mapboxgl-45afc8f572dcfb54dac5b075c8c2f19b163a453c.tar.gz |
Adress review: Comments + Tests
Diffstat (limited to 'test/style/filter.test.cpp')
-rw-r--r-- | test/style/filter.test.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
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> filter = conversion::convertJSON<Filter>(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) }})); |