aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZufu Liu <unknown>2023-12-07 09:28:42 +1100
committerZufu Liu <unknown>2023-12-07 09:28:42 +1100
commit735b490e3e29c6ee2cce6a723f900a5394e38399 (patch)
tree35935da7634b7d12247c8ada03d7add1e4cac003
parent53d83fb203491b773be90debb96c6ae6381d4cce (diff)
downloadscintilla-mirror-735b490e3e29c6ee2cce6a723f900a5394e38399.tar.gz
Simplify substitution checks.
Set global locale for llvm-mingw libc++. Add test for \w+ which currently fails for RESearch.
-rw-r--r--cppcheck.suppress2
-rw-r--r--test/unit/testDocument.cxx73
2 files changed, 36 insertions, 39 deletions
diff --git a/cppcheck.suppress b/cppcheck.suppress
index 092de64ee..5e404b6df 100644
--- a/cppcheck.suppress
+++ b/cppcheck.suppress
@@ -85,6 +85,8 @@ passedByValue
// Checks for moves move to variables that are not read but the moved from is checked
unreadVariable:scintilla/test/unit/*.cxx
accessMoved:scintilla/test/unit/*.cxx
+// Temporary code for test that fails
+redundantAssignment:scintilla/test/unit/testDocument.cxx
// cppcheck fails REQUIRE from Catch
comparisonOfFuncReturningBoolError:scintilla/test/unit/*.cxx
diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx
index bf50bfd04..e3ab0b553 100644
--- a/test/unit/testDocument.cxx
+++ b/test/unit/testDocument.cxx
@@ -38,7 +38,6 @@
using namespace Scintilla;
using namespace Scintilla::Internal;
-#if !defined(_WIN32) && !defined(NO_CXX11_REGEX)
// set global locale to pass std::regex related tests
// see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63776
struct GlobalLocaleInitializer {
@@ -48,7 +47,6 @@ struct GlobalLocaleInitializer {
} catch (...) {}
}
} globalLocaleInitializer;
-#endif
// Test Document.
@@ -147,12 +145,19 @@ struct DocPlus {
return document.FindText(document.Length(), 0, needle.data(), options, length);
}
- Match FindString(Sci::Position minPos, Sci::Position maxPos, const std::string_view needle, FindOption flags) {
+ Match FindString(Sci::Position minPos, Sci::Position maxPos, std::string_view needle, FindOption flags) {
Sci::Position lengthFinding = needle.length();
const Sci::Position location = document.FindText(minPos, maxPos, needle.data(), flags, &lengthFinding);
return { location, lengthFinding };
}
+ std::string Substitute(std::string_view substituteText) {
+ Sci::Position lengthsubstitute = substituteText.length();
+ std::string substituted = document.SubstituteByPosition(substituteText.data(), &lengthsubstitute);
+ assert(lengthsubstitute == static_cast<Sci::Position>(substituted.length()));
+ return substituted;
+ }
+
void MoveGap(Sci::Position gapNew) {
// Move gap to gapNew by inserting
document.InsertString(gapNew, "!", 1);
@@ -169,6 +174,8 @@ TEST_CASE("Document") {
constexpr std::string_view sText = "Scintilla";
constexpr Sci::Position sLength = sText.length();
+ constexpr FindOption rePosix = FindOption::RegExp | FindOption::Posix;
+ constexpr FindOption reCxx11 = FindOption::RegExp | FindOption::Cxx11RegEx;
SECTION("InsertOneLine") {
DocPlus doc("", 0);
@@ -491,58 +498,46 @@ TEST_CASE("Document") {
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
- constexpr std::string_view 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 Sci::Position docLength = doc.document.Length();
+ Match match;
+ constexpr std::string_view finding = R"(\d+(\w+))";
constexpr 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");
+ constexpr std::string_view longest = "\\w+";
+ std::string substituted;
- lengthFinding = finding.length();
- location = doc.FindNeedleReverse(finding, FindOption::RegExp | FindOption::Posix, &lengthFinding);
- REQUIRE(location == 16);
- REQUIRE(lengthFinding == 5);
+ match = doc.FindString(0, docLength, finding, rePosix);
+ REQUIRE(match == Match(5, 5));
+ substituted = doc.Substitute(substituteText);
+ REQUIRE(substituted == "\ta\xCE\x93z\n");
- lengthsubstitute = substituteText.length();
- substituted = doc.document.SubstituteByPosition(substituteText.data(), &lengthsubstitute);
- REQUIRE(lengthsubstitute == 6);
+ match = doc.FindString(docLength, 0, finding, rePosix);
+ REQUIRE(match == Match(16, 5));
+ substituted = doc.Substitute(substituteText);
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);
+ match = doc.FindString(docLength, 0, longest, rePosix);
+ //REQUIRE(match == Match(16, 5));
- lengthsubstitute = substituteText.length();
- substituted = doc.document.SubstituteByPosition(substituteText.data(), &lengthsubstitute);
- REQUIRE(lengthsubstitute == 6);
+ #ifndef NO_CXX11_REGEX
+ match = doc.FindString(0, docLength, finding, reCxx11);
+ REQUIRE(match == Match(5, 5));
+ substituted = doc.Substitute(substituteText);
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);
+ match = doc.FindString(docLength, 0, finding, reCxx11);
+ REQUIRE(match == Match(16, 5));
+ substituted = doc.Substitute(substituteText);
REQUIRE(substituted == "\tb\xCE\x93y\n");
+
+ match = doc.FindString(docLength, 0, longest, reCxx11);
+ REQUIRE(match == Match(16, 5));
#endif
}
SECTION("RegexAssertion") {
DocPlus doc("ab cd ef\r\ngh ij kl", CpUtf8);
const Sci::Position docLength = doc.document.Length();
-
- constexpr FindOption rePosix = FindOption::RegExp | FindOption::Posix;
- constexpr FindOption reCxx11 = FindOption::RegExp | FindOption::Cxx11RegEx;
-
Match match;
constexpr std::string_view findingBOL = "^";