aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/unit/UnitTester.vcxproj3
-rw-r--r--test/unit/makefile3
-rw-r--r--test/unit/test.mak3
-rw-r--r--test/unit/testCharacterCategoryMap.cxx73
-rw-r--r--test/unit/testDocument.cxx59
-rw-r--r--test/unit/testRESearch.cxx77
6 files changed, 218 insertions, 0 deletions
diff --git a/test/unit/UnitTester.vcxproj b/test/unit/UnitTester.vcxproj
index b9b004154..358302321 100644
--- a/test/unit/UnitTester.vcxproj
+++ b/test/unit/UnitTester.vcxproj
@@ -151,10 +151,13 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\CellBuffer.cxx" />
+ <ClCompile Include="..\..\src\CharacterCategoryMap.cxx" />
<ClCompile Include="..\..\src\CharClassify.cxx" />
<ClCompile Include="..\..\src\ContractionState.cxx" />
<ClCompile Include="..\..\src\Decoration.cxx" />
+ <ClCompile Include="..\..\src\Document.cxx" />
<ClCompile Include="..\..\src\PerLine.cxx" />
+ <ClCompile Include="..\..\src\RESearch.cxx" />
<ClCompile Include="..\..\src\RunStyles.cxx" />
<ClCompile Include="..\..\src\UniConversion.cxx" />
<ClCompile Include="..\..\src\UniqueString.cxx" />
diff --git a/test/unit/makefile b/test/unit/makefile
index ab70d0532..ed06e5f93 100644
--- a/test/unit/makefile
+++ b/test/unit/makefile
@@ -50,10 +50,13 @@ TESTSRC=test*.cxx
# Files being tested from scintilla/src directory
TESTEDSRC=\
../../src/CellBuffer.cxx \
+ ../../src/CharacterCategoryMap.cxx \
../../src/CharClassify.cxx \
../../src/ContractionState.cxx \
../../src/Decoration.cxx \
+ ../../src/Document.cxx \
../../src/PerLine.cxx \
+ ../../src/RESearch.cxx \
../../src/RunStyles.cxx \
../../src/UniConversion.cxx \
../../src/UniqueString.cxx
diff --git a/test/unit/test.mak b/test/unit/test.mak
index f9fdab3c8..e9f71619c 100644
--- a/test/unit/test.mak
+++ b/test/unit/test.mak
@@ -13,10 +13,13 @@ TESTSRC=test*.cxx
# Files being tested from scintilla/src directory
TESTEDSRC=\
../../src/CellBuffer.cxx \
+ ../../src/CharacterCategoryMap.cxx \
../../src/CharClassify.cxx \
../../src/ContractionState.cxx \
../../src/Decoration.cxx \
+ ../../src/Document.cxx \
../../src/PerLine.cxx \
+ ../../src/RESearch.cxx \
../../src/RunStyles.cxx \
../../src/UniConversion.cxx \
../../src/UniqueString.cxx
diff --git a/test/unit/testCharacterCategoryMap.cxx b/test/unit/testCharacterCategoryMap.cxx
new file mode 100644
index 000000000..8c5305cc7
--- /dev/null
+++ b/test/unit/testCharacterCategoryMap.cxx
@@ -0,0 +1,73 @@
+/** @file testCharacterCategoryMap.cxx
+ ** Unit Tests for Scintilla internal data structures
+ **/
+
+#include <cstddef>
+#include <cstring>
+#include <stdexcept>
+#include <string_view>
+#include <vector>
+#include <optional>
+#include <algorithm>
+#include <memory>
+
+#include "Debugging.h"
+
+#include "CharacterCategoryMap.h"
+
+#include "catch.hpp"
+
+using namespace Scintilla;
+using namespace Scintilla::Internal;
+
+// Test CharacterCategoryMap.
+
+TEST_CASE("CharacterCategoryMap") {
+
+ CharacterCategoryMap ccm;
+
+ SECTION("LowerCaseLetter") {
+ const CharacterCategory cc = ccm.CategoryFor('a');
+ REQUIRE(cc == CharacterCategory::ccLl);
+ }
+
+ SECTION("All") {
+ REQUIRE(ccm.CategoryFor('A') == CharacterCategory::ccLu);
+ REQUIRE(ccm.CategoryFor('a') == CharacterCategory::ccLl);
+ REQUIRE(ccm.CategoryFor(0x01C5) == CharacterCategory::ccLt);
+ REQUIRE(ccm.CategoryFor(0x0E46) == CharacterCategory::ccLm);
+ REQUIRE(ccm.CategoryFor(0x4E00) == CharacterCategory::ccLo);
+
+ REQUIRE(ccm.CategoryFor(0x0300) == CharacterCategory::ccMn);
+ REQUIRE(ccm.CategoryFor(0x0903) == CharacterCategory::ccMc);
+ REQUIRE(ccm.CategoryFor(0x20E0) == CharacterCategory::ccMe);
+
+ REQUIRE(ccm.CategoryFor('7') == CharacterCategory::ccNd);
+ REQUIRE(ccm.CategoryFor(0x2160) == CharacterCategory::ccNl);
+ REQUIRE(ccm.CategoryFor(0x00BC) == CharacterCategory::ccNo);
+
+ REQUIRE(ccm.CategoryFor('_') == CharacterCategory::ccPc);
+ REQUIRE(ccm.CategoryFor('-') == CharacterCategory::ccPd);
+ REQUIRE(ccm.CategoryFor('(') == CharacterCategory::ccPs);
+ REQUIRE(ccm.CategoryFor('}') == CharacterCategory::ccPe);
+ REQUIRE(ccm.CategoryFor(0x00AB) == CharacterCategory::ccPi);
+ REQUIRE(ccm.CategoryFor(0x00BB) == CharacterCategory::ccPf);
+ REQUIRE(ccm.CategoryFor('"') == CharacterCategory::ccPo);
+
+ REQUIRE(ccm.CategoryFor('+') == CharacterCategory::ccSm);
+ REQUIRE(ccm.CategoryFor('$') == CharacterCategory::ccSc);
+ REQUIRE(ccm.CategoryFor(0x02C2) == CharacterCategory::ccSk);
+ REQUIRE(ccm.CategoryFor(0x00A6) == CharacterCategory::ccSo);
+
+ REQUIRE(ccm.CategoryFor(' ') == CharacterCategory::ccZs);
+ REQUIRE(ccm.CategoryFor(0x2028) == CharacterCategory::ccZl);
+ REQUIRE(ccm.CategoryFor(0x2029) == CharacterCategory::ccZp);
+
+ REQUIRE(ccm.CategoryFor('\n') == CharacterCategory::ccCc);
+ REQUIRE(ccm.CategoryFor(0x00AD) == CharacterCategory::ccCf);
+ REQUIRE(ccm.CategoryFor(0xD800) == CharacterCategory::ccCs);
+ REQUIRE(ccm.CategoryFor(0xE000) == CharacterCategory::ccCo);
+ REQUIRE(ccm.CategoryFor(0xFFFE) == CharacterCategory::ccCn);
+ }
+
+}
diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx
new file mode 100644
index 000000000..983074daf
--- /dev/null
+++ b/test/unit/testDocument.cxx
@@ -0,0 +1,59 @@
+/** @file testDocument.cxx
+ ** Unit Tests for Scintilla internal data structures
+ **/
+
+#include <cstddef>
+#include <cstring>
+#include <stdexcept>
+#include <string_view>
+#include <vector>
+#include <optional>
+#include <algorithm>
+#include <memory>
+
+#include "ScintillaTypes.h"
+
+#include "ILoader.h"
+#include "ILexer.h"
+
+#include "Debugging.h"
+
+#include "CharacterCategoryMap.h"
+#include "Position.h"
+#include "SplitVector.h"
+#include "Partitioning.h"
+#include "RunStyles.h"
+#include "CellBuffer.h"
+#include "CharClassify.h"
+#include "Decoration.h"
+#include "CaseFolder.h"
+#include "Document.h"
+
+#include "catch.hpp"
+
+using namespace Scintilla;
+using namespace Scintilla::Internal;
+
+// Test Document.
+
+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());
+ 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());
+ }
+
+}
diff --git a/test/unit/testRESearch.cxx b/test/unit/testRESearch.cxx
new file mode 100644
index 000000000..0dadc21c4
--- /dev/null
+++ b/test/unit/testRESearch.cxx
@@ -0,0 +1,77 @@
+/** @file testRESearch.cxx
+ ** Unit Tests for Scintilla internal data structures
+ **/
+
+#include <cstddef>
+#include <cstring>
+#include <stdexcept>
+#include <string_view>
+#include <vector>
+#include <optional>
+#include <algorithm>
+#include <memory>
+
+#include "ScintillaTypes.h"
+
+#include "Debugging.h"
+
+#include "Position.h"
+#include "SplitVector.h"
+#include "Partitioning.h"
+#include "RunStyles.h"
+#include "CellBuffer.h"
+#include "CharClassify.h"
+#include "RESearch.h"
+
+#include "catch.hpp"
+
+using namespace Scintilla;
+using namespace Scintilla::Internal;
+
+class StringCI : public CharacterIndexer {
+ std::string s;
+public:
+ StringCI(std::string_view sv_) : s(sv_) {
+ }
+ Sci::Position Length() const noexcept {
+ return s.length();
+ }
+ char CharAt(Sci::Position index) const override {
+ return s.at(index);
+ }
+};
+
+// Test RESearch.
+
+TEST_CASE("RESearch") {
+
+ CharClassify cc;
+ const char sTextSpace[] = "Scintilla ";
+ const char pattern[] = "[a-z]+";
+
+ SECTION("Compile") {
+ std::unique_ptr<RESearch> re = std::make_unique<RESearch>(&cc);
+ const char *msg = re->Compile(pattern, strlen(pattern), true, false);
+ REQUIRE(nullptr == msg);
+ }
+
+ SECTION("Execute") {
+ std::unique_ptr<RESearch> re = std::make_unique<RESearch>(&cc);
+ re->Compile(pattern, strlen(pattern), true, false);
+ StringCI sci(sTextSpace);
+ const int x = re->Execute(sci, 0, sci.Length());
+ REQUIRE(x == 1);
+ REQUIRE(re->bopat[0] == 1);
+ REQUIRE(re->eopat[0] == sci.Length() - 1);
+ }
+
+ SECTION("Grab") {
+ std::unique_ptr<RESearch> re = std::make_unique<RESearch>(&cc);
+ re->Compile(pattern, strlen(pattern), true, false);
+ StringCI sci(sTextSpace);
+ re->Execute(sci, 0, sci.Length());
+ re->GrabMatches(sci);
+ REQUIRE(re->pat[0] == "cintilla");
+ }
+
+}