Files
tree-sitter-shellspec/test/spec/11.matcher_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

119 lines
2.8 KiB
Bash

# shellcheck shell=sh
Describe 'matcher example'
Describe 'status matchers'
Describe 'be success matcher'
It 'checks if status is successful'
When call true
The status should be success # status is 0
End
End
Describe 'be failure matcher'
It 'checks if status is failed'
When call false
The status should be failure # status is 1-255
End
End
# If you want to check status number, use equal matcher.
End
Describe 'stat matchers'
Describe 'exists'
It 'checks if path exists'
The path 'data.txt' should exist
End
It 'checks if path is file'
The path 'data.txt' should be file
End
It 'checks if path is directory'
The path 'data.txt' should be directory
End
End
# There are many other stat matchers.
# be empty, be symlink, be pipe, be socket, be readable, be writable,
# be executable, be block_device, be character_device,
# has setgid, has setuid
End
Describe 'variable matchers'
Before 'prepare'
Describe 'be defined'
prepare() { var=''; }
It 'checks if variable is defined'
The value "$var" should be defined
End
End
Describe 'be undefined'
prepare() { unset var; }
It 'checks if variable is undefined'
The variable var should be undefined
End
End
Describe 'be present'
prepare() { var=123; }
It 'checks if variable is present'
The value "$var" should be present # non-zero length string
End
End
Describe 'be blank'
prepare() { var=""; }
It 'checks if variable is blank'
The value "$var" should be blank # unset or zero length string
End
End
End
Describe 'string matchers'
Describe 'equal'
It 'checks if subject equals specified string'
The value "foobarbaz" should equal "foobarbaz"
End
End
Describe 'start with'
It 'checks if subject start with specified string'
The value "foobarbaz" should start with "foo"
End
End
Describe 'end with'
It 'checks if subject end with specified string'
The value "foobarbaz" should end with "baz"
End
End
Describe 'include'
It 'checks if subject include specified string'
The value "foobarbaz" should include "bar"
End
End
Describe 'match'
It 'checks if subject match specified pattern'
# Using shell script's pattern matching
The value "foobarbaz" should match pattern "f??bar*"
End
End
End
Describe 'satisfy matcher'
formula() {
eval "value=${formula:?}"
[ $(($1)) -eq 1 ]
}
It 'checks if satisfy condition'
The value 10 should satisfy formula "value >= 5"
End
End
End