Skip to content

Commit

Permalink
tests: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed May 5, 2024
1 parent 3fe03eb commit 460aeb7
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/precognition/horizontal_motions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 460aeb7

Please sign in to comment.