Skip to content

Commit

Permalink
fix: edge cases around special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed May 2, 2024
1 parent be3f69d commit a8a4308
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
5 changes: 4 additions & 1 deletion lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ local function end_of_word(str, start)
char_class(vim.fn.strcharpart(str, (offset - 1) + 1, 1))
local rev_offset

if c_class == 1 and next_char_class ~= 1 then
if
(c_class == 1 and next_char_class ~= 1)
or (next_char_class == 1 and c_class ~= 1)
then
offset = offset + 1
char = vim.fn.strcharpart(str, offset - 1, 1)
c_class = char_class(char)
Expand Down
45 changes: 30 additions & 15 deletions tests/precognition/char_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,20 @@ describe("boundaries", function()
6
)
)
-- eq(
-- 5,
-- precognition.prev_word_boundary(
-- " myFunction(example, stuff)",
-- 16
-- )
-- )
eq(
5,
precognition.prev_word_boundary(
" myFunction(example, stuff)",
15
)
)
eq(
15,
precognition.prev_word_boundary(
" myFunction(example, stuff)",
16
)
)
eq(
16,
precognition.prev_word_boundary(
Expand Down Expand Up @@ -260,9 +267,13 @@ describe("boundaries", function()
29
)
)
--TODO: This isnt right, it should ne 25, but i dont know the rules
--there is something odd if there is only one class 2 under the cursor
-- eq(25, precognition.prev_word_boundary(" myFunction(example, stuff)", 30))
eq(
25,
precognition.prev_word_boundary(
" myFunction(example, stuff)",
30
)
)
end)

it("can walk string with b", function()
Expand Down Expand Up @@ -307,10 +318,14 @@ describe("boundaries", function()
14,
precognition.end_of_word(" myFunction(example, stuff)", 5)
)
--TODO: These next two dont work either for the same reason as the previous
--something to do with the bracket being under the cursor
-- eq(15, precognition.end_of_word(" myFunction(example, stuff)", 14))
-- eq(22, precognition.end_of_word(" myFunction(example, stuff)", 15))
eq(
15,
precognition.end_of_word(" myFunction(example, stuff)", 14)
)
eq(
22,
precognition.end_of_word(" myFunction(example, stuff)", 15)
)
eq(
22,
precognition.end_of_word(" myFunction(example, stuff)", 16)
Expand All @@ -328,7 +343,7 @@ describe("boundaries", function()
precognition.end_of_word(" myFunction(example, stuff)", 25)
)
eq(
29,
30,
precognition.end_of_word(" myFunction(example, stuff)", 29)
)
eq(
Expand Down

0 comments on commit a8a4308

Please sign in to comment.