summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnand Thakker <github@anandthakker.net>2017-10-25 10:35:52 -0400
committerAnand Thakker <github@anandthakker.net>2017-10-25 11:53:48 -0400
commit02af0a671b43898a0739077a86e146968b3def23 (patch)
tree66e64961d950c745af02a9639329b4e9c56a3669
parentcd95df19bef84d5e42823a868dff43bb665781fe (diff)
downloadqtlocation-mapboxgl-02af0a671b43898a0739077a86e146968b3def23.tar.gz
Add unit test for isExpression
-rw-r--r--cmake/test-files.cmake1
-rw-r--r--src/mbgl/style/expression/is_expression.cpp29
-rw-r--r--test/style/expression/is_expression.test.cpp33
3 files changed, 49 insertions, 14 deletions
diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake
index 67c3adcb3d..5df5fb38d1 100644
--- a/cmake/test-files.cmake
+++ b/cmake/test-files.cmake
@@ -88,6 +88,7 @@ set(MBGL_TEST_FILES
test/style/conversion/stringify.test.cpp
# style/expression
+ test/style/expression/is_expression.test.cpp
test/style/expression/util.test.cpp
# style
diff --git a/src/mbgl/style/expression/is_expression.cpp b/src/mbgl/style/expression/is_expression.cpp
index 1b70c7a096..c7f6599d94 100644
--- a/src/mbgl/style/expression/is_expression.cpp
+++ b/src/mbgl/style/expression/is_expression.cpp
@@ -9,24 +9,25 @@ bool isExpression(const conversion::Convertible& value) {
using namespace mbgl::style::conversion;
static std::unordered_set<std::string> specialForms = {
- "literal",
- "match",
- "curve",
- "coalesce",
+ "all",
+ "any",
"array",
- "let",
- "var",
"at",
- "string",
- "number",
- "color",
"boolean",
- "to-string",
- "to-number",
- "to-color",
+ "case",
+ "coalesce",
+ "color",
+ "curve",
+ "let",
+ "literal",
+ "match",
+ "number",
+ "string",
"to-boolean",
- "any",
- "all"
+ "to-color",
+ "to-number",
+ "to-string",
+ "var",
};
if (!isArray(value) || arrayLength(value) == 0) return false;
diff --git a/test/style/expression/is_expression.test.cpp b/test/style/expression/is_expression.test.cpp
new file mode 100644
index 0000000000..bf76c3345e
--- /dev/null
+++ b/test/style/expression/is_expression.test.cpp
@@ -0,0 +1,33 @@
+#include <mbgl/test/util.hpp>
+#include <mbgl/util/io.hpp>
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/rapidjson.hpp>
+#include <mbgl/style/rapidjson_conversion.hpp>
+#include <mbgl/style/expression/is_expression.hpp>
+
+#include <rapidjson/document.h>
+
+using namespace mbgl;
+using namespace mbgl::style;
+
+TEST(Expression, IsExpression) {
+ rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> spec;
+ spec.Parse<0>(util::read_file("mapbox-gl-js/src/style-spec/reference/v8.json").c_str());
+ ASSERT_FALSE(spec.HasParseError());
+ ASSERT_TRUE(spec.IsObject() &&
+ spec.HasMember("expression_name") &&
+ spec["expression_name"].IsObject() &&
+ spec["expression_name"].HasMember("values") &&
+ spec["expression_name"]["values"].IsObject());
+
+ const auto& allExpressions = spec["expression_name"]["values"];
+
+ for(auto& entry : allExpressions.GetObject()) {
+ const std::string name { entry.name.GetString(), entry.name.GetStringLength() };
+ JSDocument document;
+ document.Parse<0>(R"([")" + name + R"("])");
+
+ const JSValue* expression = &document;
+ EXPECT_TRUE(expression::isExpression(conversion::Convertible(expression))) << name;
+ }
+}