aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorZufu Liu <unknown>2022-07-17 13:13:03 +1000
committerZufu Liu <unknown>2022-07-17 13:13:03 +1000
commit4e0683e5531aa99958fc742476b6150ec2595c72 (patch)
tree2fa821d5dced4e0a5e3a28d4d23965c12c73ef67 /test
parente85eee7838814ad178a841527199270e936efd72 (diff)
downloadscintilla-mirror-4e0683e5531aa99958fc742476b6150ec2595c72.tar.gz
Feature [feature-requests:#1442] Added PerLine tests for LineMarkers and
LineAnnotation. Line deletion behaviour could be defined differently but current behaviour was most expected in most circumstances.
Diffstat (limited to 'test')
-rw-r--r--test/unit/testDocument.cxx70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx
index 7f3d9c6bb..3cfb54db4 100644
--- a/test/unit/testDocument.cxx
+++ b/test/unit/testDocument.cxx
@@ -7,6 +7,7 @@
#include <stdexcept>
#include <string_view>
#include <vector>
+#include <set>
#include <optional>
#include <algorithm>
#include <memory>
@@ -601,3 +602,72 @@ TEST_CASE("SafeSegment") {
REQUIRE(text[length] == '\x8c');
}
}
+
+TEST_CASE("PerLine") {
+ SECTION("LineMarkers") {
+ DocPlus doc("1\n2\n", CpUtf8);
+ REQUIRE(doc.document.LinesTotal() == 3);
+ const int mh1 = doc.document.AddMark(0, 0);
+ const int mh2 = doc.document.AddMark(1, 1);
+ const int mh3 = doc.document.AddMark(2, 2);
+ REQUIRE(mh1 != -1);
+ REQUIRE(mh2 != -1);
+ REQUIRE(mh3 != -1);
+ REQUIRE(doc.document.AddMark(3, 3) == -1);
+
+ // delete first character, no change
+ REQUIRE(doc.document.CharAt(0) == '1');
+ doc.document.DeleteChars(0, 1);
+ REQUIRE(doc.document.LinesTotal() == 3);
+ REQUIRE(doc.document.MarkerHandleFromLine(0, 0) == mh1);
+ REQUIRE(doc.document.MarkerHandleFromLine(0, 1) == -1);
+ REQUIRE(doc.document.MarkerHandleFromLine(1, 0) == mh2);
+ REQUIRE(doc.document.MarkerHandleFromLine(1, 1) == -1);
+
+ // delete first line, so merged
+ REQUIRE(doc.document.CharAt(0) == '\n');
+ doc.document.DeleteChars(0, 1);
+ REQUIRE(doc.document.CharAt(0) == '2');
+ const std::set handleSet {mh1, mh2};
+ const int handle1 = doc.document.MarkerHandleFromLine(0, 0);
+ const int handle2 = doc.document.MarkerHandleFromLine(0, 1);
+ REQUIRE(handle1 != handle2);
+ REQUIRE(handleSet.count(handle1) == 1);
+ REQUIRE(handleSet.count(handle2) == 1);
+ REQUIRE(doc.document.MarkerHandleFromLine(0, 2) == -1);
+ REQUIRE(doc.document.MarkerHandleFromLine(1, 0) == mh3);
+ REQUIRE(doc.document.MarkerHandleFromLine(1, 1) == -1);
+ }
+
+ SECTION("LineAnnotation") {
+ DocPlus doc("1\n2\n", CpUtf8);
+ REQUIRE(doc.document.LinesTotal() == 3);
+ Sci::Position length = doc.document.Length();
+ doc.document.AnnotationSetText(0, "1");
+ doc.document.AnnotationSetText(1, "1\n2");
+ doc.document.AnnotationSetText(2, "1\n2\n3");
+ REQUIRE(doc.document.AnnotationLines(0) == 1);
+ REQUIRE(doc.document.AnnotationLines(1) == 2);
+ REQUIRE(doc.document.AnnotationLines(2) == 3);
+ REQUIRE(doc.document.AnnotationLines(3) == 0);
+
+ // delete last line
+ length -= 1;
+ doc.document.DeleteChars(length, 1);
+ // Deleting the last line moves its 3-line annotation to previous line,
+ // deleting the 2-line annotation of the previous line.
+ REQUIRE(doc.document.LinesTotal() == 2);
+ REQUIRE(doc.document.AnnotationLines(0) == 1);
+ REQUIRE(doc.document.AnnotationLines(1) == 3);
+ REQUIRE(doc.document.AnnotationLines(2) == 0);
+
+ // delete last character, no change
+ length -= 1;
+ REQUIRE(doc.document.CharAt(length) == '2');
+ doc.document.DeleteChars(length, 1);
+ REQUIRE(doc.document.LinesTotal() == 2);
+ REQUIRE(doc.document.AnnotationLines(0) == 1);
+ REQUIRE(doc.document.AnnotationLines(1) == 3);
+ REQUIRE(doc.document.AnnotationLines(2) == 0);
+ }
+}