summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-07-13 17:02:30 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-07-20 12:35:00 -0700
commitaf89318b1d3bef15e92e591887c9d65b10be54ce (patch)
treed3ccb07da91bb56197607f5319100e64f7493211 /test
parenta3d988ab8520ea12272bb80a746a2d91cbc332f5 (diff)
downloadqtlocation-mapboxgl-af89318b1d3bef15e92e591887c9d65b10be54ce.tar.gz
[core] Convert token strings to expressions
Diffstat (limited to 'test')
-rw-r--r--test/style/conversion/function.test.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/test/style/conversion/function.test.cpp b/test/style/conversion/function.test.cpp
index fa89576afa..4612147f76 100644
--- a/test/style/conversion/function.test.cpp
+++ b/test/style/conversion/function.test.cpp
@@ -4,6 +4,7 @@
#include <mbgl/style/conversion/constant.hpp>
#include <mbgl/style/conversion/property_value.hpp>
#include <mbgl/style/conversion/data_driven_property_value.hpp>
+#include <mbgl/style/expression/dsl.hpp>
using namespace mbgl;
using namespace mbgl::style;
@@ -56,7 +57,7 @@ TEST(StyleConversion, CompositeFunctionExpression) {
Error error;
auto parseFunction = [&](const std::string& json) {
- return convertJSON<DataDrivenPropertyValue<float>>(json, error);
+ return convertJSON<DataDrivenPropertyValue<float>>(json, error, false);
};
auto fn1 = parseFunction(R"(["interpolate", ["linear"], ["zoom"], 0, ["number", ["get", "x"]], 10, 10])");
@@ -75,3 +76,20 @@ TEST(StyleConversion, CompositeFunctionExpression) {
ASSERT_FALSE(fn5);
ASSERT_EQ(R"("zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.)", error.message);
}
+
+TEST(StyleConversion, TokenStrings) {
+ ASSERT_FALSE(hasTokens(""));
+ ASSERT_FALSE(hasTokens("{"));
+ ASSERT_FALSE(hasTokens("{token"));
+ ASSERT_TRUE(hasTokens("{token}"));
+ ASSERT_TRUE(hasTokens("token {token}"));
+ ASSERT_TRUE(hasTokens("{token} {token}"));
+
+ using namespace mbgl::style::expression::dsl;
+ ASSERT_EQ(*convertTokenStringToExpression("{token}"), *toString(get(literal("token"))));
+ ASSERT_EQ(*convertTokenStringToExpression("token {token}"), *concat(vec(literal("token "), toString(get(literal("token"))))));
+ ASSERT_EQ(*convertTokenStringToExpression("{token} token"), *concat(vec(toString(get(literal("token"))), literal(" token"))));
+ ASSERT_EQ(*convertTokenStringToExpression("{token} {token}"), *concat(vec(toString(get(literal("token"))), literal(" "), toString(get(literal("token"))))));
+ ASSERT_EQ(*convertTokenStringToExpression("{token} {token"), *concat(vec(toString(get(literal("token"))), literal(" "), literal("{token"))));
+ ASSERT_EQ(*convertTokenStringToExpression("{token {token}"), *concat(vec(literal("{token "), toString(get(literal("token"))))));
+}