From 1bda842fcdc2bdb23c46205fda53d25bc9e9c64a Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Mon, 21 May 2018 14:20:48 -0400 Subject: [PATCH] Accept constant expressions in non-dds properties Closes #11940 --- cmake/test-files.cmake | 1 + .../mbgl/style/conversion/property_value.hpp | 14 ++++++++++--- test/style/conversion/property_value.test.cpp | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 test/style/conversion/property_value.test.cpp diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 2aadfa8a7f4..8105cbf5ceb 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -79,6 +79,7 @@ set(MBGL_TEST_FILES test/style/conversion/geojson_options.test.cpp test/style/conversion/layer.test.cpp test/style/conversion/light.test.cpp + test/style/conversion/property_value.test.cpp test/style/conversion/stringify.test.cpp test/style/conversion/tileset.test.cpp diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp index 3130661f61f..dc1c32830f6 100644 --- a/include/mbgl/style/conversion/property_value.hpp +++ b/include/mbgl/style/conversion/property_value.hpp @@ -29,11 +29,19 @@ struct Converter> { return {}; } - if (isFeatureConstant(**expression)) { - return { CameraFunction(std::move(*expression)) }; - } else { + if (!isFeatureConstant(**expression)) { error = { "property expressions not supported" }; return {}; + } else if (!isZoomConstant(**expression)) { + return { CameraFunction(std::move(*expression)) }; + } else { + auto literal = dynamic_cast(expression->get()); + assert(literal); + optional constant = fromExpressionValue(literal->getValue()); + if (!constant) { + return {}; + } + return PropertyValue(*constant); } } else if (isObject(value)) { optional> function = convert>(value, error); diff --git a/test/style/conversion/property_value.test.cpp b/test/style/conversion/property_value.test.cpp new file mode 100644 index 00000000000..dcb08bcec7f --- /dev/null +++ b/test/style/conversion/property_value.test.cpp @@ -0,0 +1,21 @@ +#include + +#include +#include +#include + +using namespace mbgl; +using namespace mbgl::style; +using namespace mbgl::style::conversion; + +TEST(StyleConversion, PropertyValue) { + // PropertyValue accepts a constant expression: https://github.com/mapbox/mapbox-gl-native/issues/11940 + Error error; + JSDocument doc; + doc.Parse<0>(R"(["literal", [1, 2]])"); + auto expected = std::array{{1, 2}}; + auto result = convert>>(doc, error); + ASSERT_TRUE(result); + ASSERT_TRUE(result->isConstant()); + ASSERT_EQ(result->asConstant(), expected); +}