aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/unit/testDocument.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-07-01 09:01:22 +1000
committerNeil <nyamatongwe@gmail.com>2021-07-01 09:01:22 +1000
commit12dabace25a229d74db880473ecb7a5081bc65b9 (patch)
tree5cc729f899f3c18da26b2acf3fa347352a0e01e5 /test/unit/testDocument.cxx
parent3a8326c2b1e58da085bc363c060d6aa5ce3727b3 (diff)
downloadscintilla-mirror-12dabace25a229d74db880473ecb7a5081bc65b9.tar.gz
Add searching test cases for multi-byte encoding
Diffstat (limited to 'test/unit/testDocument.cxx')
-rw-r--r--test/unit/testDocument.cxx66
1 files changed, 55 insertions, 11 deletions
diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx
index 983074daf..14d5fc22f 100644
--- a/test/unit/testDocument.cxx
+++ b/test/unit/testDocument.cxx
@@ -36,24 +36,68 @@ using namespace Scintilla::Internal;
// Test Document.
+struct DocPlus {
+ Document document;
+
+ DocPlus(std::string_view svInitial, int codePage) : document(DocumentOption::Default) {
+ document.SetDBCSCodePage(codePage);
+ if (codePage == CpUtf8) {
+ document.SetCaseFolder(std::make_unique<CaseFolderUnicode>());
+ } else {
+ // This case folder will not handle many DBCS cases. Scintilla uses platform-specific code for DBCS
+ // case folding which can not easily be inserted in platform-independent tests.
+ std::unique_ptr<CaseFolderTable> pcft = std::make_unique<CaseFolderTable>();
+ pcft->StandardASCII();
+ document.SetCaseFolder(std::move(pcft));
+ }
+ document.InsertString(0, svInitial.data(), svInitial.length());
+ }
+
+};
+
TEST_CASE("Document") {
const char sText[] = "Scintilla";
const Sci::Position sLength = static_cast<Sci::Position>(strlen(sText));
- Document doc(DocumentOption::Default);
-
SECTION("InsertOneLine") {
- const Sci::Position length = doc.InsertString(0, sText, sLength);
- REQUIRE(sLength == doc.Length());
+ DocPlus doc("", 0);
+ const Sci::Position length = doc.document.InsertString(0, sText, sLength);
+ REQUIRE(sLength == doc.document.Length());
REQUIRE(length == sLength);
- REQUIRE(1 == doc.LinesTotal());
- REQUIRE(0 == doc.LineStart(0));
- REQUIRE(0 == doc.LineFromPosition(0));
- REQUIRE(sLength == doc.LineStart(1));
- REQUIRE(0 == doc.LineFromPosition(static_cast<int>(sLength)));
- REQUIRE(doc.CanUndo());
- REQUIRE(!doc.CanRedo());
+ REQUIRE(1 == doc.document.LinesTotal());
+ REQUIRE(0 == doc.document.LineStart(0));
+ REQUIRE(0 == doc.document.LineFromPosition(0));
+ REQUIRE(sLength == doc.document.LineStart(1));
+ REQUIRE(0 == doc.document.LineFromPosition(static_cast<int>(sLength)));
+ REQUIRE(doc.document.CanUndo());
+ REQUIRE(!doc.document.CanRedo());
+ }
+
+ SECTION("SearchInUTF8") {
+ DocPlus doc("ab\xCE\x93" "d", CpUtf8); // a b gamma d
+ std::string finding = "b";
+ Sci::Position lengthFinding = finding.length();
+ Sci::Position location = doc.document.FindText(0, doc.document.Length(), finding.c_str(), FindOption::MatchCase, &lengthFinding);
+ REQUIRE(location == 1);
+ location = doc.document.FindText(doc.document.Length(), 0, finding.c_str(), FindOption::MatchCase, &lengthFinding);
+ REQUIRE(location == 1);
+ }
+
+ SECTION("SearchInShiftJIS") {
+ // {CJK UNIFIED IDEOGRAPH-9955} is two bytes: {0xE9, 'b'} in Shift-JIS
+ // The 'b' can be incorrectly matched by the search string 'b' when the search
+ // does not iterate the text correctly.
+ DocPlus doc("ab\xe9" "b ", 932); // a b {CJK UNIFIED IDEOGRAPH-9955} {space}
+ std::string finding = "b";
+ // Search forwards
+ Sci::Position lengthFinding = finding.length();
+ Sci::Position location = doc.document.FindText(0, doc.document.Length(), finding.c_str(), FindOption::MatchCase, &lengthFinding);
+ REQUIRE(location == 1);
+ // Search backwards
+ lengthFinding = finding.length();
+ location = doc.document.FindText(doc.document.Length(), 0, finding.c_str(), FindOption::MatchCase, &lengthFinding);
+ REQUIRE(location == 1);
}
}