diff options
Diffstat (limited to 'test/style')
-rw-r--r-- | test/style/conversion/stringify.test.cpp | 27 | ||||
-rw-r--r-- | test/style/expression/expression.test.cpp | 2 | ||||
-rw-r--r-- | test/style/filter.test.cpp | 14 |
3 files changed, 28 insertions, 15 deletions
diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index 0b2940a0e0..136f276aaf 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -80,23 +80,25 @@ TEST(Stringify, Filter) { } TEST(Stringify, CameraFunction) { + ASSERT_EQ(stringify(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 1 })), + "[\"interpolate\",[\"linear\"],[\"zoom\"],0.0,1.0]"); ASSERT_EQ(stringify(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 2 })), - "{\"type\":\"exponential\",\"base\":2.0,\"stops\":[[0.0,1.0]]}"); + "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]"); ASSERT_EQ(stringify(CameraFunction<float>(IntervalStops<float> { {{0, 1}} })), - "{\"type\":\"interval\",\"stops\":[[0.0,1.0]]}"); + "[\"step\",[\"zoom\"],0.0,1.0]"); } TEST(Stringify, SourceFunction) { ASSERT_EQ(stringify(SourceFunction<float>("property", ExponentialStops<float> { {{0, 1}}, 2 })), - "{\"property\":\"property\",\"type\":\"exponential\",\"base\":2.0,\"stops\":[[0.0,1.0]]}"); + "[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]"); ASSERT_EQ(stringify(SourceFunction<float>("property", IntervalStops<float> { {{0, 1}} })), - "{\"property\":\"property\",\"type\":\"interval\",\"stops\":[[0.0,1.0]]}"); + "[\"step\",[\"number\",[\"get\",\"property\"]],0.0,1.0]"); ASSERT_EQ(stringify(SourceFunction<float>("property", CategoricalStops<float> { {{CategoricalValue(true), 1}} })), - "{\"property\":\"property\",\"type\":\"categorical\",\"stops\":[[true,1.0]]}"); + "[\"case\",[\"boolean\",[\"get\",\"property\"]],1.0,[\"error\"]]"); ASSERT_EQ(stringify(SourceFunction<float>("property", IdentityStops<float> {})), - "{\"property\":\"property\",\"type\":\"identity\"}"); + "[\"number\",[\"get\",\"property\"]]"); ASSERT_EQ(stringify(SourceFunction<float>("property", IdentityStops<float> {}, 0.0f)), - "{\"property\":\"property\",\"type\":\"identity\",\"default\":0.0}"); + "[\"number\",[\"get\",\"property\"]]"); } TEST(Stringify, CompositeFunction) { @@ -108,16 +110,17 @@ TEST(Stringify, CompositeFunction) { }, 2 }, 0.0f)), - "{\"property\":\"property\",\"type\":\"exponential\",\"base\":2.0," - "\"stops\":[" - "[{\"zoom\":0.0,\"value\":0.0},1.0]," - "[{\"zoom\":1.0,\"value\":0.0},1.0]],\"default\":0.0}"); + "[\"interpolate\"," + "[\"linear\"]," + "[\"zoom\"]," + "0.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]," + "1.0,[\"interpolate\",[\"exponential\",2.0],[\"number\",[\"get\",\"property\"]],0.0,1.0]]"); } TEST(Stringify, PropertyValue) { ASSERT_EQ(stringify(PropertyValue<float>(1)), "1.0"); ASSERT_EQ(stringify(PropertyValue<float>(CameraFunction<float>(ExponentialStops<float> { {{0, 1}}, 2 }))), - "{\"type\":\"exponential\",\"base\":2.0,\"stops\":[[0.0,1.0]]}"); + "[\"interpolate\",[\"exponential\",2.0],[\"zoom\"],0.0,1.0]"); } TEST(Stringify, Layout) { diff --git a/test/style/expression/expression.test.cpp b/test/style/expression/expression.test.cpp index 694569695c..fe5c261be1 100644 --- a/test/style/expression/expression.test.cpp +++ b/test/style/expression/expression.test.cpp @@ -49,7 +49,7 @@ TEST_P(ExpressionEqualityTest, ExpressionEquality) { assert(!document.HasParseError()); const JSValue* expression = &document; expression::ParsingContext ctx; - expression::ParseResult parsed = ctx.parse(conversion::Convertible(expression)); + expression::ParseResult parsed = ctx.parseExpression(conversion::Convertible(expression)); if (!parsed) { error_ = ctx.getErrors().size() > 0 ? ctx.getErrors()[0].message : "failed to parse"; }; diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp index 6f261c43ec..49edcaef45 100644 --- a/test/style/filter.test.cpp +++ b/test/style/filter.test.cpp @@ -11,14 +11,19 @@ using namespace mbgl; using namespace mbgl::style; -bool filter(const char * json, const PropertyMap& featureProperties = {{}}, optional<FeatureIdentifier> featureId = {}, FeatureType featureType = FeatureType::Point, GeometryCollection featureGeometry = {}) { +bool filter(const char * json, + const PropertyMap& featureProperties = {{}}, + optional<FeatureIdentifier> featureId = {}, + FeatureType featureType = FeatureType::Point, + GeometryCollection featureGeometry = {}, + float zoom = 0.0f) { conversion::Error error; optional<Filter> filter = conversion::convertJSON<Filter>(json, error); EXPECT_TRUE(bool(filter)); EXPECT_EQ(error.message, ""); StubGeometryTileFeature feature { featureId, featureType, featureGeometry, featureProperties }; - expression::EvaluationContext context = { &feature }; + expression::EvaluationContext context = { zoom, &feature }; return (*filter)(context); } @@ -109,3 +114,8 @@ TEST(Filter, PropertyExpression) { ASSERT_TRUE(filter("[\"==\", [\"get\", \"two\"], 2]", {{"two", int64_t(2)}})); ASSERT_FALSE(filter("[\"==\", [\"get\", \"two\"], 4]", {{"two", int64_t(2)}})); } + +TEST(Filter, ZoomExpressionNested) { + ASSERT_TRUE(filter(R"(["==", ["get", "two"], ["zoom"]])", {{"two", int64_t(2)}}, {}, FeatureType::Point, {}, 2.0f)); + ASSERT_FALSE(filter(R"(["==", ["get", "two"], ["+", ["zoom"], 1]])", {{"two", int64_t(2)}}, {}, FeatureType::Point, {}, 2.0f)); +} |