diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-03-28 00:44:32 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-03-28 14:57:08 +0200 |
commit | 341058cd62472c6f2430db18950345de34f324cb (patch) | |
tree | c79bc55a5b02035f40432de94322c1bc23010e1b /test | |
parent | bbefcb6d516d1602cf1e254ebe90c63727bdc8d6 (diff) | |
download | qtlocation-mapboxgl-upstream/alexshalamov_check_nested_expression_overrides.tar.gz |
[core] Traverse expression tree when checking for property overridesupstream/alexshalamov_check_nested_expression_overrides
Before this change, symbol layer was only checking whether top level
'text-field' layout property expression is FormatExpression and if it
has paint property overrides. This change takes into account that
'text-field' might have nested expressions, thus, requires traversal
over child expressions.
Fixes: #14254
Diffstat (limited to 'test')
-rw-r--r-- | test/style/style_layer.test.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp index e58a5fe5d0..7598d888e9 100644 --- a/test/style/style_layer.test.cpp +++ b/test/style/style_layer.test.cpp @@ -1,4 +1,5 @@ #include <mbgl/style/expression/dsl.hpp> +#include <mbgl/style/expression/match.hpp> #include <mbgl/style/expression/format_expression.hpp> #include <mbgl/style/style_impl.hpp> #include <mbgl/style/layers/background_layer.hpp> @@ -330,6 +331,17 @@ void testHasOverrides(LayoutType& layout) { PropertyExpression<Formatted> propExprOverride(std::move(formatExprOverride)); layout.template get<TextField>() = PropertyValueType<Formatted>(std::move(propExprOverride)); EXPECT_TRUE(MockOverrides::hasOverrides(layout.template get<TextField>())); + + // Nested expressions, overridden text-color. + auto formattedExpr1 = format("first paragraph"); + std::vector<FormatExpressionSection> sections{ { literal("second paragraph"), nullopt, nullopt, toColor(literal("blue")) } }; + auto formattedExpr2 = std::make_unique<FormatExpression>(std::move(sections)); + std::unordered_map<std::string, std::shared_ptr<Expression>> branches{ { "1st", std::move(formattedExpr1) }, + { "2nd", std::move(formattedExpr2) } }; + auto match = std::make_unique<Match<std::string>>(type::Formatted, literal("input"), std::move(branches), format("otherwise")); + PropertyExpression<Formatted> nestedPropExpr(std::move(match)); + layout.template get<TextField>() = PropertyValueType<Formatted>(std::move(nestedPropExpr)); + EXPECT_TRUE(MockOverrides::hasOverrides(layout.template get<TextField>())); } } // namespace |