diff options
-rw-r--r-- | test/unit/UnitTester.vcxproj | 2 | ||||
-rw-r--r-- | test/unit/makefile | 2 | ||||
-rw-r--r-- | test/unit/test.mak | 2 | ||||
-rw-r--r-- | test/unit/testDocument.cxx | 66 |
4 files changed, 61 insertions, 11 deletions
diff --git a/test/unit/UnitTester.vcxproj b/test/unit/UnitTester.vcxproj index 358302321..2e130ec3d 100644 --- a/test/unit/UnitTester.vcxproj +++ b/test/unit/UnitTester.vcxproj @@ -150,6 +150,8 @@ </Link>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="..\..\src\CaseConvert.cxx" />
+ <ClCompile Include="..\..\src\CaseFolder.cxx" />
<ClCompile Include="..\..\src\CellBuffer.cxx" />
<ClCompile Include="..\..\src\CharacterCategoryMap.cxx" />
<ClCompile Include="..\..\src\CharClassify.cxx" />
diff --git a/test/unit/makefile b/test/unit/makefile index ed06e5f93..1cde6319e 100644 --- a/test/unit/makefile +++ b/test/unit/makefile @@ -49,6 +49,8 @@ CXXFLAGS += -Wall -Wextra TESTSRC=test*.cxx # Files being tested from scintilla/src directory TESTEDSRC=\ + ../../src/CaseConvert.cxx \ + ../../src/CaseFolder.cxx \ ../../src/CellBuffer.cxx \ ../../src/CharacterCategoryMap.cxx \ ../../src/CharClassify.cxx \ diff --git a/test/unit/test.mak b/test/unit/test.mak index e9f71619c..116c6c0d5 100644 --- a/test/unit/test.mak +++ b/test/unit/test.mak @@ -12,6 +12,8 @@ CXXFLAGS = /EHsc /std:c++17 /D_HAS_AUTO_PTR_ETC=1 /wd 4805 $(INCLUDEDIRS) TESTSRC=test*.cxx # Files being tested from scintilla/src directory TESTEDSRC=\ + ../../src/CaseConvert.cxx \ + ../../src/CaseFolder.cxx \ ../../src/CellBuffer.cxx \ ../../src/CharacterCategoryMap.cxx \ ../../src/CharClassify.cxx \ 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); } } |