Skip to content

Commit

Permalink
Merge pull request mapnik#3921 from lightmare/unicode-attr-name
Browse files Browse the repository at this point in the history
add test for parsing expression with non-ascii characters in attribute name
  • Loading branch information
artemp authored Jul 2, 2018
2 parents 9e30144 + 5544c4c commit 5106598
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions test/unit/core/expressions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <mapnik/unicode.hpp>

#include <functional>
#include <vector>
#include <map>

namespace {

Expand Down Expand Up @@ -57,14 +57,15 @@ std::string parse_and_dump(std::string const& str)
TEST_CASE("expressions")
{
using namespace std::placeholders;
using properties_type = std::vector<std::pair<std::string, mapnik::value> > ;
using properties_type = std::map<std::string, mapnik::value>;
mapnik::transcoder tr("utf8");

properties_type prop = {{ "foo" , tr.transcode("bar") },
{ "name" , tr.transcode("Québec")},
{ "grass" , tr.transcode("grow")},
{ "wind" , tr.transcode("blow")},
{ "sky" , tr.transcode("is blue")},
{ "τ" , mapnik::value_double(6.2831853)},
{ "double", mapnik::value_double(1.23456)},
{ "int" , mapnik::value_integer(123)},
{ "bool" , mapnik::value_bool(true)},
Expand All @@ -74,8 +75,6 @@ TEST_CASE("expressions")
auto eval = std::bind(evaluate_string, feature, _1);
auto approx = Approx::custom().epsilon(1e-6);

TRY_CHECK(eval(" [foo]='bar' ") == true);

// primary expressions
// null
TRY_CHECK(parse_and_dump("null") == "null");
Expand All @@ -98,6 +97,17 @@ TEST_CASE("expressions")
TRY_CHECK(parse_and_dump("deg_to_rad") == "0.0174533");
TRY_CHECK(parse_and_dump("rad_to_deg") == "57.2958");

// ascii attribute name
TRY_CHECK(eval(" [foo]='bar' ") == true);

// unicode attribute name
TRY_CHECK(eval("[τ]") == prop.at("τ"));
TRY_CHECK(eval("[τ]") == eval(u8"[\u03C4]"));

// change to TRY_CHECK once \u1234 escape sequence in attribute name
// is implemented in expression grammar
CHECK_NOFAIL(eval("[τ]") == eval("[\\u03C3]"));

// unary functions
// sin / cos
TRY_CHECK(eval(" sin(0.25 * pi) / cos(0.25 * pi) ").to_double() == approx(1.0));
Expand Down

0 comments on commit 5106598

Please sign in to comment.