mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
add test
This commit is contained in:
parent
1c7ba3ffcf
commit
474c59dcf1
4 changed files with 37 additions and 2 deletions
|
|
@ -138,15 +138,15 @@ function M.get_indent(lnum)
|
||||||
-- The final node we capture of the previous line can be a comment node, which should also be ignored
|
-- The final node we capture of the previous line can be a comment node, which should also be ignored
|
||||||
-- Unless the last line is an entire line of comment, ignore the comment range and find the last node again
|
-- Unless the last line is an entire line of comment, ignore the comment range and find the last node again
|
||||||
local first_node = get_first_node_at_line(root, prevlnum, indent)
|
local first_node = get_first_node_at_line(root, prevlnum, indent)
|
||||||
|
local _, scol, _, _ = node:range()
|
||||||
if first_node:id() ~= node:id() then
|
if first_node:id() ~= node:id() then
|
||||||
-- In case the last captured node is a trailing comment node, re-trim the string
|
-- In case the last captured node is a trailing comment node, re-trim the string
|
||||||
prevline = vim.trim(prevline:sub(1, node:start() + 1 - indent))
|
prevline = vim.trim(prevline:sub(1, scol - indent))
|
||||||
-- Add back indent as indent of prevline was trimmed away
|
-- Add back indent as indent of prevline was trimmed away
|
||||||
local col = indent + #prevline - 1
|
local col = indent + #prevline - 1
|
||||||
node = get_last_node_at_line(root, prevlnum, col)
|
node = get_last_node_at_line(root, prevlnum, col)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if q.indent["end"][node:id()] then
|
if q.indent["end"][node:id()] then
|
||||||
node = get_first_node_at_line(root, lnum)
|
node = get_first_node_at_line(root, lnum)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
6
tests/indent/algorithm/trailing.py
Normal file
6
tests/indent/algorithm/trailing.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
class x: # Ignore comment
|
||||||
|
|
||||||
|
class y:
|
||||||
|
def z(): # Ignore comment
|
||||||
|
|
||||||
|
class t:
|
||||||
11
tests/indent/algorithm/trailing_whitespace.html
Normal file
11
tests/indent/algorithm/trailing_whitespace.html
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<body>
|
||||||
|
<!-- This file deliberately contains trailing whitespace -->
|
||||||
|
<!-- Don't remove them -->
|
||||||
|
<div>
|
||||||
|
a
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
18
tests/indent/algorithm_spec.lua
Normal file
18
tests/indent/algorithm_spec.lua
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
local Runner = require("tests.indent.common").Runner
|
||||||
|
-- local XFAIL = require("tests.indent.common").XFAIL
|
||||||
|
|
||||||
|
local runner = Runner:new(it, "tests/indent/algorithm", {
|
||||||
|
tabstop = 4,
|
||||||
|
shiftwidth = 4,
|
||||||
|
softtabstop = 4,
|
||||||
|
expandtab = true,
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("test indent algorithm: ", function()
|
||||||
|
describe("new line:", function()
|
||||||
|
runner:new_line("trailing.py", { on_line = 1, text = "x: str", indent = 4 }, "indent next line, ignore comment")
|
||||||
|
runner:new_line("trailing.py", { on_line = 4, text = "pass", indent = 8 }, "indent next line, ignore comment")
|
||||||
|
runner:new_line("trailing.py", { on_line = 6, text = "pass", indent = 4 }, "indent next line, ignore whitespace")
|
||||||
|
runner:new_line("trailing_whitespace.html", { on_line = 9, text = "x", indent = 8 }, "not ignore @indent.end")
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue