From 7d69a0041a965406464f61b6ebb5da18a10d7c83 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Sat, 30 Nov 2024 13:13:49 +1100 Subject: Feature [feature-requests:#1533]. Tests for BraceMatch. --- test/unit/testDocument.cxx | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test') diff --git a/test/unit/testDocument.cxx b/test/unit/testDocument.cxx index a80e83a3f..c4985f330 100644 --- a/test/unit/testDocument.cxx +++ b/test/unit/testDocument.cxx @@ -729,6 +729,55 @@ TEST_CASE("Document") { REQUIRE(substituted == "\ta\n"); } + SECTION("BraceMatch") { + DocPlus doc("{}(()())[]", CpUtf8); + constexpr Sci::Position maxReStyle = 0; // unused parameter + Sci::Position pos = doc.document.BraceMatch(0, maxReStyle, 0, false); + REQUIRE(pos == 1); + pos = doc.document.BraceMatch(1, maxReStyle, 0, false); + REQUIRE(pos == 0); + pos = doc.document.BraceMatch(8, maxReStyle, 0, false); + REQUIRE(pos == 9); + pos = doc.document.BraceMatch(9, maxReStyle, 0, false); + REQUIRE(pos == 8); + pos = doc.document.BraceMatch(2, maxReStyle, 0, false); + REQUIRE(pos == 7); + pos = doc.document.BraceMatch(7, maxReStyle, 0, false); + REQUIRE(pos == 2); + + // BraceMatchNext() + pos = doc.document.BraceMatch(2, maxReStyle, 3, true); + REQUIRE(pos == 7); + pos = doc.document.BraceMatch(2, maxReStyle, 4, true); + REQUIRE(pos == 4); + pos = doc.document.BraceMatch(2, maxReStyle, 5, true); + REQUIRE(pos == 7); + pos = doc.document.BraceMatch(2, maxReStyle, 6, true); + REQUIRE(pos == 6); + pos = doc.document.BraceMatch(2, maxReStyle, 7, true); + REQUIRE(pos == 7); + + pos = doc.document.BraceMatch(7, maxReStyle, 6, true); + REQUIRE(pos == 2); + pos = doc.document.BraceMatch(7, maxReStyle, 5, true); + REQUIRE(pos == 5); + pos = doc.document.BraceMatch(7, maxReStyle, 4, true); + REQUIRE(pos == 2); + pos = doc.document.BraceMatch(7, maxReStyle, 3, true); + REQUIRE(pos == 3); + pos = doc.document.BraceMatch(7, maxReStyle, 2, true); + REQUIRE(pos == 2); + } + + SECTION("BraceMatch DBCS") { + DocPlus doc("{\x81}\x81{}", 932); // { U+00B1 U+FF0B } + constexpr Sci::Position maxReStyle = 0; // unused parameter + Sci::Position pos = doc.document.BraceMatch(0, maxReStyle, 0, false); + REQUIRE(pos == 5); + pos = doc.document.BraceMatch(5, maxReStyle, 0, false); + REQUIRE(pos == 0); + } + } TEST_CASE("DocumentUndo") { -- cgit v1.2.3