summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2018-10-01 14:06:49 -0700
committerChris Loer <chris.loer@mapbox.com>2018-10-15 13:15:46 -0700
commitd4c9b21bae5702dff6670dddf771385103e70504 (patch)
tree06c9cddfee44acb24b4e1d16efefbc9d8edbf14e
parentfdfb9386a6732d5a00c5c205013aa1d9ed8b91a4 (diff)
downloadqtlocation-mapboxgl-d4c9b21bae5702dff6670dddf771385103e70504.tar.gz
[core, tests] Don't break text-field support "identity functions"
-rw-r--r--src/mbgl/style/conversion/function.cpp3
-rw-r--r--test/style/conversion/function.test.cpp18
2 files changed, 21 insertions, 0 deletions
diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp
index 34ac52ec1b..5877d0eb7c 100644
--- a/src/mbgl/style/conversion/function.cpp
+++ b/src/mbgl/style/conversion/function.cpp
@@ -700,6 +700,9 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
[&] (const type::Array& array) -> optional<std::unique_ptr<Expression>> {
return assertion(array, get(literal(*property)));
},
+ [&] (const type::FormattedType&) -> optional<std::unique_ptr<Expression>> {
+ return format(get(literal(*property)));
+ },
[&] (const auto&) -> optional<std::unique_ptr<Expression>> {
assert(false); // No properties use this type.
return nullopt;
diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp
index 8ebdcdb9bb..93a9a7e608 100644
--- a/test/style/conversion/function.test.cpp
+++ b/test/style/conversion/function.test.cpp
@@ -92,3 +92,21 @@ TEST(StyleConversion, TokenStrings) {
ASSERT_EQ(*convertTokenStringToExpression("{token} {token"), *concat(vec(get(literal("token")), literal(" "), literal("{token"))));
ASSERT_EQ(*convertTokenStringToExpression("{token {token}"), *concat(vec(literal("{token "), get(literal("token")))));
}
+
+
+TEST(StyleConversion, FormattedIdentityFunction) {
+ // See https://github.com/mapbox/mapbox-gl-js/issues/7311
+ // We never introduced this bug on gl-native, but we _almost_ did
+ Error error;
+
+ auto parseFunction = [&](const std::string& json) {
+ return convertJSON<PropertyValue<mbgl::style::expression::Formatted>>(json, error, true, false);
+ };
+
+ using namespace mbgl::style::expression::dsl;
+
+ auto fn1 = parseFunction(R"({ "property": "name", "type": "identity" })");
+ ASSERT_TRUE(bool(fn1));
+ ASSERT_TRUE(fn1->isExpression());
+ ASSERT_EQ(fn1->asExpression().getExpression(), *format(get(literal("name"))));
+}