mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
feat(bash): add indents query
It's pretty basic at the moment but already makes working with bash scripts way easier.
This commit is contained in:
parent
86cf4fb684
commit
4337799162
4 changed files with 105 additions and 1 deletions
39
tests/indent/bash/test.sh
Normal file
39
tests/indent/bash/test.sh
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
for i in 1 2 3; do
|
||||
if [[ true ]]; then
|
||||
echo "asd"
|
||||
elif [ true ]; then
|
||||
echo "dsa"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
echo $i
|
||||
done
|
||||
|
||||
while true; do
|
||||
break
|
||||
done
|
||||
|
||||
case $foo in
|
||||
a) echo a ;;
|
||||
b) echo b ;;
|
||||
esac
|
||||
|
||||
function x() {
|
||||
echo x
|
||||
}
|
||||
|
||||
y() {
|
||||
echo y
|
||||
}
|
||||
|
||||
{
|
||||
echo z
|
||||
}
|
||||
|
||||
(
|
||||
echo subshell
|
||||
)
|
||||
|
||||
A=$(
|
||||
echo command substitution
|
||||
)
|
||||
33
tests/indent/bash_spec.lua
Normal file
33
tests/indent/bash_spec.lua
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
local Runner = require('tests.indent.common').Runner
|
||||
local XFAIL = require('tests.indent.common').XFAIL
|
||||
|
||||
local run = Runner:new(it, 'tests/indent/bash', {
|
||||
tabstop = 4,
|
||||
shiftwidth = 4,
|
||||
softtabstop = 0,
|
||||
expandtab = true,
|
||||
})
|
||||
|
||||
describe('indent Bash:', function()
|
||||
describe('whole file:', function()
|
||||
run:whole_file('.', {
|
||||
expected_failures = {},
|
||||
})
|
||||
end)
|
||||
|
||||
describe('new line:', function()
|
||||
run:new_line('test.sh', { on_line = 1, text = 'echo test', indent = 4 }) -- in "for"
|
||||
run:new_line('test.sh', { on_line = 2, text = 'echo test', indent = 8 }) -- in "if"
|
||||
run:new_line('test.sh', { on_line = 4, text = 'echo test', indent = 8 }) -- in "elif"
|
||||
run:new_line('test.sh', { on_line = 6, text = 'echo test', indent = 8 }) -- in "else"
|
||||
run:new_line('test.sh', { on_line = 8, text = 'echo test', indent = 4 }) -- after "fi"
|
||||
run:new_line('test.sh', { on_line = 12, text = 'echo test', indent = 4 }) -- in "while"
|
||||
run:new_line('test.sh', { on_line = 18, text = 'c) echo test ;;', indent = 4 }) -- in "case"
|
||||
run:new_line('test.sh', { on_line = 21, text = 'echo test', indent = 4 }) -- in "function"
|
||||
run:new_line('test.sh', { on_line = 25, text = 'echo test', indent = 4 }) -- in "f() { ... }"
|
||||
run:new_line('test.sh', { on_line = 29, text = 'echo test', indent = 4 }) -- in "{ ... }"
|
||||
run:new_line('test.sh', { on_line = 33, text = 'echo test', indent = 4 }) -- in subshell
|
||||
run:new_line('test.sh', { on_line = 37, text = 'echo test', indent = 4 }) -- in command substitution
|
||||
run:new_line('test.sh', { on_line = 39, text = 'echo test', indent = 0 })
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue