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))