mirror of
https://github.com/windwp/nvim-ts-autotag.git
synced 2025-01-01 13:59:13 -06:00
add some test case
This commit is contained in:
parent
a82f6cd412
commit
5d12b68979
@ -8,5 +8,7 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -9,7 +9,7 @@ const SamplePage: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div className="h-full">
|
||||
|
||||
<Img
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
<template>
|
||||
<div class="aaa">
|
||||
|
||||
</div>
|
||||
<Img
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: 'Sample',
|
||||
data() {
|
||||
@ -20,6 +19,6 @@ export default {
|
||||
|
||||
<style scoped>
|
||||
.sample{
|
||||
width:`100px`;
|
||||
width:100px;
|
||||
}
|
||||
</style>
|
||||
|
@ -3,9 +3,6 @@ local helpers = {}
|
||||
ts.setup {
|
||||
ensure_installed = 'maintained',
|
||||
highlight = {enable = true},
|
||||
indent = {
|
||||
enable = false
|
||||
}
|
||||
}
|
||||
local eq = assert.are.same
|
||||
|
||||
@ -56,24 +53,25 @@ local data = {
|
||||
before = [[const data:Array<string| ]],
|
||||
after = [[const data:Array<string> ]]
|
||||
},
|
||||
{
|
||||
name = "vue auto close tag" ,
|
||||
filepath = './sample/index.vue',
|
||||
filetype = "vue",
|
||||
linenr = 4,
|
||||
key = [[>]],
|
||||
before = [[<Img| ]],
|
||||
after = [[<Img>| </Img>]]
|
||||
},
|
||||
{
|
||||
name = "vue not close on script",
|
||||
filepath = './sample/index.vue',
|
||||
filetype = "vue",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[const data:Array<string| ]],
|
||||
after = [[const data:Array<string> ]]
|
||||
},
|
||||
-- {
|
||||
-- only = true,
|
||||
-- name = "vue auto close tag" ,
|
||||
-- filepath = './sample/index.vue',
|
||||
-- filetype = "vue",
|
||||
-- linenr = 4,
|
||||
-- key = [[>]],
|
||||
-- before = [[<Img| ]],
|
||||
-- after = [[<Img>| </Img>]]
|
||||
-- },
|
||||
-- {
|
||||
-- name = "vue not close on script",
|
||||
-- filepath = './sample/index.vue',
|
||||
-- filetype = "vue",
|
||||
-- linenr = 12,
|
||||
-- key = [[>]],
|
||||
-- before = [[const data:Array<string| ]],
|
||||
-- after = [[const data:Array<string> ]]
|
||||
-- },
|
||||
}
|
||||
local run_data = {}
|
||||
for _, value in pairs(data) do
|
||||
@ -84,7 +82,7 @@ for _, value in pairs(data) do
|
||||
end
|
||||
if #run_data == 0 then run_data = data end
|
||||
local autotag = require('nvim-ts-autotag')
|
||||
autotag.test=true
|
||||
autotag.test = true
|
||||
|
||||
local function Test(test_data)
|
||||
for _, value in pairs(test_data) do
|
||||
@ -96,14 +94,15 @@ local function Test(test_data)
|
||||
local line =value.linenr
|
||||
vim.bo.filetype = value.filetype
|
||||
if vim.fn.filereadable(vim.fn.expand(value.filepath)) == 1 then
|
||||
vim.cmd(":bd!")
|
||||
vim.cmd(":e " .. value.filepath)
|
||||
vim.fn.setline(line , before)
|
||||
vim.fn.cursor(line, p_before)
|
||||
-- autotag.closeTag()
|
||||
helpers.insert(value.key)
|
||||
helpers.feed("<esc>")
|
||||
local result = vim.fn.getline(line)
|
||||
eq(after, result , "\n\n text error: " .. value.name .. "\n")
|
||||
vim.cmd(":bd!")
|
||||
else
|
||||
eq(false, true, "\n\n file not exist " .. value.filepath .. "\n")
|
||||
end
|
||||
@ -111,6 +110,6 @@ local function Test(test_data)
|
||||
end
|
||||
end
|
||||
|
||||
describe('autotag ', function()
|
||||
describe('[close tag]', function()
|
||||
Test(run_data)
|
||||
end)
|
119
tests/renametag_spec.lua
Normal file
119
tests/renametag_spec.lua
Normal file
@ -0,0 +1,119 @@
|
||||
local ts = require 'nvim-treesitter.configs'
|
||||
local helpers = {}
|
||||
ts.setup {
|
||||
ensure_installed = 'maintained',
|
||||
highlight = {
|
||||
use_languagetree = true,
|
||||
enable = true
|
||||
},
|
||||
}
|
||||
local eq = assert.are.same
|
||||
|
||||
function helpers.feed(text, feed_opts)
|
||||
feed_opts = feed_opts or 'n'
|
||||
local to_feed = vim.api.nvim_replace_termcodes(text, true, false, true)
|
||||
vim.api.nvim_feedkeys(to_feed, feed_opts, true)
|
||||
end
|
||||
|
||||
function helpers.insert(text)
|
||||
helpers.feed('i' .. text, 'x')
|
||||
end
|
||||
|
||||
local data = {
|
||||
{
|
||||
name = "html rename tag" ,
|
||||
filepath = './sample/index.html',
|
||||
filetype = "html",
|
||||
linenr = 10,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v> dsadsa </div> ]],
|
||||
after = [[<lala|> dsadsa </lala> ]]
|
||||
},
|
||||
{
|
||||
name = "html rename 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 on 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 </lala|> ]]
|
||||
},
|
||||
{
|
||||
name = "typescriptreact rename tag" ,
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[ciwlala]],
|
||||
before = [[<di|v> dsadsa </div> ]],
|
||||
after = [[<lala|> dsadsa </lala> ]]
|
||||
},
|
||||
{
|
||||
name = "typescriptreact rename tag" ,
|
||||
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 on 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 </lala|> ]]
|
||||
},
|
||||
}
|
||||
|
||||
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
|
||||
local autotag = require('nvim-ts-autotag')
|
||||
autotag.test = true
|
||||
|
||||
local function Test(test_data)
|
||||
for _, value in pairs(test_data) do
|
||||
it("test "..value.name, function()
|
||||
local before = string.gsub(value.before , '%|' , "")
|
||||
local after = string.gsub(value.after , '%|' , "")
|
||||
local p_before = string.find(value.before , '%|')
|
||||
local p_after = string.find(value.after , '%|')
|
||||
local line =value.linenr
|
||||
vim.bo.filetype = value.filetype
|
||||
if vim.fn.filereadable(vim.fn.expand(value.filepath)) == 1 then
|
||||
vim.cmd(":bd!")
|
||||
vim.cmd(":e " .. value.filepath)
|
||||
vim.fn.setline(line , before)
|
||||
vim.fn.cursor(line, p_before)
|
||||
-- autotag.closeTag()
|
||||
helpers.feed(value.key,'x')
|
||||
helpers.feed("<esc>",'x')
|
||||
local result = vim.fn.getline(line)
|
||||
eq(after, result , "\n\n text error: " .. value.name .. "\n")
|
||||
else
|
||||
eq(false, true, "\n\n file not exist " .. value.filepath .. "\n")
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
describe('[rename tag]', function()
|
||||
Test(run_data)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user