From 460aeb76417de8a0aee4b411793eceab92f77617 Mon Sep 17 00:00:00 2001 From: tris203 Date: Sun, 5 May 2024 21:20:10 +0100 Subject: [PATCH] tests: add tests --- .../precognition/horizontal_motions_spec.lua | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/precognition/horizontal_motions_spec.lua b/tests/precognition/horizontal_motions_spec.lua index de992f0..63b1656 100644 --- a/tests/precognition/horizontal_motions_spec.lua +++ b/tests/precognition/horizontal_motions_spec.lua @@ -144,6 +144,52 @@ describe("boundaries", function() end) end) + +describe("matching pair tests", function() + it("if cursor is over a bracket it can find the pair", function() + eq(9, hm.matching_bracket("abc (efg)", 5, 9)) + eq(0, hm.matching_bracket("abc (efg)", 6, 9)) + eq(0, hm.matching_bracket("abc (efg)", 7, 9)) + eq(0, hm.matching_bracket("abc (efg)", 8, 9)) + eq(5, hm.matching_bracket("abc (efg)", 9, 9)) + end) + + it("if cursor is over a square bracket it can find the pair", function() + eq(9, hm.matching_bracket("abc [efg]", 5, 9)) + eq(0, hm.matching_bracket("abc [efg]", 6, 9)) + eq(0, hm.matching_bracket("abc [efg]", 7, 9)) + eq(0, hm.matching_bracket("abc [efg]", 8, 9)) + eq(5, hm.matching_bracket("abc [efg]", 9, 9)) + end) + + it("if cursor is over a curly bracket it can find the pair", function() + eq(9, hm.matching_bracket("abc {efg}", 5, 9)) + eq(0, hm.matching_bracket("abc {efg}", 6, 9)) + eq(0, hm.matching_bracket("abc {efg}", 7, 9)) + eq(0, hm.matching_bracket("abc {efg}", 8, 9)) + eq(5, hm.matching_bracket("abc {efg}", 9, 9)) + end) + + it("nested brackets find the correct pair", function() + eq(19, hm.matching_bracket("abc (efg [hij] klm)", 5, 19)) + eq(0, hm.matching_bracket("abc (efg [hij] klm)", 6, 19)) + eq(14, hm.matching_bracket("abc (efg [hij] klm)", 10, 19)) + eq(10, hm.matching_bracket("abc (efg [hij] klm)", 14, 19)) + eq(0, hm.matching_bracket("abc (efg [hij] klm)", 15, 19)) + eq(5, hm.matching_bracket("abc (efg [hij] klm)", 19, 19)) + end) + + it ("nested brackets of the same type find the correct pair", function() + eq(19, hm.matching_bracket("abc (efg (hij) klm)", 5, 19)) + eq(0, hm.matching_bracket("abc (efg (hij) klm)", 6, 19)) + eq(14, hm.matching_bracket("abc (efg (hij) klm)", 10, 19)) + eq(10, hm.matching_bracket("abc (efg (hij) klm)", 14, 19)) + eq(0, hm.matching_bracket("abc (efg (hij) klm)", 15, 19)) + eq(5, hm.matching_bracket("abc (efg (hij) klm)", 19, 19)) + end) + +end) + describe("edge case", function() it("can handle empty strings", function() eq(0, hm.next_word_boundary("", 1, 0))