-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle_spec.lua
More file actions
53 lines (47 loc) · 1.69 KB
/
toggle_spec.lua
File metadata and controls
53 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local toggle = require('toggle')
local function open_file_at(file_to_open, row, column, callback)
local full_path = vim.fs.joinpath(vim.fn.getcwd(), file_to_open)
vim.api.nvim_command('edit ' .. full_path)
vim.api.nvim_win_set_cursor(0, { row, column })
callback()
vim.cmd(':bd!')
end
local function get_character_under_cursor()
local coords = vim.api.nvim_win_get_cursor(0)
local line = vim.api.nvim_get_current_line()
return line:sub(coords[2] + 1, coords[2] + 1)
end
describe('toggle', function()
it('toggle - cword', function()
open_file_at('test/test_files/test_1.txt', 1, 1, function()
toggle.toggle()
assert(vim.fn.expand('<cword>') == 'true')
toggle.toggle()
assert(vim.fn.expand('<cword>') == 'false')
end)
end)
it('toggle - cWORD', function()
open_file_at('test/test_files/test_1.txt', 2, 1, function()
toggle.toggle()
assert(vim.fn.expand('<cword>') == 'true')
toggle.toggle()
assert(vim.fn.expand('<cword>') == 'false')
end)
end)
it('toggle - char', function()
open_file_at('test/test_files/test_1.txt', 3, 1, function()
toggle.toggle()
assert(get_character_under_cursor() == '>')
toggle.toggle()
assert(get_character_under_cursor() == '<')
end)
end)
it('toggle - end of word', function()
open_file_at('test/test_files/test_1.txt', 4, 5, function()
toggle.toggle()
assert(vim.fn.expand('<cword>') == 'goto_next')
toggle.toggle()
assert(vim.fn.expand('<cword>') == 'goto_prev')
end)
end)
end)