Add indentation tests

This commit is contained in:
Bruno BELANYI 2024-04-13 17:04:55 +01:00
parent f8f328fa17
commit 0ca28eb2e9
3 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,22 @@
foo = 1 + 2
foo = [
1,
2,
3,
]
foo = {
foo: [
"bar",
],
},
foo = {
foo: [
"bar",
{
key: "value",
},
],
},

28
test/indent/select.bp Normal file
View file

@ -0,0 +1,28 @@
foo = select(variant("VARIANT"), {
"x86": "my_x86",
"x86_64": [
"x86",
"x64",
],
"arm": {
some: "aarch",
value: "aarch64",
},
default: 0,
})
foo = select(
variant("VARIANT"),
{
"x86": "my_x86",
"x86_64": [
"x86",
"x64",
],
"arm": {
some: "aarch",
value: "aarch64",
},
default: 0,
}
)

47
test/indent_spec.lua Normal file
View file

@ -0,0 +1,47 @@
package.path = package.path .. ";" .. vim.env.NVIM_TREESITTER .. "/?.lua"
local Runner = require("tests.indent.common").Runner
-- FIXME: path to root
local runner = Runner:new(it, ".", {
tabstop = 4,
shiftwidth = 4,
softtabstop = 0,
expandtab = true,
})
describe("indent Blueprint:", function()
describe("whole file:", function()
runner:whole_file("test/highlight/", {
expected_failures = {
-- NOTE: none for now
},
})
runner:whole_file("test/indent/", {
expected_failures = {
-- NOTE: none for now
},
})
end)
describe("new line:", function()
runner:new_line("test/indent/expressions.bp", { on_line = 2, text = "foo = 42", indent = 0 }, "variable declaration")
runner:new_line("test/indent/expressions.bp", { on_line = 4, text = "0,", indent = 4 }, "list element")
runner:new_line("test/indent/expressions.bp", { on_line = 6, text = "]", indent = 0 }, "list closing delimiter")
runner:new_line("test/indent/expressions.bp", { on_line = 9, text = "key: 42", indent = 4 }, "map property")
runner:new_line("test/indent/expressions.bp", { on_line = 12, text = "key: 42", indent = 4 }, "map property, trailing")
runner:new_line("test/indent/expressions.bp", { on_line = 9, text = "}", indent = 0 }, "map closing delimiter")
runner:new_line("test/indent/expressions.bp", { on_line = 11, text = "]", indent = 4 }, "nested list closing delimiter")
runner:new_line("test/indent/expressions.bp", { on_line = 18, text = "key: 42", indent = 12 }, "nested map property")
runner:new_line("test/indent/expressions.bp", { on_line = 19, text = "key: 42", indent = 12 }, "nested map property, trailing")
runner:new_line("test/indent/select.bp", { on_line = 1, text = '"case": "value"', indent = 4 }, "select case")
runner:new_line("test/indent/select.bp", { on_line = 1, text = 'default: "value"', indent = 4 }, "default case")
runner:new_line("test/indent/select.bp", { on_line = 11, text = '"case": "value"', indent = 4 }, "select case, trailing")
runner:new_line("test/indent/select.bp", { on_line = 11, text = 'default: "value"', indent = 4 }, "default case, trailing")
runner:new_line("test/indent/select.bp", { on_line = 16, text = '"case": "value"', indent = 8 }, "select case, alternate formatting")
runner:new_line("test/indent/select.bp", { on_line = 16, text = 'default: "value"', indent = 8 }, "default case, alternate formatting")
runner:new_line("test/indent/select.bp", { on_line = 26, text = '"case": "value"', indent = 8 }, "select case, trailing, alternate formattingg")
runner:new_line("test/indent/select.bp", { on_line = 26, text = 'default: "value"', indent = 8 }, "default case, trailing, alternate formattingn")
end)
end)