diff options
author | Neil <nyamatongwe@gmail.com> | 2023-10-26 13:44:13 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2023-10-26 13:44:13 +1100 |
commit | 8f42bb51d6445602027d8c68d6c6f225f6536c68 (patch) | |
tree | 076c344e247f686086090738356df63b60f0056d /test | |
parent | fdbb5c9273a8f25f86f4113b837926f883083b23 (diff) | |
download | scintilla-mirror-8f42bb51d6445602027d8c68d6c6f225f6536c68.tar.gz |
Implement LineEnd method in CellBuffer as it is a basic function and only uses
CellBuffer fields.
Declare LineEnd noexcept as it should never throw and that allows methods
calling it to also be noexcept.
Call LineEndPosition to simplify Editor::LineSelectionRange.
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/testCellBuffer.cxx | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/unit/testCellBuffer.cxx b/test/unit/testCellBuffer.cxx index 690611d2f..b44f47735 100644 --- a/test/unit/testCellBuffer.cxx +++ b/test/unit/testCellBuffer.cxx @@ -72,6 +72,58 @@ TEST_CASE("CellBuffer") { REQUIRE(!cb.CanRedo()); } + SECTION("LineEnds") { + // Check that various line ends produce correct result from LineEnd. + cb.SetLineEndTypes(LineEndType::Unicode); + bool startSequence = false; + { + // Unix \n + const char sText2[] = "Two\nLines"; + const Sci::Position sLength2 = static_cast<Sci::Position>(strlen(sText2)); + cb.InsertString(0, sText2, strlen(sText2), startSequence); + REQUIRE(3 == cb.LineEnd(0)); + REQUIRE(sLength2 == cb.LineEnd(1)); + cb.DeleteChars(0, sLength2, startSequence); + } + { + // Windows \r\n + const char sText2[] = "Two\r\nLines"; + const Sci::Position sLength2 = static_cast<Sci::Position>(strlen(sText2)); + cb.InsertString(0, sText2, sLength2, startSequence); + REQUIRE(3 == cb.LineEnd(0)); + REQUIRE(sLength2 == cb.LineEnd(1)); + cb.DeleteChars(0, sLength2, startSequence); + } + { + // Old macOS \r + const char sText2[] = "Two\rLines"; + const Sci::Position sLength2 = static_cast<Sci::Position>(strlen(sText2)); + cb.InsertString(0, sText2, strlen(sText2), startSequence); + REQUIRE(3 == cb.LineEnd(0)); + REQUIRE(sLength2 == cb.LineEnd(1)); + cb.DeleteChars(0, sLength2, startSequence); + } + { + // Unicode NEL is U+0085 \xc2\x85 + const char sText2[] = "Two\xc2\x85Lines"; + const Sci::Position sLength2 = static_cast<Sci::Position>(strlen(sText2)); + cb.InsertString(0, sText2, sLength2, startSequence); + REQUIRE(3 == cb.LineEnd(0)); + REQUIRE(sLength2 == cb.LineEnd(1)); + cb.DeleteChars(0, sLength2, startSequence); + } + { + // Unicode LS line separator is U+2028 \xe2\x80\xa8 + const char sText2[] = "Two\xe2\x80\xa8Lines"; + const Sci::Position sLength2 = static_cast<Sci::Position>(strlen(sText2)); + cb.InsertString(0, sText2, sLength2, startSequence); + REQUIRE(3 == cb.LineEnd(0)); + REQUIRE(sLength2 == cb.LineEnd(1)); + cb.DeleteChars(0, sLength2, startSequence); + } + cb.SetLineEndTypes(LineEndType::Default); + } + SECTION("UndoOff") { REQUIRE(cb.IsCollectingUndo()); cb.SetUndoCollection(false); |