|
| 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 | + |
| 25 | +local get_lines = function() return child.api.nvim_buf_get_lines(0, 0, -1, true) end |
| 26 | + |
| 27 | +T['wrap_cursor'] = MiniTest.new_set({ |
| 28 | + hooks = { |
| 29 | + pre_case = function() |
| 30 | + child.cmd("e _not_existing_new_buffer.py") |
| 31 | + child.type_keys("cc", [["TEST"]], "<Esc>", "0") |
| 32 | + end, |
| 33 | + } |
| 34 | +}) |
| 35 | + |
| 36 | +T['wrap_cursor']['normal'] = function() |
| 37 | + child.cmd("Python treesitter wrap_cursor test(%s)") |
| 38 | + eq(get_lines(), {[[test("TEST")]]}) |
| 39 | +end |
| 40 | + |
| 41 | +T['wrap_cursor']['visual'] = function() |
| 42 | + child.type_keys("l", "v", "$") |
| 43 | + child.type_keys([[:Python treesitter wrap_cursor test(%s)<cr>]]) |
| 44 | + eq(get_lines(), {[["test(TEST")]]}) |
| 45 | +end |
| 46 | + |
| 47 | +T['wrap_cursor']['visual_with_selection'] = function() |
| 48 | + child.type_keys("l", "v", "$") |
| 49 | + child.type_keys([[:Python treesitter wrap_cursor<cr>1<cr>]]) |
| 50 | + eq(get_lines(), {[["print(TEST")]]}) |
| 51 | +end |
| 52 | + |
| 53 | +T['wrap_cursor']['with_selection'] = function() |
| 54 | + child.type_keys([[:Python treesitter wrap_cursor<cr>1<cr>]]) |
| 55 | + eq(get_lines(), {[[print("TEST")]]}) |
| 56 | +end |
| 57 | + |
| 58 | +-- Return test set which will be collected and execute inside `MiniTest.run()` |
| 59 | +return T |
0 commit comments