From aa77eb4550d29158c74d479f873d672ba156aa3b Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 9 Aug 2016 16:13:12 +0100 Subject: [PATCH] Expressions - add more regex tests to cover #3483 --- src/expression_node.cpp | 4 ++-- test/unit/core/expressions_test.cpp | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/expression_node.cpp b/src/expression_node.cpp index 380c36a4e..549f4c891 100644 --- a/src/expression_node.cpp +++ b/src/expression_node.cpp @@ -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 diff --git a/test/unit/core/expressions_test.cpp b/test/unit/core/expressions_test.cpp index e60d6127b..9f6a919f3 100644 --- a/test/unit/core/expressions_test.cpp +++ b/test/unit/core/expressions_test.cpp @@ -1,4 +1,3 @@ - #include "catch_ext.hpp" #include @@ -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('(?