Skip to content

Commit 462695f

Browse files
committed
test: text action and enumerate ts test
1 parent ee72d7a commit 462695f

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

tests/test_text_actions.lua

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- Define helper aliases
2+
local new_set = MiniTest.new_set
3+
local expect, eq = MiniTest.expect, MiniTest.expect.equality
4+
5+
-- Create (but not start) child Neovim object
6+
local child = MiniTest.new_child_neovim()
7+
8+
-- Define main test set of this file
9+
local T = new_set({
10+
-- Register hooks
11+
hooks = {
12+
-- This will be executed before every (even nested) case
13+
pre_case = function()
14+
-- Restart child process with custom 'init.lua' script
15+
child.restart({ "-u", "scripts/minimal_init.lua" })
16+
-- Load tested plugin
17+
child.lua([[require('python').setup()]])
18+
end,
19+
-- This will be executed one after all tests from this set are finished
20+
post_once = child.stop,
21+
},
22+
})
23+
24+
local get_lines = function()
25+
return child.api.nvim_buf_get_lines(0, 0, -1, true)
26+
end
27+
28+
29+
T["text_actions"] = MiniTest.new_set({
30+
hooks = {
31+
pre_case = function()
32+
child.cmd("e _not_existing_new_buffer.py")
33+
end,
34+
},
35+
})
36+
37+
T['text_actions']['insert_f_string'] = function()
38+
child.type_keys("i", [[print("{foo}")]], "<left><esc>")
39+
40+
eq(get_lines(), { [[print(f"{foo}")]] })
41+
end
42+
43+
-- Return test set which will be collected and execute inside `MiniTest.run()`
44+
return T

tests/test_treesitter.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,12 @@ T["wrap_cursor"]["with_selection"] = function()
5656
eq(get_lines(), { [[print("TEST")]] })
5757
end
5858

59+
T["enumerate"] = function()
60+
child.cmd("e _not_existing_new_buffer.py")
61+
child.type_keys("cc", "for i in [1, 2, 3]:", "<Esc>", "0")
62+
child.type_keys([[:Python treesitter toggle_enumerate<cr>]])
63+
eq(get_lines(), { "for idx, i in enumerate([1, 2, 3]):" })
64+
end
65+
5966
-- Return test set which will be collected and execute inside `MiniTest.run()`
6067
return T

0 commit comments

Comments
 (0)