diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-11-15 17:21:09 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2018-11-15 17:22:23 +0200 |
commit | d730f11b675cabc188a5b7756e94916b78162680 (patch) | |
tree | 7ad59109adef62851cbf1e27450639b215d7c95d | |
parent | 73dcfe2d0d3475ad9584969c7908ba681a3f5bfa (diff) | |
download | qtlocation-mapboxgl-upstream/property-expression-zoom-non-constant.tar.gz |
[core] PropertyExpression zoom evaluation should not assume zoom is non-constantupstream/property-expression-zoom-non-constant
-rw-r--r-- | include/mbgl/style/property_expression.hpp | 9 | ||||
-rw-r--r-- | test/style/properties.test.cpp | 9 |
2 files changed, 12 insertions, 6 deletions
diff --git a/include/mbgl/style/property_expression.hpp b/include/mbgl/style/property_expression.hpp index b198de02b2..db802eb7c3 100644 --- a/include/mbgl/style/property_expression.hpp +++ b/include/mbgl/style/property_expression.hpp @@ -25,8 +25,7 @@ public: bool isFeatureConstant() const { return expression::isFeatureConstant(*expression); } T evaluate(float zoom) const { - assert(!expression::isZoomConstant(*expression)); - assert(expression::isFeatureConstant(*expression)); + assert(isFeatureConstant()); const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(zoom, nullptr)); if (result) { const optional<T> typed = expression::fromExpressionValue<T>(*result); @@ -37,8 +36,8 @@ public: template <class Feature> T evaluate(const Feature& feature, T finalDefaultValue) const { - assert(expression::isZoomConstant(*expression)); - assert(!expression::isFeatureConstant(*expression)); + assert(isZoomConstant()); + assert(!isFeatureConstant()); const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext(&feature)); if (result) { const optional<T> typed = expression::fromExpressionValue<T>(*result); @@ -49,7 +48,7 @@ public: template <class Feature> T evaluate(float zoom, const Feature& feature, T finalDefaultValue) const { - assert(!expression::isFeatureConstant(*expression)); + assert(!isFeatureConstant()); const expression::EvaluationResult result = expression->evaluate(expression::EvaluationContext({zoom}, &feature)); if (result) { const optional<T> typed = expression::fromExpressionValue<T>(*result); diff --git a/test/style/properties.test.cpp b/test/style/properties.test.cpp index f3af1a92b2..69ffb0b0ba 100644 --- a/test/style/properties.test.cpp +++ b/test/style/properties.test.cpp @@ -1,7 +1,8 @@ #include <mbgl/test/util.hpp> -#include <mbgl/style/properties.hpp> #include <mbgl/style/expression/dsl.hpp> +#include <mbgl/style/expression/format_expression.hpp> +#include <mbgl/style/properties.hpp> #include <mbgl/renderer/property_evaluator.hpp> #include <mbgl/renderer/data_driven_property_evaluator.hpp> @@ -136,3 +137,9 @@ TEST(TransitioningDataDrivenPropertyValue, Evaluate) { ASSERT_FALSE(evaluateDataExpression(t1, 0ms).isConstant()) << "A paint property transition to a data-driven evaluates immediately to the final value (see https://github.com/mapbox/mapbox-gl-native/issues/8237)."; } + +TEST(PropertyValue, EvaluateFormatted) { + using namespace mbgl::style::expression; + using namespace mbgl::style::expression::dsl; + ASSERT_EQ(PropertyExpression<Formatted> { format("hello") }.evaluate(12.0).toString(), std::string("hello")); +} |