1

Regenerate nvim config

This commit is contained in:
2024-06-02 03:29:20 +02:00
parent 75eea0c030
commit ef2e28883d
5576 changed files with 604886 additions and 503 deletions

View File

@ -0,0 +1,99 @@
local npairs = require('nvim-autopairs')
_G.npairs = npairs
npairs.setup({
enable_afterquote = true,
})
local data = {
{
name = 'add bracket after quote ',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[(]],
before = [[const abc=|"test" ]],
after = [[const abc=(|"test") ]],
},
{
name = 'add bracket after quote ',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[(]],
before = [[|"test"]],
after = [[(|"test")]],
},
{
name = 'check quote without any text on end similar',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[(]],
before = [[ const [template, setTemplate] = useState|'')]],
after = [[ const [template, setTemplate] = useState(|'')]],
},
{
name = 'add bracket after quote ',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[{]],
before = [[(|"test") ]],
after = [[({|"test"}) ]],
},
{
name = 'add bracket after quote ',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[(]],
before = [[const abc=|"visu\"dsa" ]],
after = [[const abc=(|"visu\"dsa") ]],
},
{
name = 'not add on exist quote',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[(]],
before = [[const abc=|"visu\"dsa") ]],
after = [[const abc=(|"visu\"dsa") ]],
},
{
name = 'test add close quote on match',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[(]],
before = [[const abc=|"visu\"dsa" ]],
after = [[const abc=(|"visu\"dsa") ]],
},
{
name = 'not add bracket with quote have comma',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[(]],
before = [[|"data", abcdef]],
after = [[(|"data", abcdef]],
},
{
name = 'not add bracket with quote have comma',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[(]],
before = [[|"data", "abcdef"]],
after = { [[(|"data", "abcdef"]] },
},
}
local run_data = _G.Test_filter(data)
describe('[afterquote tag]', function()
_G.Test_withfile(run_data, {})
end)

View File

@ -0,0 +1,22 @@
local data1, data2
local function wind()
vim.api.nvim_get_current_buf()
end

View File

@ -0,0 +1,15 @@
fn main() {
}

View File

@ -0,0 +1,4 @@
module MyFirstModule
end

View File

@ -0,0 +1,18 @@
local M={}
M.autopairs_bs = function(rules)
for _, rule in pairs(rules) do
if rule.start_pair then
end
if rule.start_pair then
end
end
end
return M

View File

@ -0,0 +1,9 @@
# Example Markdown File
```javascript
let;
let;
let;
let;
let;
```

View File

@ -0,0 +1,83 @@
local npairs = require('nvim-autopairs')
local ts = require('nvim-treesitter.configs')
local log = require('nvim-autopairs._log')
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 }
)
local data = {
{
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',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[<cr>]],
before = [[function a()|x ab ]],
after = {
[[function a() ]],
[[|x ab]],
},
},
{
name = 'add if endwise',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[<cr>]],
before = [[if data== 'fdsafdsa' then| ]],
after = {
[[if data== 'fdsafdsa' then ]],
[[|]],
[[end ]],
},
},
{
name = 'undo on<cr> key',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[{<cr><esc>u]],
before = [[local abc = | ]],
after = {
[[local abc = {|} ]],
[[]],
[[]],
},
},
}
local run_data = _G.Test_filter(data)
describe('[endwise tag]', function()
_G.Test_withfile(run_data, {
-- need to understand this ??? new line make change cursor zzz
cursor_add = 1,
before_each = function(value)
npairs.add_rules(
require('nvim-autopairs.rules.endwise-' .. value.filetype)
)
end,
})
end)

View File

@ -0,0 +1,53 @@
-- local npairs = require('nvim-autopairs')
-- _G.npairs = npairs
-- npairs.setup({
-- enable_afterquote = true,
-- fast_wrap = true,
-- })
-- local data = {
-- {
-- only = true,
-- name = 'move end wise after quote ',
-- filepath = './tests/endwise/init.lua',
-- filetype = 'lua',
-- linenr = 5,
-- key = [[<M-e>]],
-- before = [[const abc=(|"test",data ]],
-- after = [[const abc=(|"test"),data ]],
-- },
-- {
-- name = 'move end wise after quote ',
-- filepath = './tests/endwise/init.lua',
-- filetype = 'lua',
-- linenr = 5,
-- key = [[<M-e>]],
-- before = [[const abc=(|"test"),data ]],
-- after = [[const abc=(|"test",data) ]],
-- },
-- {
-- name = 'move end wise after quote ',
-- filepath = './tests/endwise/init.lua',
-- filetype = 'lua',
-- linenr = 5,
-- key = [[<M-e>]],
-- before = [[const abc=(|"test",data),dadas ]],
-- after = [[const abc=(|"test",data,dadas) ]],
-- },
-- {
-- name = 'move end wise after quote ',
-- filepath = './tests/endwise/init.lua',
-- filetype = 'lua',
-- linenr = 5,
-- key = [[<M-e>]],
-- before = [[Plug {(|'dsfdsa',) on = 'aaa'} ]],
-- after = [[Plug {('dsfdsa', on = 'aaa')} ]],
-- },
-- }
-- local run_data = _G.Test_filter(data)
-- describe('[endwise tag]', function()
-- _G.Test_withfile(run_data, {})
-- end)

View File

@ -0,0 +1,30 @@
set rtp +=.
set rtp +=../plenary.nvim/
set rtp +=../nvim-treesitter
set rtp +=../playground/
lua _G.__is_log = true
lua vim.fn.setenv("DEBUG_PLENARY", true)
runtime! plugin/plenary.vim
runtime! plugin/nvim-treesitter.vim
runtime! plugin/playground.vim
runtime! plugin/nvim-autopairs.vim
set noswapfile
set nobackup
filetype indent off
set expandtab
set shiftwidth=4
set nowritebackup
set noautoindent
set nocindent
set nosmartindent
set indentexpr=
lua << EOF
require("plenary/busted")
require("nvim-treesitter").setup()
vim.cmd[[luafile ./tests/test_utils.lua]]
require("nvim-autopairs").setup()
EOF

View File

@ -0,0 +1,838 @@
local npairs = require('nvim-autopairs')
local Rule = require('nvim-autopairs.rule')
local cond = require('nvim-autopairs.conds')
local log = require('nvim-autopairs._log')
_G.log = log
local utils = require('nvim-autopairs.utils')
_G.npairs = npairs;
-- use only = true to test 1 case
-- stylua: ignore
local data = {
{
-- only = true,
name = "1 add normal bracket",
key = [[{]],
before = [[x| ]],
after = [[x{|} ]]
},
{
name = "2 add bracket inside bracket",
key = [[{]],
before = [[{|} ]],
after = [[{{|}} ]]
},
{
name = "3 test single quote ",
filetype = "lua",
key = "'",
before = [[data,|) ]],
after = [[data,'|') ]]
},
{
name = "4 add normal bracket",
key = [[(]],
before = [[aaaa| x ]],
after = [[aaaa(|) x ]]
},
{
name = "5 add normal quote",
key = [["]],
before = [[aa| aa]],
after = [[aa"|" aa]]
},
{
name = "6 add python quote",
filetype = "python",
key = [["]],
before = [[""| ]],
after = [["""|""" ]]
},
{
name = "7 don't repeat python quote",
filetype = "python",
key = [["]],
before = [[a"""|""" ]],
after = [[a""""|"" ]]
},
{
name = "8 add markdown quote",
filetype = "markdown",
key = [[`]],
before = [[``| ]],
after = [[```|``` ]]
},
{
name = "9 don't add single quote with previous alphabet char",
key = [[']],
before = [[aa| aa ]],
after = [[aa'| aa ]]
},
{
name = "10 don't add single quote with alphabet char",
key = [[']],
before = [[a|x ]],
after = [[a'|x ]]
},
{
name = "11 don't add single quote on end line",
key = [[<right>']],
before = [[c aa|]],
after = [[c aa'|]]
},
{
name = "12 don't add quote after alphabet char",
key = [["]],
before = [[aa |aa]],
after = [[aa "|aa]]
},
{
name = "13 don't add quote inside quote",
key = [["]],
before = [["aa | aa]],
after = [["aa "| aa]]
},
{
name = "14 add quote if not inside quote",
key = [["]],
before = [["aa " | aa]],
after = [["aa " "|" aa]]
},
{
name = "15 don't add pair after alphabet char",
key = [[(]],
before = [[aa |aa]],
after = [[aa (|aa]]
},
{
name = "16 don't add pair after dot char",
key = [[(]],
before = [[aa |.aa]],
after = [[aa (|.aa]]
},
{
name = "17 don't add bracket have open bracket in same line",
key = [[(]],
before = [[( many char |))]],
after = [[( many char (|))]]
},
{
filetype = 'vim',
name = "18 add bracket inside quote when nextchar is ignore",
key = [[{]],
before = [["|"]],
after = [["{|}"]]
},
{
filetype = '',
name = "19 add bracket inside quote when next char is ignore",
key = [[{]],
before = [[" |"]],
after = [[" {|}"]]
},
{
name = "20 move right on quote line ",
key = [["]],
before = [["|"]],
after = [[""|]]
},
{
name = "21 move right end line ",
key = [["]],
before = [[aaaa|"]],
after = [[aaaa"|]]
},
{
name = "22 move right when inside quote",
key = [["]],
before = [[("abcd|")]],
after = [[("abcd"|)]]
},
{
name = "23 move right when inside quote",
key = [["]],
before = [[foo("|")]],
after = [[foo(""|)]]
},
{
name = "24 move right square bracket",
key = [[)]],
before = [[("abcd|) ]],
after = [[("abcd)| ]]
},
{
name = "25 move right bracket",
key = [[}]],
before = [[("abcd|}} ]],
after = [[("abcd}|} ]]
},
{
-- ref: issue #331
name = "26 move right, should not move on non-end-pair char: `§|§` with (",
setup_func = function()
npairs.add_rule(Rule("§", "§"):with_move(cond.done()))
end,
key = [[(]],
before = [[§|§]],
after = [[§(|)§]]
},
{
-- ref: issue #331
name = "27 move right, should not move on non-end-pair char: `#|#` with \"",
setup_func = function()
npairs.add_rule(Rule("#", "#"):with_move(cond.done()))
end,
key = [["]],
before = [[#|#]],
after = [[#"|"#]]
},
{
-- ref: issue #331 and #330
name = "28 move right, should not move on non-end-pair char: `<|>` with (",
setup_func = function()
npairs.add_rule(Rule("<", ">"):with_move(cond.done()))
end,
key = [[(]],
before = [[<|>]],
after = [[<(|)>]],
},
{
name = "29 move right when inside grave with special slash",
key = [[`]],
before = [[(`abcd\"|`)]],
after = [[(`abcd\"`|)]]
},
{
name = "30 move right when inside quote with special slash",
key = [["]],
before = [[("abcd\"|")]],
after = [[("abcd\""|)]]
},
{
filetype = 'rust',
name = "31 move right double quote after single quote",
key = [["]],
before = [[ ('x').expect("|");]],
after = [[ ('x').expect(""|);]],
},
{
filetype = 'rust',
name = "32 move right, should not move when bracket not closing",
key = [[}]],
before = [[{{ |} ]],
after = [[{{ }|} ]]
},
{
filetype = 'rust',
name = "33 move right, should move when bracket closing",
key = [[}]],
before = [[{ }|} ]],
after = [[{ }}| ]]
},
{
name = "34 delete bracket",
filetype = "javascript",
key = [[<bs>]],
before = [[aaa(|) ]],
after = [[aaa| ]]
},
{
name = "35 breakline on {",
filetype = "javascript",
key = [[<cr>]],
before = [[a{|}]],
after = {
"a{",
"|",
"}"
}
},
{
setup_func = function()
vim.opt.indentexpr = "nvim_treesitter#indent()"
end,
name = "36 breakline on (",
filetype = "javascript",
key = [[<cr>]],
before = [[function ab(|)]],
after = {
"function ab(",
"|",
")"
}
},
{
name = "37 breakline on ]",
filetype = "javascript",
key = [[<cr>]],
before = [[a[|] ]],
after = {
"a[",
"|",
"]"
}
},
{
name = "38 move ) inside nested function call",
filetype = "javascript",
key = [[)]],
before = {
"fn(fn(|))",
},
after = {
"fn(fn()|)",
}
},
{
name = "39 move } inside singleline function's params",
filetype = "javascript",
key = [[}]],
before = {
"({|}) => {}",
},
after = {
"({}|) => {}",
}
},
{
name = "40 move } inside multiline function's params",
filetype = "javascript",
key = [[}]],
before = {
"({|}) => {",
"",
"}",
},
after = {
"({}|) => {",
"",
"}",
}
},
{
name = "41 breakline on markdown ",
filetype = "markdown",
key = [[<cr>]],
before = [[``` lua|```]],
after = {
[[``` lua]],
[[|]],
[[```]]
}
},
{
name = "42 breakline on < html",
filetype = "html",
key = [[<cr>]],
before = [[<div>|</div>]],
after = {
[[<div>]],
[[|]],
[[</div>]]
}
},
{
name = "43 breakline on < html with text",
filetype = "html",
key = [[<cr>]],
before = [[<div> ads |</div>]],
after = {
[[<div> ads]],
[[|]],
[[</div>]]
},
},
{
name = "44 breakline on < html with space after cursor",
filetype = "html",
key = [[<cr>]],
before = [[<div> ads | </div>]],
after = {
[[<div> ads]],
[[|]],
[[</div>]]
},
},
{
name = "45 do not mapping on > html",
filetype = "html",
key = [[>]],
before = [[<div| ]],
after = [[<div>| ]]
},
{
name = "46 press multiple key",
filetype = "html",
key = [[((((]],
before = [[a| ]],
after = [[a((((|)))) ]]
},
{
setup_func = function()
npairs.add_rules({
Rule('u%d%d%d%d$', 'number', 'lua'):use_regex(true),
})
end,
name = "47 text regex",
filetype = "lua",
key = "4",
before = [[u123| ]],
after = [[u1234|number ]]
},
{
setup_func = function()
npairs.add_rules({
Rule('x%d%d%d%d$', 'number', 'lua'):use_regex(true):replace_endpair(function(opts)
return opts.prev_char:sub(#opts.prev_char - 3, #opts.prev_char)
end),
})
end,
name = "48 text regex with custom end_pair",
filetype = "lua",
key = "4",
before = [[x123| ]],
after = [[x1234|1234 ]]
},
{
setup_func = function()
npairs.add_rules({
Rule('b%d%d%d%d%w$', '', 'vim'):use_regex(true, '<tab>'):replace_endpair(function(opts)
return opts.prev_char:sub(#opts.prev_char - 4, #opts.prev_char) .. '<esc>viwUi'
end),
})
end,
name = "49 text regex with custom key",
filetype = "vim",
key = "<tab>",
before = [[b1234s| ]],
after = [[B|1234S1234S ]]
},
{
setup_func = function()
npairs.add_rules({
Rule('b%d%d%d%d%w$', '', 'vim'):use_regex(true, '<tab>'):replace_endpair(function(opts)
return opts.prev_char:sub(#opts.prev_char - 4, #opts.prev_char) .. '<esc>viwUi'
end),
})
end,
name = "50 test move right custom char",
filetype = "vim",
key = "<tab>",
before = [[b1234s| ]],
after = [[B|1234S1234S ]]
},
{
setup_func = function()
npairs.add_rules({
Rule("-", "+", "vim")
:with_move(function(opt)
return utils.get_prev_char(opt) == "x"
end)
:with_move(cond.done())
})
end,
name = "51 test move right custom char plus",
filetype = "vim",
key = "+",
before = [[x|+ ]],
after = [[x+| ]]
},
{
setup_func = function()
npairs.add_rules({
Rule("/**", "**/", "javascript")
:with_move(cond.none())
})
end,
name = "52 test javascript comment",
filetype = "javascript",
key = "*",
before = [[/*| ]],
after = [[/**|**/ ]]
},
{
setup_func = function()
npairs.add_rules({
Rule("(", ")")
:use_key("<c-h>")
:replace_endpair(function() return "<bs><del>" end, true)
})
end,
name = "53 test map custom key",
filetype = "latex",
key = [[<c-h>]],
before = [[ abcde(|) ]],
after = [[ abcde| ]],
},
{
setup_func = function()
npairs.add_rules {
Rule(' ', ' '):with_pair(function(opts)
local pair = opts.line:sub(opts.col, opts.col + 1)
return vim.tbl_contains({ '()', '[]', '{}' }, pair)
end),
Rule('( ', ' )')
:with_pair(function() return false end)
:with_del(function() return false end)
:with_move(function() return true end)
:use_regex(false, ")")
}
end,
name = "54 test multiple move right",
filetype = "latex",
key = [[)]],
before = [[( | ) ]],
after = [[( )| ]],
},
{
setup_func = function()
npairs.setup({
enable_check_bracket_line = false
})
end,
name = "55 test disable check bracket line",
filetype = "latex",
key = [[(]],
before = [[(|))) ]],
after = [[((|)))) ]],
},
{
setup_func = function()
npairs.add_rules({
Rule("<", ">", { "rust" })
:with_pair(cond.before_text("Vec"))
})
end,
name = "56 test disable check bracket line",
filetype = "rust",
key = [[<]],
before = [[Vec| ]],
after = [[Vec<|> ]],
},
{
setup_func = function()
npairs.add_rule(Rule("!", "!"):with_pair(cond.not_filetypes({ "lua" })))
end,
name = "57 disable pairs in lua",
filetype = "lua",
key = "!",
before = [[x| ]],
after = [[x!| ]]
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rules({
Rule("%(.*%)%s*%=>", " { }", { "typescript", "typescriptreact", "javascript" })
:use_regex(true)
:set_end_pair_length(2)
})
end,
name = "58 mapping regex with custom end_pair_length",
filetype = "typescript",
key = ">",
before = [[(o)=| ]],
after = [[(o)=> { | } ]]
},
{
setup_func = function()
npairs.add_rules({
Rule('(', ')'):use_key('<c-w>'):replace_endpair(function()
return '<bs><del><del><del>'
end, true),
Rule('(', ')'):use_key('<c-h>'):replace_endpair(function()
return '<bs><del>'
end, true),
})
end,
name = "59 mapping same pair with different key",
filetype = "typescript",
key = "(",
before = [[(test|) ]],
after = [[(test(|)) ]]
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rule(Rule("", ""))
end,
name = "60 multibyte character from custom keyboard",
not_replace_term_code = true,
key = "",
before = [[a | ]],
after = [[a „|” ]],
end_cursor = 3
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rule(Rule("", ""):with_move(cond.done()))
end,
name = "61 multibyte character move_right",
not_replace_term_code = true,
key = "",
before = [[a „|”xx ]],
after = [[a „”|xx ]],
end_cursor = 6
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rule(Rule("", ""):with_move(cond.done()))
end,
name = "62 multibyte character delete",
key = "<bs>",
before = [[a „|” ]],
after = [[a | ]],
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rule(Rule("a„", "”b"):with_move(cond.done()))
end,
not_replace_term_code = true,
name = "63 multibyte character and multiple ",
key = "",
before = [[a| ]],
after = [[a„|”b ]],
end_cursor = 2
},
{
setup_func = function()
npairs.setup({ map_c_h = true })
end,
name = "64 map <c-h>",
key = "<c-h>",
before = [[aa'|' ]],
after = [[aa| ]],
},
{
setup_func = function()
npairs.setup({
map_c_w = true
})
end,
name = "65 map <c-w>",
key = "<c-w>",
before = [[aa'|' ]],
after = [[aa| ]],
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rule(Rule("x", "x", { '-vim', '-rust' }))
end,
filetype = 'vim',
name = "66 disable filetype vim",
key = [[x]],
before = [[a | ]],
after = [[a x| ]]
},
{
filetype = 'vim',
name = "67 undo on quote",
key = [[{123<esc>u]],
end_cursor = 12,
before = [[local abc=| ]],
after = [[local abc={|} ]]
},
{
filetype = 'vim',
name = "68 undo on bracket",
key = [['123<esc>u]],
end_cursor = 12,
before = [[local abc=| ]],
after = [[local abc='|' ]]
},
{
filetype = 'vim',
name = "69 double quote on vim after char",
key = [["ab]],
before = [[echo | ]],
after = [[echo "ab|" ]]
},
{
filetype = 'vim',
name = "70 double quote on vim on begin",
key = [["ab]],
before = [[ | aaa]],
after = [[ "ab| aaa]]
},
{
setup_func = function()
npairs.add_rule(
Rule('struct%s[a-zA-Z]+%s?{$', '};')
:use_regex(true, "{")
)
end,
filetype = 'javascript',
name = "71 custom endwise rule",
key = [[{]],
before = [[struct abc | ]],
after = [[struct abc {|};]],
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rule(Rule("{", "}"):end_wise())
end,
filetype = 'javascript',
name = "72 custom endwise rule",
key = [[<cr>]],
before = [[function () {| ]],
after = {
[[function () {]],
[[|]],
[[}]],
},
},
{
setup_func = function()
vim.opt.smartindent = true
end,
filetype = 'ps1',
name = "73 indent on powershell",
key = [[<cr>]],
before = [[function () {|} ]],
after = {
[[function () {]],
[[|]],
[[}]],
},
},
{
setup_func = function()
npairs.clear_rules()
npairs.add_rule(
Rule("{", "")
:replace_endpair(function()
return "}"
end)
:end_wise()
)
end,
filetype = 'javascript',
name = "74 custom endwise rule with custom end_pair",
key = [[<cr>]],
before = [[function () {| ]],
after = {
[[function () {]],
[[|]],
[[}]],
},
},
{
name = "75 open bracker on back tick",
key = [[(]],
before = [[ |`abcd`]],
after = [[ (`abcd`) ]]
},
{
name = "76 should not add bracket on line have bracket ",
key = [[(]],
before = [[ |(abcd))]],
after = [[ ((abcd)) ]]
},
{
name = "77 not add bracket on line have bracket ",
key = [[(]],
before = [[ |(abcd) ( visual)]],
after = [[ ()(abcd) ( visual)]]
},
{
name = "78 should add single quote when it have primes char",
key = [[']],
before = [[Ben's friends say: | ]],
after = [[Ben's friends say: '|' ]]
},
{
name = "79 a quote with single quote string",
key = "'",
before = [[{{("It doesn't name %s", ''), 'ErrorMsg'| }}, ]],
after = [[{{("It doesn't name %s", ''), 'ErrorMsg''|' }}, ]],
end_cursor = 41
},
{
name = "80 add normal quote with '",
key = [["]],
before = [[aa| 'aa]],
after = [[aa"|" 'aa]]
},
{
name = "81 add closing single quote for python prefixed string",
filetype = "python",
key = [[']],
before = [[print(f|)]],
after = [[print(f'|')]]
},
{
name = "82 add closing single quote for capital python prefixed string",
filetype = "python",
key = [[']],
before = [[print(B|)]],
after = [[print(B'|')]]
},
{
name = "83 don't add closing single quote for random prefix string",
filetype = "python",
key = [[']],
before = [[print(s|)]],
after = [[print(s'|)]]
},
{
name = "84 don't add closing single quote for other filetype prefixed string",
filetype = "lua",
key = [[']],
before = [[print(f|)]],
after = [[print(f'|)]]
},
{
name = "85 allow brackets in prefixed python single quote string",
filetype = "python",
key = [[{]],
before = [[print(f'|')]],
after = [[print(f'{|}')]]
},
{
name = "86 move ' is working on python",
filetype = "python",
key = [[']],
before = [[('|') ]],
after = [[(''|) ]]
},
{
setup_func = function()
npairs.add_rules({
Rule('123456', '789'):with_pair(cond.before_regex('^12345$', 5)),
})
end,
name = '87 test before_regex with a specific string length',
key = [[123456]],
before = [[ some text before| ]],
after = [[ some text before123456|789 ]],
},
}
local run_data = _G.Test_filter(data)
describe('autopairs ', function()
_G.Test_withfile(run_data, {
cursor_add = 0,
before_each = function(value)
npairs.setup()
vim.opt.indentexpr = ""
if value.setup_func then
value.setup_func()
end
end,
})
end)

View File

@ -0,0 +1,189 @@
local utils = require('nvim-autopairs.utils')
local log = require('nvim-autopairs._log')
local api = vim.api
local ts_get_node_text = vim.treesitter.get_node_text or vim.treesitter.query.get_node_text
local helpers = {}
function helpers.feed(text, feed_opts, is_replace)
feed_opts = feed_opts or 'n'
if not is_replace then
text = vim.api.nvim_replace_termcodes(text, true, false, true)
end
vim.api.nvim_feedkeys(text, feed_opts, true)
end
function helpers.insert(text, is_replace)
helpers.feed('i' .. text, 'x', is_replace)
end
utils.insert_char = function(text)
api.nvim_put({ text }, 'c', true, true)
end
utils.feed = function(text, num)
local result = ''
for _ = 1, num, 1 do
result = result .. text
end
api.nvim_feedkeys(
---@diagnostic disable-next-line: param-type-mismatch
api.nvim_replace_termcodes(result, true, false, true),
'x',
true
)
end
_G.eq = assert.are.same
_G.Test_filter = function(data)
local run_data = {}
for _, value in pairs(data) do
if value.only == true then
table.insert(run_data, value)
break
end
end
if #run_data == 0 then
run_data = data
end
return run_data
end
local compare_text = function(linenr, text_after, name, cursor_add, end_cursor)
cursor_add = cursor_add or 0
local new_text = vim.api.nvim_buf_get_lines(
0,
linenr - 1,
linenr + #text_after - 1,
true
)
for i = 1, #text_after, 1 do
local t = string.gsub(text_after[i], '%|', '')
if t
and new_text[i]
and t:gsub('%s+$', '') ~= new_text[i]:gsub('%s+$', '')
then
eq(t, new_text[i], '\n\n text error: ' .. name .. '\n')
end
local p_after = string.find(text_after[i], '%|')
if p_after then
local row, col = utils.get_cursor()
if end_cursor then
eq(row, linenr + i - 2, '\n\n cursor row error: ' .. name .. '\n')
eq(
col + 1,
end_cursor,
'\n\n end cursor column error : ' .. name .. '\n'
)
else
eq(row, linenr + i - 2, '\n\n cursor row error: ' .. name .. '\n')
p_after = p_after + cursor_add
eq(
col,
math.max(p_after - 2, 0),
'\n\n cursor column error : ' .. name .. '\n'
)
end
end
end
return true
end
_G.Test_withfile = function(test_data, cb)
for _, value in pairs(test_data) do
it('test ' .. value.name, function(_)
local text_before = {}
value.linenr = value.linenr or 1
local pos_before = {
linenr = value.linenr,
colnr = 0,
}
if not vim.tbl_islist(value.before) then
value.before = { value.before }
end
for index, text in pairs(value.before) do
local txt = string.gsub(tostring(text), '%|', '')
table.insert(text_before, txt)
if string.match(tostring(text), '%|') then
if string.find(tostring(text), '%|') then
pos_before.colnr = string.find(tostring(text), '%|')
pos_before.linenr = value.linenr + index - 1
end
end
end
if not vim.tbl_islist(value.after) then
value.after = { value.after }
end
vim.bo.filetype = value.filetype or 'text'
vim.cmd(':bd!')
if cb.before_each then
cb.before_each(value)
end
---@diagnostic disable-next-line: missing-parameter
if vim.fn.filereadable(vim.fn.expand(value.filepath)) == 1 then
vim.cmd(':e ' .. value.filepath)
if value.filetype then
vim.bo.filetype = value.filetype
end
vim.cmd(':e')
else
vim.cmd(':new')
if value.filetype then
vim.bo.filetype = value.filetype
end
end
local status, parser = pcall(vim.treesitter.get_parser, 0)
if status then
parser:parse(true)
end
vim.api.nvim_buf_set_lines(
0,
value.linenr - 1,
value.linenr + #text_before,
false,
text_before
)
vim.api.nvim_win_set_cursor(
0,
{ pos_before.linenr, pos_before.colnr - 1 }
)
if type(value.key) == "function" then
log.debug("call key")
value.key()
else
log.debug('insert:' .. value.key)
helpers.insert(value.key, value.not_replace_term_code)
vim.wait(2)
helpers.feed('<esc>')
end
compare_text(
value.linenr,
value.after,
value.name,
cb.cursor_add,
value.end_cursor
)
if cb.after_each then
cb.after_each(value)
end
vim.cmd(':bd!')
end)
end
end
_G.dump_node = function(node)
local text = ts_get_node_text(node)
for _, txt in pairs(text) do
print(txt)
end
end
_G.dump_node_text = function(target)
for node in target:iter_children() do
local node_type = node:type()
local text = ts_get_node_text(node)
log.debug('type:' .. node_type .. ' ')
log.debug(text)
end
end

View File

@ -0,0 +1,131 @@
local npairs = require('nvim-autopairs')
local ts = require('nvim-treesitter.configs')
local log = require('nvim-autopairs._log')
local Rule = require('nvim-autopairs.rule')
local ts_conds = require('nvim-autopairs.ts-conds')
_G.npairs = npairs
vim.api.nvim_set_keymap(
'i',
'<CR>',
'v:lua.npairs.check_break_line_char()',
{ expr = true, noremap = true }
)
ts.setup({
ensure_installed = { 'lua', 'javascript', 'rust', 'markdown', 'markdown_inline' },
highlight = { enable = true },
autopairs = { enable = true },
})
local data = {
{
name = 'treesitter lua quote',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [["]],
before = {
[[ [[ aaa| ]],
[[ ]],
']]',
},
after = [[ [[ aaa"| ]],
},
{
setup_func = function()
npairs.add_rules({
Rule('%', '%', 'lua'):with_pair(
ts_conds.is_ts_node({ 'string', 'comment', 'string_content' })
),
})
end,
name = 'ts_conds is_ts_node quote',
filepath = './tests/endwise/init.lua',
filetype = 'lua',
linenr = 5,
key = [[%]],
before = {
[[ [[ abcde | ]],
[[ ]],
']]',
},
after = [[ [[ abcde %|% ]],
},
{
name = 'ts_conds is_ts_node failed',
filepath = './tests/endwise/init.lua',
linenr = 5,
filetype = 'lua',
key = '%',
before = { [[local abcd| = ' visual ']] },
after = [[local abcd%| = ' visual ']],
},
{
setup_func = function()
npairs.add_rules({
Rule('<', '>', 'rust'):with_pair(ts_conds.is_ts_node({
'type_identifier',
'let_declaration',
'parameters',
})),
})
end,
name = 'ts_conds is_ts_node failed',
filepath = './tests/endwise/main.rs',
linenr = 5,
filetype = 'rust',
key = '<',
before = [[pub fn noop(_inp: Vec|) {]],
after = [[pub fn noop(_inp: Vec<|>) {]],
},
{
setup_func = function()
npairs.add_rules({
Rule('*', '*', { 'markdown', 'markdown_inline' })
:with_pair(ts_conds.is_not_in_context()),
})
end,
name = 'ts_context markdown `*` success md_context',
filepath = './tests/endwise/sample.md',
linenr = 2,
filetype = 'markdown',
key = '*',
before = [[|]],
after = [[*|*]],
},
{
setup_func = function()
npairs.add_rules({
Rule('*', '*', { 'markdown', 'markdown_inline' })
:with_pair(ts_conds.is_not_in_context()),
})
end,
name = 'ts_context codeblock `*` fail js_context',
filepath = './tests/endwise/sample.md',
linenr = 6,
filetype = 'markdown',
key = '*',
before = [[let calc = 1 |]],
after = [[let calc = 1 *|]],
},
}
local run_data = _G.Test_filter(data)
describe('[treesitter check]', function()
_G.Test_withfile(run_data, {
before_each = function(value)
npairs.setup({
check_ts = true,
ts_config = {
javascript = { 'template_string', 'comment' },
},
})
if value.setup_func then
value.setup_func()
end
end,
})
end)

View File

@ -0,0 +1,65 @@
local utils = require('nvim-autopairs.utils')
local log = require('nvim-autopairs._log')
local eq = assert.are.same
local data = {
{
text = "add normal bracket",
start = 2,
num = 2,
result = 'dd'
},
{
text = "iood",
start = 1,
num = 2,
result = 'io'
},
{
text = "add normal bracket",
start = 0,
num = -2,
result = ''
},
{
text = "add normal bracket",
start = 3,
num = -2,
result = 'dd'
},
{
text = [["""]],
start = 3,
num = -3,
result = '"""'
},
{
text = [["""]],
start = 3,
num = 3,
result = '"'
},
{
text = [["""]],
start = 2,
num = 2,
result = '""'
},
}
describe('utils test substring ', function()
for _, value in pairs(data) do
it('test sub: ' .. value.text, function()
local result = utils.text_sub_char(value.text, value.start, value.num)
eq(value.result, result, 'start ' .. value.start .. ' num' .. value.num)
end)
end
end)
vim.wait(100)