aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/unit/testDocument.cxx
diff options
context:
space:
mode:
authorZufu Liu <unknown>2023-10-15 08:46:43 +1100
committerZufu Liu <unknown>2023-10-15 08:46:43 +1100
commit6658e397e2d0447bef4c5dd1db1c38d5d7917ac9 (patch)
treede11bc1a7c36a52fe8ae0be87408badcee161d81 /test/unit/testDocument.cxx
parent0a00f1b52c9f05800192db71ccc28dfaed58729b (diff)
downloadscintilla-mirror-6658e397e2d0447bef4c5dd1db1c38d5d7917ac9.tar.gz
Bug [#2405]. Fix incorrect substitution when searching for a regular expression
backwards.
Diffstat (limited to 'test/unit/testDocument.cxx')
-rw-r--r--test/unit/testDocument.cxx46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx
index 3cfb54db4..4ed1dbbbd 100644
--- a/test/unit/testDocument.cxx
+++ b/test/unit/testDocument.cxx
@@ -453,6 +453,52 @@ TEST_CASE("Document") {
REQUIRE(doc.NextPosition(15, -1) == 14);
}
+ SECTION("RegexSearchAndSubstitution") {
+ DocPlus doc("\n\r\r\n 1a\xCE\x93z \n\r\r\n 2b\xCE\x93y \n\r\r\n", CpUtf8);// 1a gamma z 2b gamma y
+ const std::string finding = R"(\d+(\w+))";
+ Sci::Position lengthFinding = finding.length();
+ Sci::Position location = doc.FindNeedle(finding, FindOption::RegExp | FindOption::Posix, &lengthFinding);
+ REQUIRE(location == 5);
+ REQUIRE(lengthFinding == 5);
+
+ const std::string_view substituteText = R"(\t\1\n)";
+ Sci::Position lengthsubstitute = substituteText.length();
+ std::string substituted = doc.document.SubstituteByPosition(substituteText.data(), &lengthsubstitute);
+ REQUIRE(lengthsubstitute == 6);
+ REQUIRE(substituted == "\ta\xCE\x93z\n");
+
+ lengthFinding = finding.length();
+ location = doc.FindNeedleReverse(finding, FindOption::RegExp | FindOption::Posix, &lengthFinding);
+ REQUIRE(location == 16);
+ REQUIRE(lengthFinding == 5);
+
+ lengthsubstitute = substituteText.length();
+ substituted = doc.document.SubstituteByPosition(substituteText.data(), &lengthsubstitute);
+ REQUIRE(lengthsubstitute == 6);
+ REQUIRE(substituted == "\tb\xCE\x93y\n");
+
+ #ifndef NO_CXX11_REGEX
+ lengthFinding = finding.length();
+ location = doc.FindNeedle(finding, FindOption::RegExp | FindOption::Cxx11RegEx, &lengthFinding);
+ REQUIRE(location == 5);
+ REQUIRE(lengthFinding == 5);
+
+ lengthsubstitute = substituteText.length();
+ substituted = doc.document.SubstituteByPosition(substituteText.data(), &lengthsubstitute);
+ REQUIRE(lengthsubstitute == 6);
+ REQUIRE(substituted == "\ta\xCE\x93z\n");
+
+ lengthFinding = finding.length();
+ location = doc.FindNeedleReverse(finding, FindOption::RegExp | FindOption::Cxx11RegEx, &lengthFinding);
+ REQUIRE(location == 16);
+ REQUIRE(lengthFinding == 5);
+
+ lengthsubstitute = substituteText.length();
+ substituted = doc.document.SubstituteByPosition(substituteText.data(), &lengthsubstitute);
+ REQUIRE(lengthsubstitute == 6);
+ REQUIRE(substituted == "\tb\xCE\x93y\n");
+ #endif
+ }
}
TEST_CASE("Words") {