Files
tree-sitter-shellspec/test/spec/16.text_directive_spec.sh
Ismo Vuorinen 193f8871b6 fix: apply CodeRabbit nitpick suggestions and improve code quality
- Fix grammar.js TypeScript errors by correcting optional field usage
- Update .yamlignore to use more robust glob pattern (**/node_modules/**)
- Remove hard-coded test count from README.md for maintainability
- Fix shellcheck directive format (add space after #) in all test specs
- Fix typos throughout test specifications:
  - 'can not' → 'cannot'
  - 'expantion' → 'expansion'
  - 'singnal' → 'signal'
  - 'It mean' → 'It means'
- Update CODE_OF_CONDUCT.md HTTP links to HTTPS
- Update tree-sitter parse command to use --scope instead of --language
- Add comments to .mega-linter.yml explaining disabled linters

All grammar tests still pass (61/61) and the parser functions correctly
with the updated tree-sitter CLI v0.25.0.
2026-01-04 15:32:39 +02:00

94 lines
1.7 KiB
Bash

# shellcheck shell=sh disable=SC2016
# %text directive is easy way to output text like here document.
# Removes `#|` from the beginning of the each line in the %text directive,
# the rest is the output text.
Describe '%text directive'
It 'outputs texts'
output() {
echo "start" # you can write code here
%text
#|aaa
#|bbb
#|ccc
echo "end" # you can write code here
}
When call output
The line 1 of output should eq 'start'
The line 2 of output should eq 'aaa'
The line 3 of output should eq 'bbb'
The line 4 of output should eq "ccc"
The line 5 of output should eq 'end'
End
It 'sets to variable'
output() {
texts=$(
%text
#|aaa
#|bbb
#|ccc
)
echo "$texts"
}
When call output
The line 1 of output should eq 'aaa'
The line 2 of output should eq 'bbb'
The line 3 of output should eq "ccc"
End
It 'outputs texts with filter'
output() {
%text | tr 'a-z_' 'A-Z_'
#|abc
}
When call output
The output should eq 'ABC'
End
Describe 'variable expansion'
Before 'text=abc'
Example 'not expand variable (default)'
output() {
%text:raw
#|$text
}
When call output
The output should eq '$text'
End
Example 'expand variable'
output() {
%text:expand
#|$text
}
When call output
The output should eq 'abc'
End
End
It 'outputs texts with more complex code'
output() {
if true; then
set -- 1 2 3 4 5
while [ $# -gt 0 ]; do
%text:expand | tr 'a-z_' 'A-Z_'
#|value $(($1 * 10))
shift
done
else
%text
#|text
fi
}
When call output
The line 1 of output should eq 'VALUE 10'
The line 2 of output should eq 'VALUE 20'
The line 3 of output should eq 'VALUE 30'
The line 4 of output should eq "VALUE 40"
The line 5 of output should eq 'VALUE 50'
End
End