diff options
author | Zufu Liu <unknown> | 2023-12-21 16:00:00 +1100 |
---|---|---|
committer | Zufu Liu <unknown> | 2023-12-21 16:00:00 +1100 |
commit | 8e55cc0c973cc2fbaac8cca1505524b86ce58dff (patch) | |
tree | 0cf01d056b0c92de62b811466495a42d82a7879b /test/unit/testDocument.cxx | |
parent | 1b153f8d8d4b2f09afc2d039256c958e94bd3b05 (diff) | |
download | scintilla-mirror-8e55cc0c973cc2fbaac8cca1505524b86ce58dff.tar.gz |
Bug [#2405]. Avoid character fragments in regular expression search results.
Diffstat (limited to 'test/unit/testDocument.cxx')
-rw-r--r-- | test/unit/testDocument.cxx | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx index ba7bb8616..a3fca9f5e 100644 --- a/test/unit/testDocument.cxx +++ b/test/unit/testDocument.cxx @@ -682,6 +682,44 @@ TEST_CASE("Document") { #endif } + SECTION("RESearchMovePositionOutsideCharUTF8") { + DocPlus doc(" a\xCE\x93\xCE\x93z ", CpUtf8);// a gamma gamma z + const Sci::Position docLength = doc.document.Length(); + constexpr std::string_view finding = R"([a-z](\w)\1)"; + + Match match = doc.FindString(0, docLength, finding, rePosix); + REQUIRE(match == Match(1, 5)); + + constexpr std::string_view substituteText = R"(\t\1\n)"; + std::string substituted = doc.Substitute(substituteText); + REQUIRE(substituted == "\t\xCE\x93\n"); + + #ifndef NO_CXX11_REGEX + match = doc.FindString(0, docLength, finding, reCxx11); + REQUIRE(match == Match(1, 5)); + + substituted = doc.Substitute(substituteText); + REQUIRE(substituted == "\t\xCE\x93\n"); + #endif + } + + SECTION("RESearchMovePositionOutsideCharDBCS") { + DocPlus doc(" \x98\x61xx 1aa\x83\xA1\x83\xA1z ", 932);// U+548C xx 1aa gamma gamma z + const Sci::Position docLength = doc.document.Length(); + + Match match = doc.FindString(0, docLength, R"([a-z](\w)\1)", rePosix); + REQUIRE(match == Match(8, 5)); + + constexpr std::string_view substituteText = R"(\t\1\n)"; + std::string substituted = doc.Substitute(substituteText); + REQUIRE(substituted == "\t\x83\xA1\n"); + + match = doc.FindString(0, docLength, R"(\w([a-z])\1)", rePosix); + REQUIRE(match == Match(6, 3)); + + substituted = doc.Substitute(substituteText); + REQUIRE(substituted == "\ta\n"); + } } |