mirror of
https://github.com/windwp/nvim-ts-autotag.git
synced 2025-01-04 17:49:20 -06:00
style: format with stylua
This commit is contained in:
parent
bc8dea7a78
commit
34f6d24007
@ -3,23 +3,23 @@ local internal = require("nvim-ts-autotag.internal")
|
||||
local M = {}
|
||||
|
||||
function M.init()
|
||||
require "nvim-treesitter".define_modules {
|
||||
autotag = {
|
||||
module_path = 'nvim-ts-autotag.internal',
|
||||
is_supported = function(lang)
|
||||
return internal.is_supported(lang)
|
||||
end
|
||||
}
|
||||
}
|
||||
require("nvim-treesitter").define_modules({
|
||||
autotag = {
|
||||
module_path = "nvim-ts-autotag.internal",
|
||||
is_supported = function(lang)
|
||||
return internal.is_supported(lang)
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
internal.setup(opts)
|
||||
vim.cmd[[augroup nvim_ts_xmltag]]
|
||||
vim.cmd[[autocmd!]]
|
||||
vim.cmd[[autocmd FileType * call v:lua.require('nvim-ts-autotag.internal').attach()]]
|
||||
vim.cmd[[autocmd BufDelete * lua require('nvim-ts-autotag.internal').detach(vim.fn.expand('<abuf>'))]]
|
||||
vim.cmd[[augroup end]]
|
||||
internal.setup(opts)
|
||||
vim.cmd([[augroup nvim_ts_xmltag]])
|
||||
vim.cmd([[autocmd!]])
|
||||
vim.cmd([[autocmd FileType * call v:lua.require('nvim-ts-autotag.internal').attach()]])
|
||||
vim.cmd([[autocmd BufDelete * lua require('nvim-ts-autotag.internal').detach(vim.fn.expand('<abuf>'))]])
|
||||
vim.cmd([[augroup end]])
|
||||
end
|
||||
|
||||
return M
|
||||
|
@ -1,13 +1,12 @@
|
||||
if _G.__is_log then
|
||||
return require('plenary.log').new {
|
||||
plugin = 'nvim-ts-autotag',
|
||||
level = (_G.__is_log == true and 'debug') or 'warn',
|
||||
}
|
||||
return require("plenary.log").new({
|
||||
plugin = "nvim-ts-autotag",
|
||||
level = (_G.__is_log == true and "debug") or "warn",
|
||||
})
|
||||
else
|
||||
return{
|
||||
return {
|
||||
debug = function(_) end,
|
||||
info = function(_) end,
|
||||
error = function(_) end,
|
||||
|
||||
}
|
||||
end
|
||||
|
@ -485,8 +485,8 @@ local function rename_start_tag()
|
||||
-- log.debug("do replace")
|
||||
-- log.debug(tag_name)
|
||||
-- log.debug(close_tag_name)
|
||||
if close_tag_name == '>' then
|
||||
tag_name = tag_name .. '>'
|
||||
if close_tag_name == ">" then
|
||||
tag_name = tag_name .. ">"
|
||||
end
|
||||
replace_text_node(close_tag_node, tag_name)
|
||||
end
|
||||
@ -531,7 +531,7 @@ local function rename_end_tag()
|
||||
if start_tag_node ~= nil then
|
||||
local start_tag_name = get_tag_name(start_tag_node)
|
||||
if tag_name ~= start_tag_name then
|
||||
log.debug('replace end tag')
|
||||
log.debug("replace end tag")
|
||||
replace_text_node(start_tag_node, tag_name)
|
||||
end
|
||||
end
|
||||
@ -550,8 +550,8 @@ local function is_before(regex, range)
|
||||
end
|
||||
end
|
||||
|
||||
local is_before_word = is_before('%w', 1)
|
||||
local is_before_arrow = is_before('<', 0)
|
||||
local is_before_word = is_before("%w", 1)
|
||||
local is_before_arrow = is_before("<", 0)
|
||||
|
||||
M.rename_tag = function()
|
||||
if is_before_word() and parsers.has_parser() then
|
||||
@ -568,7 +568,7 @@ M.attach = function(bufnr, lang)
|
||||
|
||||
if is_in_table(M.tbl_filetypes, vim.bo.filetype) then
|
||||
setup_ts_tag()
|
||||
local group = vim.api.nvim_create_augroup('nvim-ts-autotag', { clear = true })
|
||||
local group = vim.api.nvim_create_augroup("nvim-ts-autotag", { clear = true })
|
||||
if M.enable_close == true then
|
||||
vim.api.nvim_buf_set_keymap(bufnr or 0, "i", ">", ">", {
|
||||
noremap = true,
|
||||
@ -589,7 +589,7 @@ M.attach = function(bufnr, lang)
|
||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
vim.api.nvim_buf_set_text(bufnr or 0, row - 1, col, row - 1, col, { "/" })
|
||||
if is_before_arrow() then
|
||||
log.debug('is_before_arrow')
|
||||
log.debug("is_before_arrow")
|
||||
M.close_slash_tag()
|
||||
end
|
||||
local new_row, new_col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
|
@ -1,19 +1,16 @@
|
||||
local _, ts_utils = pcall(require, 'nvim-treesitter.ts_utils')
|
||||
local log = require('nvim-ts-autotag._log')
|
||||
local _, ts_utils = pcall(require, "nvim-treesitter.ts_utils")
|
||||
local log = require("nvim-ts-autotag._log")
|
||||
local get_node_text = vim.treesitter.get_node_text or vim.treesitter.query.get_node_text or ts_utils.get_node_text
|
||||
local M = {}
|
||||
|
||||
M.get_node_text = function(node)
|
||||
local _, txt = pcall(get_node_text, node, vim.api.nvim_get_current_buf())
|
||||
return vim.split(txt, '\n') or {}
|
||||
return vim.split(txt, "\n") or {}
|
||||
end
|
||||
|
||||
M.verify_node = function(node, node_tag)
|
||||
local txt = get_node_text(node, vim.api.nvim_get_current_buf())
|
||||
if
|
||||
txt:match(string.format('^<%s>', node_tag))
|
||||
and txt:match(string.format('</%s>$', node_tag))
|
||||
then
|
||||
if txt:match(string.format("^<%s>", node_tag)) and txt:match(string.format("</%s>$", node_tag)) then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
@ -30,22 +27,22 @@ M.dump_node = function(node)
|
||||
end
|
||||
|
||||
M.is_close_empty_node = function(node)
|
||||
local tag_name = ''
|
||||
local tag_name = ""
|
||||
if node ~= nil then
|
||||
local text = M.get_node_text(node)
|
||||
tag_name = text[#text - 1]
|
||||
end
|
||||
return tag_name:match('%<%/%>$')
|
||||
return tag_name:match("%<%/%>$")
|
||||
end
|
||||
|
||||
M.dump_node_text = function(target)
|
||||
log.debug('=============================')
|
||||
log.debug("=============================")
|
||||
for node in target:iter_children() do
|
||||
local node_type = node:type()
|
||||
local text = M.get_node_text(node)
|
||||
log.debug('type:' .. node_type .. ' ')
|
||||
log.debug("type:" .. node_type .. " ")
|
||||
log.debug(text)
|
||||
end
|
||||
log.debug('=============================')
|
||||
log.debug("=============================")
|
||||
end
|
||||
return M
|
||||
|
@ -1,4 +1,4 @@
|
||||
local ts = require('nvim-treesitter.configs')
|
||||
local ts = require("nvim-treesitter.configs")
|
||||
ts.setup({
|
||||
ensure_installed = _G.ts_filetypes,
|
||||
highlight = { enable = true },
|
||||
@ -6,162 +6,162 @@ ts.setup({
|
||||
|
||||
local data = {
|
||||
{
|
||||
name = '1 html close tag after inputting /',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "1 html close tag after inputting /",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[/]],
|
||||
before = [[<div><| ]],
|
||||
after = [[<div></div>|]],
|
||||
},
|
||||
{
|
||||
name = '2 html close tag after inputting /',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "2 html close tag after inputting /",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[/]],
|
||||
before = [[<div clas="laa"><| ]],
|
||||
after = [[<div clas="laa"></div>|]],
|
||||
},
|
||||
{
|
||||
name = '3 html don\'t close tag when no opening tag is found',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "3 html don't close tag when no opening tag is found",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[/>]],
|
||||
before = [[<div><|</div> ]],
|
||||
after = [[<div></>|</div>]],
|
||||
},
|
||||
{
|
||||
name = '4 html not close inside quote',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "4 html not close inside quote",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[/]],
|
||||
before = [[<div class="aa|"> </div> ]],
|
||||
after = [[<div class="aa/|"> </div> ]],
|
||||
},
|
||||
{
|
||||
name = '5 typescriptreact close tag after inputting /',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "5 typescriptreact close tag after inputting /",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[/]],
|
||||
before = [[<Img><| ]],
|
||||
after = [[<Img></Img>| ]],
|
||||
},
|
||||
{
|
||||
name = '6 typescriptreact close after inputting /',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "6 typescriptreact close after inputting /",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[/]],
|
||||
before = [[<div class="abc"><| ]],
|
||||
after = [[<div class="abc"></div>| ]],
|
||||
},
|
||||
{
|
||||
name = '7 typescriptreact close on inline script after inputting /',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "7 typescriptreact close on inline script after inputting /",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 9,
|
||||
key = [[/]],
|
||||
before = [[const a = () => <div><| ]],
|
||||
after = [[const a = () => <div></div>| ]],
|
||||
},
|
||||
{
|
||||
name = '8 typescriptreact not close on close tag',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "8 typescriptreact not close on close tag",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[/]],
|
||||
before = [[<button className="btn " onClick={()}> <| ]],
|
||||
after = [[<button className="btn " onClick={()}> </button>| ]],
|
||||
},
|
||||
{
|
||||
name = '9 typescriptreact not close on expresion',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "9 typescriptreact not close on expresion",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[/]],
|
||||
before = [[<button className="btn " onClick={(|)}> </button> ]],
|
||||
after = [[<button className="btn " onClick={(/|)}> </button> ]],
|
||||
},
|
||||
{
|
||||
name = '10 typescriptreact not close on typescript',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "10 typescriptreact not close on typescript",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 6,
|
||||
key = [[/]],
|
||||
before = [[const data:Array<string| ]],
|
||||
after = [[const data:Array<string/| ]],
|
||||
},
|
||||
{
|
||||
name = '11 typescriptreact not close on script',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "11 typescriptreact not close on script",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 6,
|
||||
key = [[/]],
|
||||
before = [[{(card.data | 0) && <div></div>}]],
|
||||
after = [[{(card.data /| 0) && <div></div>}]],
|
||||
},
|
||||
{
|
||||
name = '12 vue close tag after inputting /',
|
||||
filepath = './sample/index.vue',
|
||||
filetype = 'vue',
|
||||
name = "12 vue close tag after inputting /",
|
||||
filepath = "./sample/index.vue",
|
||||
filetype = "vue",
|
||||
linenr = 4,
|
||||
key = [[/]],
|
||||
before = [[<Img><| ]],
|
||||
after = [[<Img></Img>|]],
|
||||
},
|
||||
{
|
||||
name = '13 vue not close on script',
|
||||
filepath = './sample/index.vue',
|
||||
filetype = 'vue',
|
||||
name = "13 vue not close on script",
|
||||
filepath = "./sample/index.vue",
|
||||
filetype = "vue",
|
||||
linenr = 12,
|
||||
key = [[/]],
|
||||
before = [[const data:Array<string| ]],
|
||||
after = [[const data:Array<string/| ]],
|
||||
},
|
||||
{
|
||||
name = '14 typescriptreact nested indentifer close after inputting /',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "14 typescriptreact nested indentifer close after inputting /",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[/]],
|
||||
before = [[<Opt.Input><| ]],
|
||||
after = [[<Opt.Input></Opt.Input>| ]],
|
||||
},
|
||||
{
|
||||
name = '15 php close tag after inputting /',
|
||||
filepath = './sample/index.php',
|
||||
filetype = 'php',
|
||||
name = "15 php close tag after inputting /",
|
||||
filepath = "./sample/index.php",
|
||||
filetype = "php",
|
||||
linenr = 25,
|
||||
key = [[/]],
|
||||
before = [[<div><| ]],
|
||||
after = [[<div></div>| ]],
|
||||
},
|
||||
{
|
||||
name = '16 lit template div close after inputting /',
|
||||
filepath = './sample/index.ts',
|
||||
filetype = 'typescript',
|
||||
name = "16 lit template div close after inputting /",
|
||||
filepath = "./sample/index.ts",
|
||||
filetype = "typescript",
|
||||
linenr = 3,
|
||||
key = [[/]],
|
||||
before = [[<div><| ]],
|
||||
after = [[<div></div>| ]],
|
||||
},
|
||||
{
|
||||
name = '17 eruby template div close after inputting /',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "17 eruby template div close after inputting /",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 10,
|
||||
key = [[/]],
|
||||
before = [[<div><| ]],
|
||||
after = [[<div></div>| ]],
|
||||
},
|
||||
{
|
||||
name = '18 eruby template ruby string write raw /',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "18 eruby template ruby string write raw /",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 10,
|
||||
key = [[/]],
|
||||
before = [[<%= <div| %>]],
|
||||
@ -169,13 +169,13 @@ local data = {
|
||||
},
|
||||
}
|
||||
|
||||
local autotag = require('nvim-ts-autotag')
|
||||
local autotag = require("nvim-ts-autotag")
|
||||
autotag.test = true
|
||||
local run_data = _G.Test_filter(data)
|
||||
|
||||
describe('[close slash tag]', function()
|
||||
describe("[close slash tag]", function()
|
||||
_G.Test_withfile(run_data, {
|
||||
mode = 'i',
|
||||
mode = "i",
|
||||
cursor_add = 0,
|
||||
})
|
||||
end)
|
||||
|
@ -1,4 +1,4 @@
|
||||
local ts = require('nvim-treesitter.configs')
|
||||
local ts = require("nvim-treesitter.configs")
|
||||
ts.setup({
|
||||
ensure_installed = _G.ts_filetypes,
|
||||
highlight = { enable = true },
|
||||
@ -6,90 +6,90 @@ ts.setup({
|
||||
|
||||
local data = {
|
||||
{
|
||||
name = '1 html close tag',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "1 html close tag",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[>]],
|
||||
before = [[<div| ]],
|
||||
after = [[<div>|</div>]],
|
||||
},
|
||||
{
|
||||
name = '2 html close tag',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "2 html close tag",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[>]],
|
||||
before = [[<div clas="laa"| ]],
|
||||
after = [[<div clas="laa">|</div>]],
|
||||
},
|
||||
{
|
||||
name = '3 html not close tag on close tag',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "3 html not close tag on close tag",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[>]],
|
||||
before = [[<div>aa</div| ]],
|
||||
after = [[<div>aa</div>|]],
|
||||
},
|
||||
{
|
||||
name = '4 html not close on input tag',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "4 html not close on input tag",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[>]],
|
||||
before = [[<input| ]],
|
||||
after = [[<input>| ]],
|
||||
},
|
||||
{
|
||||
name = '5 html not close inside quote',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "5 html not close inside quote",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[>]],
|
||||
before = [[<div class="aa|"> </div> ]],
|
||||
after = [[<div class="aa>|"> </div> ]],
|
||||
},
|
||||
{
|
||||
name = '6 html not close on exist tag',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "6 html not close on exist tag",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[>]],
|
||||
before = [[<div><div|</div></div>]],
|
||||
after = [[<div><div>|</div></div>]],
|
||||
},
|
||||
{
|
||||
name = '7 typescriptreact close tag',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "7 typescriptreact close tag",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[<Img| ]],
|
||||
after = [[<Img>|</Img> ]],
|
||||
},
|
||||
{
|
||||
name = '8 typescriptreact close',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "8 typescriptreact close",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[<div class="abc"| ]],
|
||||
after = [[<div class="abc">|</div> ]],
|
||||
},
|
||||
{
|
||||
name = '9 typescriptreact not close on exist tag',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "9 typescriptreact not close on exist tag",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[<div><div|</div></div>]],
|
||||
after = [[<div><div>|</div></div>]],
|
||||
},
|
||||
{
|
||||
name = '10 typescriptreact close on inline script',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "10 typescriptreact close on inline script",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 9,
|
||||
key = [[>]],
|
||||
before = [[const a = () => <div| ]],
|
||||
@ -97,27 +97,27 @@ local data = {
|
||||
},
|
||||
{
|
||||
|
||||
name = '11 typescriptreact not close on close tag',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "11 typescriptreact not close on close tag",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[<button className="btn " onClick={()}> </button| ]],
|
||||
after = [[<button className="btn " onClick={()}> </button>| ]],
|
||||
},
|
||||
{
|
||||
name = '12 typescriptreact not close on expresion',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "12 typescriptreact not close on expresion",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[<button className="btn " onClick={(|)}> </button> ]],
|
||||
after = [[<button className="btn " onClick={(>|)}> </button> ]],
|
||||
},
|
||||
{
|
||||
name = '13 typescriptreact not close on typescript',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "13 typescriptreact not close on typescript",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 6,
|
||||
key = [[>]],
|
||||
before = [[const data:Array<string| ]],
|
||||
@ -125,45 +125,45 @@ local data = {
|
||||
},
|
||||
|
||||
{
|
||||
name = '14 typescriptreact not close on script',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "14 typescriptreact not close on script",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 6,
|
||||
key = [[>]],
|
||||
before = [[{(card.data | 0) && <div></div>}]],
|
||||
after = [[{(card.data >| 0) && <div></div>}]],
|
||||
},
|
||||
{
|
||||
name = '15 vue auto close tag',
|
||||
filepath = './sample/index.vue',
|
||||
filetype = 'vue',
|
||||
name = "15 vue auto close tag",
|
||||
filepath = "./sample/index.vue",
|
||||
filetype = "vue",
|
||||
linenr = 4,
|
||||
key = [[>]],
|
||||
before = [[<Img| ]],
|
||||
after = [[<Img>|</Img>]],
|
||||
},
|
||||
{
|
||||
name = '16 vue not close on script',
|
||||
filepath = './sample/index.vue',
|
||||
filetype = 'vue',
|
||||
name = "16 vue not close on script",
|
||||
filepath = "./sample/index.vue",
|
||||
filetype = "vue",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[const data:Array<string| ]],
|
||||
after = [[const data:Array<string>| ]],
|
||||
},
|
||||
{
|
||||
name = '17 typescriptreact nested indentifer ',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "17 typescriptreact nested indentifer ",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[<Opt.Input| ]],
|
||||
after = [[<Opt.Input>|</Opt.Input> ]],
|
||||
},
|
||||
{
|
||||
name = '18 php div ',
|
||||
filepath = './sample/index.php',
|
||||
filetype = 'php',
|
||||
name = "18 php div ",
|
||||
filepath = "./sample/index.php",
|
||||
filetype = "php",
|
||||
linenr = 25,
|
||||
key = [[>]],
|
||||
before = [[<div| ]],
|
||||
@ -179,27 +179,27 @@ local data = {
|
||||
-- after = [[<div>|</div> ]],
|
||||
-- },
|
||||
{
|
||||
name = '19 lit template div',
|
||||
filepath = './sample/index.ts',
|
||||
filetype = 'typescript',
|
||||
name = "19 lit template div",
|
||||
filepath = "./sample/index.ts",
|
||||
filetype = "typescript",
|
||||
linenr = 3,
|
||||
key = [[>]],
|
||||
before = [[<div| ]],
|
||||
after = [[<div>|</div> ]],
|
||||
},
|
||||
{
|
||||
name = '20 eruby template div',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "20 eruby template div",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 10,
|
||||
key = [[>]],
|
||||
before = [[<div| ]],
|
||||
after = [[<div>|</div> ]],
|
||||
},
|
||||
{
|
||||
name = '20 eruby template ruby string',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "20 eruby template ruby string",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 10,
|
||||
key = [[>]],
|
||||
before = [[<%= <div| %>]],
|
||||
@ -207,13 +207,13 @@ local data = {
|
||||
},
|
||||
}
|
||||
|
||||
local autotag = require('nvim-ts-autotag')
|
||||
local autotag = require("nvim-ts-autotag")
|
||||
autotag.test = true
|
||||
local run_data = _G.Test_filter(data)
|
||||
|
||||
describe('[close tag]', function()
|
||||
describe("[close tag]", function()
|
||||
_G.Test_withfile(run_data, {
|
||||
mode = 'i',
|
||||
mode = "i",
|
||||
cursor_add = 0,
|
||||
before_each = function(value) end,
|
||||
})
|
||||
|
@ -1,4 +1,4 @@
|
||||
local ts = require 'nvim-treesitter.configs'
|
||||
local ts = require("nvim-treesitter.configs")
|
||||
ts.setup({
|
||||
ensure_installed = _G.ts_filetypes,
|
||||
highlight = {
|
||||
@ -8,39 +8,38 @@ ts.setup({
|
||||
fold = { enable = false },
|
||||
})
|
||||
|
||||
|
||||
local data = {
|
||||
{
|
||||
name = 'html rename open tag',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "html rename open tag",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v> dsadsa </div> ]],
|
||||
after = [[<lala|> dsadsa </lala> ]],
|
||||
},
|
||||
{
|
||||
name = 'html rename open tag with attr',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "html rename open tag with attr",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v class="lla"> dsadsa </div> ]],
|
||||
after = [[<lala| class="lla"> dsadsa </lala|> ]],
|
||||
},
|
||||
{
|
||||
name = 'html rename close tag with attr',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "html rename close tag with attr",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[ciwlala]],
|
||||
before = [[<div class="lla"> dsadsa </di|v> ]],
|
||||
after = [[<lala class="lla"> dsadsa </lal|a> ]],
|
||||
},
|
||||
{
|
||||
name = 'html not rename close tag on char <',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "html not rename close tag on char <",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[i<]],
|
||||
before = [[<div class="lla"> dsadsa |/button> ]],
|
||||
@ -48,9 +47,9 @@ local data = {
|
||||
},
|
||||
{
|
||||
|
||||
name = 'html not rename close tag with not valid',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "html not rename close tag with not valid",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = {
|
||||
@ -74,9 +73,9 @@ local data = {
|
||||
-- },
|
||||
{
|
||||
|
||||
name = 'html not rename close tag with not valid',
|
||||
filepath = './sample/index.html',
|
||||
filetype = 'html',
|
||||
name = "html not rename close tag with not valid",
|
||||
filepath = "./sample/index.html",
|
||||
filetype = "html",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = {
|
||||
@ -85,202 +84,202 @@ local data = {
|
||||
after = [[<div class="lla" </lala|>]],
|
||||
},
|
||||
{
|
||||
name = 'typescriptreact rename open tag',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "typescriptreact rename open tag",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v> dsadsa </div> ]],
|
||||
after = [[<lala|> dsadsa </lala> ]],
|
||||
},
|
||||
{
|
||||
name = 'typescriptreact rename open tag with attr',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "typescriptreact rename open tag with attr",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v class="lla"> dsadsa </div> ]],
|
||||
after = [[<lala| class="lla"> dsadsa </lala> ]],
|
||||
},
|
||||
{
|
||||
name = 'typescriptreact rename close tag with attr',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'html',
|
||||
name = "typescriptreact rename close tag with attr",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "html",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<div class="lla"> dsadsa </di|v> ]],
|
||||
after = [[<lala class="lla"> dsadsa </lal|a> ]],
|
||||
},
|
||||
{
|
||||
name = '17 typescriptreact nested indentifer ',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "17 typescriptreact nested indentifer ",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<Opt.In|put></Opt.Input> ]],
|
||||
after = [[<Opt.lala|></Opt.lala> ]],
|
||||
},
|
||||
{
|
||||
name = '18 rename empty node ',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "18 rename empty node ",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[ilala]],
|
||||
before = [[<|><div></div></>]],
|
||||
after = [[<lala|><div></div></lala>]],
|
||||
},
|
||||
{
|
||||
name = '19 rename start tag on svelte ',
|
||||
filepath = './sample/index.svelte',
|
||||
filetype = 'svelte',
|
||||
name = "19 rename start tag on svelte ",
|
||||
filepath = "./sample/index.svelte",
|
||||
filetype = "svelte",
|
||||
linenr = 18,
|
||||
key = [[ciwlala]],
|
||||
before = [[<|data></data>]],
|
||||
after = [[<lala|></lala>]],
|
||||
},
|
||||
{
|
||||
name = '20 rename end tag on svelte ',
|
||||
filepath = './sample/index.svelte',
|
||||
filetype = 'svelte',
|
||||
name = "20 rename end tag on svelte ",
|
||||
filepath = "./sample/index.svelte",
|
||||
filetype = "svelte",
|
||||
linenr = 18,
|
||||
key = [[ciwlala]],
|
||||
before = [[<span></spa|n>]],
|
||||
after = [[<lala></lala>]],
|
||||
},
|
||||
{
|
||||
name = "21 rescript rename open tag",
|
||||
filepath = './sample/index.res',
|
||||
name = "21 rescript rename open tag",
|
||||
filepath = "./sample/index.res",
|
||||
filetype = "rescript",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v> dsadsa </div> ]],
|
||||
after = [[<lala|> dsadsa </lala> ]]
|
||||
},
|
||||
{
|
||||
name = "22 rescript rename open tag with attr",
|
||||
filepath = './sample/index.res',
|
||||
filetype = "rescript",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v class="lla"> dsadsa </div> ]],
|
||||
after = [[<lala| class="lla"> dsadsa </lala> ]]
|
||||
},
|
||||
{
|
||||
name = "23 rescript rename close tag with attr",
|
||||
filepath = './sample/index.res',
|
||||
filetype = "rescript",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<div class="lla"> dsadsa </di|v> ]],
|
||||
after = [[<lala class="lla"> dsadsa </lal|a> ]]
|
||||
},
|
||||
{
|
||||
name = '24 test check rename same with parent',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
linenr = 12,
|
||||
key = 'ciwkey',
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v> dsadsa </div> ]],
|
||||
after = [[<lala|> dsadsa </lala> ]],
|
||||
},
|
||||
{
|
||||
name = "22 rescript rename open tag with attr",
|
||||
filepath = "./sample/index.res",
|
||||
filetype = "rescript",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v class="lla"> dsadsa </div> ]],
|
||||
after = [[<lala| class="lla"> dsadsa </lala> ]],
|
||||
},
|
||||
{
|
||||
name = "23 rescript rename close tag with attr",
|
||||
filepath = "./sample/index.res",
|
||||
filetype = "rescript",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<div class="lla"> dsadsa </di|v> ]],
|
||||
after = [[<lala class="lla"> dsadsa </lal|a> ]],
|
||||
},
|
||||
{
|
||||
name = "24 test check rename same with parent",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = "ciwkey",
|
||||
before = {
|
||||
'<Container>',
|
||||
' <di|v>',
|
||||
'',
|
||||
' <span></span>',
|
||||
'</Container>',
|
||||
"<Container>",
|
||||
" <di|v>",
|
||||
"",
|
||||
" <span></span>",
|
||||
"</Container>",
|
||||
},
|
||||
after = {
|
||||
'<Container>',
|
||||
' <key>',
|
||||
'',
|
||||
' <span></span>',
|
||||
'</Container>',
|
||||
"<Container>",
|
||||
" <key>",
|
||||
"",
|
||||
" <span></span>",
|
||||
"</Container>",
|
||||
},
|
||||
},
|
||||
{
|
||||
name = '25 rename start have same node with parent',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "25 rename start have same node with parent",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = {
|
||||
'<div>',
|
||||
' <di|v>',
|
||||
' <span>test </span>',
|
||||
' </div>',
|
||||
'</div>',
|
||||
"<div>",
|
||||
" <di|v>",
|
||||
" <span>test </span>",
|
||||
" </div>",
|
||||
"</div>",
|
||||
},
|
||||
after = {
|
||||
'<div>',
|
||||
' <lala>',
|
||||
' <span>test </span>',
|
||||
' </lala>',
|
||||
'</div>',
|
||||
"<div>",
|
||||
" <lala>",
|
||||
" <span>test </span>",
|
||||
" </lala>",
|
||||
"</div>",
|
||||
},
|
||||
},
|
||||
{
|
||||
name = '26 rename should not rename tag on attribute node',
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = 'typescriptreact',
|
||||
name = "26 rename should not rename tag on attribute node",
|
||||
filepath = "./sample/index.tsx",
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = {
|
||||
'<div>',
|
||||
"<div>",
|
||||
'<Navbar className="|a">',
|
||||
' <div className="flex flex-col">',
|
||||
' <div className="flex flex-row">',
|
||||
' </div>',
|
||||
' </div>',
|
||||
'</div>',
|
||||
" </div>",
|
||||
" </div>",
|
||||
"</div>",
|
||||
},
|
||||
after = {
|
||||
'<div>',
|
||||
"<div>",
|
||||
'<Navbar className="lala">',
|
||||
' <div className="flex flex-col">',
|
||||
' <div className="flex flex-row">',
|
||||
' </div>',
|
||||
' </div>',
|
||||
'</div>',
|
||||
" </div>",
|
||||
" </div>",
|
||||
"</div>",
|
||||
},
|
||||
},
|
||||
{
|
||||
name = 'eruby rename open tag',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "eruby rename open tag",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 10,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v> dsadsa </div> ]],
|
||||
after = [[<lala|> dsadsa </lala> ]],
|
||||
},
|
||||
{
|
||||
name = 'eruby rename open tag with attr',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "eruby rename open tag with attr",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 10,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v class="lla"> dsadsa </div> ]],
|
||||
after = [[<lala| class="lla"> dsadsa </lala|> ]],
|
||||
},
|
||||
{
|
||||
name = 'eruby rename close tag with attr',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "eruby rename close tag with attr",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 10,
|
||||
key = [[ciwlala]],
|
||||
before = [[<div class="lla"> dsadsa </di|v> ]],
|
||||
after = [[<lala class="lla"> dsadsa </lal|a> ]],
|
||||
},
|
||||
{
|
||||
name = 'eruby not rename close tag on char <',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "eruby not rename close tag on char <",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 10,
|
||||
key = [[i<]],
|
||||
before = [[<div class="lla"> dsadsa |/button> ]],
|
||||
after = [[<div class="lla"> dsadsa <|/button> ]],
|
||||
},
|
||||
{
|
||||
name = 'eruby not rename close tag with not valid',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "eruby not rename close tag with not valid",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = {
|
||||
@ -290,9 +289,9 @@ local data = {
|
||||
after = [[<lala class="lla" ]],
|
||||
},
|
||||
{
|
||||
name = 'eruby not rename close tag with not valid',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "eruby not rename close tag with not valid",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = {
|
||||
@ -301,9 +300,9 @@ local data = {
|
||||
after = [[<div class="lla" </lala|>]],
|
||||
},
|
||||
{
|
||||
name = 'eruby not rename tag-like ruby string',
|
||||
filepath = './sample/index.html.erb',
|
||||
filetype = 'eruby',
|
||||
name = "eruby not rename tag-like ruby string",
|
||||
filepath = "./sample/index.html.erb",
|
||||
filetype = "eruby",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = {
|
||||
@ -313,12 +312,12 @@ local data = {
|
||||
},
|
||||
}
|
||||
|
||||
local autotag = require('nvim-ts-autotag')
|
||||
local autotag = require("nvim-ts-autotag")
|
||||
autotag.test = true
|
||||
|
||||
local run_data = _G.Test_filter(data)
|
||||
|
||||
describe('[rename tag]', function()
|
||||
describe("[rename tag]", function()
|
||||
_G.Test_withfile(run_data, {
|
||||
cursor_add = 0,
|
||||
before_each = function(value) end,
|
||||
|
@ -1,11 +1,11 @@
|
||||
local utils = require('nvim-ts-autotag.utils')
|
||||
local log = require('nvim-ts-autotag._log')
|
||||
local utils = require("nvim-ts-autotag.utils")
|
||||
local log = require("nvim-ts-autotag._log")
|
||||
local api = vim.api
|
||||
|
||||
local helpers = {}
|
||||
|
||||
function helpers.feed(text, feed_opts, is_replace)
|
||||
feed_opts = feed_opts or 'n'
|
||||
feed_opts = feed_opts or "n"
|
||||
if not is_replace then
|
||||
text = vim.api.nvim_replace_termcodes(text, true, false, true)
|
||||
end
|
||||
@ -13,23 +13,19 @@ function helpers.feed(text, feed_opts, is_replace)
|
||||
end
|
||||
|
||||
function helpers.insert(text, is_replace)
|
||||
helpers.feed('i' .. text, 'x', is_replace)
|
||||
helpers.feed("i" .. text, "x", is_replace)
|
||||
end
|
||||
|
||||
utils.insert_char = function(text)
|
||||
api.nvim_put({ text }, 'c', true, true)
|
||||
api.nvim_put({ text }, "c", true, true)
|
||||
end
|
||||
|
||||
utils.feed = function(text, num)
|
||||
local result = ''
|
||||
local result = ""
|
||||
for _ = 1, num, 1 do
|
||||
result = result .. text
|
||||
end
|
||||
api.nvim_feedkeys(
|
||||
api.nvim_replace_termcodes(result, true, false, true),
|
||||
'x',
|
||||
true
|
||||
)
|
||||
api.nvim_feedkeys(api.nvim_replace_termcodes(result, true, false, true), "x", true)
|
||||
end
|
||||
|
||||
_G.eq = assert.are.same
|
||||
@ -50,38 +46,22 @@ 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
|
||||
)
|
||||
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')
|
||||
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], '%|')
|
||||
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'
|
||||
)
|
||||
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')
|
||||
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'
|
||||
)
|
||||
eq(col, math.max(p_after - 2, 0), "\n\n cursor column error : " .. name .. "\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -90,7 +70,7 @@ end
|
||||
|
||||
_G.Test_withfile = function(test_data, cb)
|
||||
for _, value in pairs(test_data) do
|
||||
it('test ' .. value.name, function(done)
|
||||
it("test " .. value.name, function(done)
|
||||
local text_before = {}
|
||||
value.linenr = value.linenr or 1
|
||||
local pos_before = {
|
||||
@ -101,11 +81,11 @@ _G.Test_withfile = function(test_data, cb)
|
||||
value.before = { value.before }
|
||||
end
|
||||
for index, text in pairs(value.before) do
|
||||
local txt = string.gsub(text, '%|', '')
|
||||
local txt = string.gsub(text, "%|", "")
|
||||
table.insert(text_before, txt)
|
||||
if string.match(text, '%|') then
|
||||
if string.find(text, '%|') then
|
||||
pos_before.colnr = string.find(text, '%|')
|
||||
if string.match(text, "%|") then
|
||||
if string.find(text, "%|") then
|
||||
pos_before.colnr = string.find(text, "%|")
|
||||
pos_before.linenr = value.linenr + index - 1
|
||||
end
|
||||
end
|
||||
@ -113,61 +93,46 @@ _G.Test_withfile = function(test_data, cb)
|
||||
if not vim.tbl_islist(value.after) then
|
||||
value.after = { value.after }
|
||||
end
|
||||
vim.bo.filetype = value.filetype or 'text'
|
||||
vim.cmd(':bd!')
|
||||
vim.bo.filetype = value.filetype or "text"
|
||||
vim.cmd(":bd!")
|
||||
if cb.before_each then
|
||||
cb.before_each(value)
|
||||
end
|
||||
if vim.fn.filereadable(vim.fn.expand(value.filepath)) == 1 then
|
||||
vim.cmd(':e ' .. value.filepath)
|
||||
vim.cmd(":e " .. value.filepath)
|
||||
if value.filetype then
|
||||
vim.bo.filetype = value.filetype
|
||||
end
|
||||
vim.cmd(':e')
|
||||
vim.cmd(":e")
|
||||
else
|
||||
vim.cmd(':new')
|
||||
vim.cmd(":new")
|
||||
if value.filetype then
|
||||
vim.bo.filetype = value.filetype
|
||||
end
|
||||
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 }
|
||||
)
|
||||
log.debug('insert:' .. value.key)
|
||||
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 })
|
||||
log.debug("insert:" .. value.key)
|
||||
|
||||
if type(value.key) == 'string' then
|
||||
if cb.mode == 'i' then
|
||||
if type(value.key) == "string" then
|
||||
if cb.mode == "i" then
|
||||
helpers.insert(value.key, value.not_replace_term_code)
|
||||
else
|
||||
helpers.feed(value.key, 'x')
|
||||
helpers.feed(value.key, "x")
|
||||
end
|
||||
else
|
||||
for _, key in pairs(value.key) do
|
||||
helpers.feed(key, 'x')
|
||||
helpers.feed(key, "x")
|
||||
vim.wait(1)
|
||||
end
|
||||
end
|
||||
vim.wait(2)
|
||||
helpers.feed('<esc>')
|
||||
compare_text(
|
||||
value.linenr,
|
||||
value.after,
|
||||
value.name,
|
||||
cb.cursor_add,
|
||||
value.end_cursor
|
||||
)
|
||||
helpers.feed("<esc>")
|
||||
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!')
|
||||
vim.cmd(":bd!")
|
||||
end)
|
||||
end
|
||||
end
|
||||
@ -183,7 +148,7 @@ _G.dump_node_text = function(target)
|
||||
for node in target:iter_children() do
|
||||
local node_type = node:type()
|
||||
local text = utils.get_node_text(node)
|
||||
log.debug('type:' .. node_type .. ' ')
|
||||
log.debug("type:" .. node_type .. " ")
|
||||
log.debug(text)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user