Expressions - add more regex tests to cover #3483

This commit is contained in:
artemp 2016-08-09 16:13:12 +01:00
parent 6eb7783f9e
commit aa77eb4550
2 changed files with 16 additions and 5 deletions

View file

@ -130,9 +130,9 @@ value regex_replace_node::apply(value const& v) const
auto const& pattern = impl_.get()->pattern_;
auto const& format = impl_.get()->format_;
#if defined(BOOST_REGEX_HAS_ICU)
return boost::u32regex_replace(v.to_unicode(),pattern,format);
return boost::u32regex_replace(v.to_unicode(), pattern, format);
#else
std::string repl = boost::regex_replace(v.to_string(),pattern,format);
std::string repl = boost::regex_replace(v.to_string(), pattern, format);
transcoder tr_("utf8");
return tr_.transcode(repl.c_str());
#endif

View file

@ -1,4 +1,3 @@
#include "catch_ext.hpp"
#include <mapnik/expression.hpp>
@ -176,6 +175,18 @@ TEST_CASE("expressions")
// regex
// replace
TRY_CHECK(eval(" [foo].replace('(\\B)|( )','$1 ') ") == tr.transcode("b a r"));
// https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode
//'\u265C\u265E\u265D\u265B\u265A\u265D\u265E\u265C' - black chess figures
// replace black knights with white knights
auto val0 = eval(u8"'\u265C\u265E\u265D\u265B\u265A\u265D\u265E\u265C'.replace('\u265E','\u2658')");
auto val1 = eval(u8"'♜♞♝♛♚♝♞♜'.replace('♞','♘')"); // ==> expected ♜♘♝♛♚♝♘♜
TRY_CHECK(val0 == val1);
TRY_CHECK(val0.to_string() == val1.to_string());
// following test will fail if boost_regex is built without ICU support (unpaired surrogates in output)
TRY_CHECK(eval("[name].replace('(\\B)|( )',' ') ") == tr.transcode(u8"Q u é b e c"));
TRY_CHECK(eval("'Москва'.replace('(?<!^)(\\B|b)(?!$)',' ')") == tr.transcode(u8"М о с к в а"));
// 'foo' =~ s:(\w)\1:$1x:r
TRY_CHECK(eval(" 'foo'.replace('(\\w)\\1', '$1x') ") == tr.transcode("fox"));
TRY_CHECK(parse_and_dump(" 'foo'.replace('(\\w)\\1', '$1x') ") == "'foo'.replace('(\\w)\\1','$1x')");
@ -187,8 +198,8 @@ TEST_CASE("expressions")
TRY_CHECK(parse_and_dump(" [name].match('^Q\\S*$') ") == "[name].match('^Q\\S*$')");
// string & value concatenation
// this should evaluate as two strings concatenating, but currently fails
// this should evaluate as two strings concatenating
TRY_CHECK(eval("Hello + '!'") == eval("'Hello!'"));
// this should evaulate as a combination of an int value and string, but fails
// this should evaulate as a combination of an int value and string
TRY_CHECK(eval("[int]+m") == eval("'123m'"));
}