diff options
author | Lucas Wojciechowski <lucas@mapbox.com> | 2018-04-23 14:48:57 -0700 |
---|---|---|
committer | Asheem Mamoowala <asheem.mamoowala@mapbox.com> | 2018-05-09 16:08:50 -0700 |
commit | 5f69284f22e6639e1b86319944a5262892d1b599 (patch) | |
tree | df5be92015c439f786b4b9eb5b54108694abe317 | |
parent | 8dd21f0107180ce3837a7c2edf551e5be575e1dc (diff) | |
download | qtlocation-mapboxgl-5f69284f22e6639e1b86319944a5262892d1b599.tar.gz |
Add `createLiteral` convenience method
-rw-r--r-- | include/mbgl/style/expression/literal.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/style/expression/literal.cpp | 8 | ||||
-rw-r--r-- | test/style/conversion/stringify.test.cpp | 7 |
3 files changed, 16 insertions, 2 deletions
diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp index a00c468efc..d3b3a20cce 100644 --- a/include/mbgl/style/expression/literal.hpp +++ b/include/mbgl/style/expression/literal.hpp @@ -51,6 +51,9 @@ private: Value value; }; +std::unique_ptr<Literal> createLiteral(const char* value); +std::unique_ptr<Literal> createLiteral(Value value); + } // namespace expression } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/expression/literal.cpp b/src/mbgl/style/expression/literal.cpp index 8a63980dba..f68cfd5cf5 100644 --- a/src/mbgl/style/expression/literal.cpp +++ b/src/mbgl/style/expression/literal.cpp @@ -109,6 +109,14 @@ mbgl::Value Literal::serialize() const { return *fromExpressionValue<mbgl::Value>(value); } } + +std::unique_ptr<Literal> createLiteral(const char* value) { + return createLiteral(std::string(value)); +} + +std::unique_ptr<Literal> createLiteral(Value value) { + return std::make_unique<Literal>(value); +} } // namespace expression } // namespace style diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index 851301d515..c3faf1f838 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -1,5 +1,6 @@ #include <mbgl/test/util.hpp> +#include <mbgl/style/expression/literal.hpp> #include <mbgl/style/conversion/stringify.hpp> #include <mbgl/style/types.hpp> #include <mbgl/style/layers/symbol_layer_properties.hpp> @@ -75,10 +76,12 @@ TEST(Stringify, Value) { } TEST(Stringify, Filter) { + using namespace mbgl::style::expression; + ASSERT_EQ(stringify(Filter()), "null"); - expression::ParsingContext context; - ASSERT_EQ(stringify(Filter(expression::createCompoundExpression("filter-==", std::make_unique<expression::Literal>(std::string("a")), std::make_unique<expression::Literal>(1.0), context))), "[\"filter-==\",\"a\",1.0]"); + ParsingContext context; + ASSERT_EQ(stringify(Filter(createCompoundExpression("filter-==", createLiteral("a"), createLiteral(1.0), context))), "[\"filter-==\",\"a\",1.0]"); } TEST(Stringify, CameraFunction) { |