2021-04-18 18:06:11 +03:00
|
|
|
local npairs = require('nvim-autopairs')
|
2021-10-20 04:36:54 +03:00
|
|
|
local ts = require('nvim-treesitter.configs')
|
2021-04-18 18:06:11 +03:00
|
|
|
local log = require('nvim-autopairs._log')
|
|
|
|
|
2021-10-20 04:36:54 +03:00
|
|
|
ts.setup({
|
|
|
|
ensure_installed = { 'lua' },
|
|
|
|
highlight = { enable = true },
|
|
|
|
})
|
|
|
|
_G.npairs = npairs
|
|
|
|
vim.api.nvim_set_keymap(
|
|
|
|
'i',
|
|
|
|
'<CR>',
|
|
|
|
'v:lua.npairs.autopairs_cr()',
|
|
|
|
{ expr = true, noremap = true }
|
|
|
|
)
|
2021-04-18 18:06:11 +03:00
|
|
|
|
|
|
|
local data = {
|
|
|
|
{
|
2021-10-20 04:36:54 +03:00
|
|
|
name = 'lua function add endwise',
|
|
|
|
filepath = './tests/endwise/init.lua',
|
|
|
|
filetype = 'lua',
|
|
|
|
linenr = 5,
|
|
|
|
key = [[<cr>]],
|
|
|
|
before = [[function a()| ]],
|
|
|
|
after = {
|
|
|
|
[[function a() ]],
|
|
|
|
[[| ]],
|
|
|
|
[[ end ]],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name = 'lua function add endwise',
|
2021-04-18 18:06:11 +03:00
|
|
|
filepath = './tests/endwise/init.lua',
|
2021-10-20 04:36:54 +03:00
|
|
|
filetype = 'lua',
|
|
|
|
linenr = 5,
|
|
|
|
key = [[<cr>]],
|
|
|
|
before = [[function a()|x ab ]],
|
|
|
|
after = {
|
|
|
|
[[function a() ]],
|
|
|
|
[[|x ab]],
|
|
|
|
},
|
2021-07-24 03:09:46 +03:00
|
|
|
},
|
|
|
|
{
|
2021-10-20 04:36:54 +03:00
|
|
|
name = 'add if endwise',
|
2021-07-24 03:09:46 +03:00
|
|
|
filepath = './tests/endwise/init.lua',
|
2021-10-20 04:36:54 +03:00
|
|
|
filetype = 'lua',
|
|
|
|
linenr = 5,
|
|
|
|
key = [[<cr>]],
|
|
|
|
before = [[if data== 'fdsafdsa' then| ]],
|
|
|
|
after = {
|
|
|
|
[[if data== 'fdsafdsa' then ]],
|
|
|
|
[[|]],
|
|
|
|
[[end ]],
|
|
|
|
},
|
2021-04-18 18:06:11 +03:00
|
|
|
},
|
|
|
|
{
|
2021-10-20 04:36:54 +03:00
|
|
|
name = 'undo on<cr> key',
|
2021-04-18 18:06:11 +03:00
|
|
|
filepath = './tests/endwise/init.lua',
|
2021-10-20 04:36:54 +03:00
|
|
|
filetype = 'lua',
|
|
|
|
linenr = 5,
|
|
|
|
key = [[{<cr><esc>uu]],
|
|
|
|
before = [[local abc = | ]],
|
|
|
|
after = {
|
|
|
|
[[local abc = {|} ]],
|
|
|
|
[[]],
|
|
|
|
[[]],
|
|
|
|
},
|
2021-04-18 18:06:11 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-21 07:39:36 +03:00
|
|
|
local run_data = _G.Test_filter(data)
|
2021-04-18 18:06:11 +03:00
|
|
|
|
|
|
|
local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
|
|
|
|
_G.TU = ts_utils
|
|
|
|
|
|
|
|
describe('[endwise tag]', function()
|
2021-10-20 04:36:54 +03:00
|
|
|
_G.Test_withfile(run_data, {
|
|
|
|
-- need to understand this ??? new line make change cursor zzz
|
|
|
|
cursor_add = 1,
|
2021-04-21 07:39:36 +03:00
|
|
|
before = function(value)
|
2021-10-20 04:36:54 +03:00
|
|
|
npairs.add_rules(
|
|
|
|
require('nvim-autopairs.rules.endwise-' .. value.filetype)
|
|
|
|
)
|
|
|
|
end,
|
2021-04-21 07:39:36 +03:00
|
|
|
})
|
2021-04-18 18:06:11 +03:00
|
|
|
end)
|