restores Helder in all its glory

This commit is contained in:
2026-09-28 11:34:49 +02:00
parent c2b38b853c
commit 1d29d0952d
280 changed files with 29205 additions and 7 deletions
@@ -0,0 +1,52 @@
import HelderCore
import Testing
@Suite struct ShellGrammarTests {
@Test("keywords, builtins, variables and strings")
func basics() {
let text = "if [ -n \"$HOME\" ]; then echo \"dir: ${HOME}/x\" 'no $sub'; fi"
#expect(role("if", in: text, .bash) == .keyword)
#expect(role("$HOME", in: text, .bash) == .variable)
#expect(role("echo", in: text, .bash) == .number)
#expect(role("${HOME}", in: text, .bash) == .variable)
#expect(role("'no $sub'", in: text, .bash) == .string)
#expect(role("fi", in: text, .bash) == .keyword)
}
@Test("a hash inside a word is not a comment")
func hashInWord() {
let text = "echo a#b # real"
#expect(role("a#b", in: text, .bash) == .plain)
#expect(role("# real", in: text, .bash) == .comment)
}
@Test("a heredoc runs to its marker; a quoted marker turns interpolation off")
func heredoc() {
let text = "cat <<EOF\nhi $USER\nEOF\ncat <<'RAW'\n$keep\nRAW\necho done"
#expect(role("hi ", in: text, .bash) == .string)
#expect(role("$USER", in: text, .bash) == .variable)
#expect(role("$keep", in: text, .bash) == .string)
#expect(role("echo", in: text, .bash) == .number)
}
@Test("a .env file reads keys as assignments")
func dotenv() {
let text = "APP_NAME=Helder\n# comment\nDB_PASSWORD=\"s3cret\""
#expect(role("APP_NAME", in: text, .bash) == .variable)
#expect(role("# comment", in: text, .bash) == .comment)
#expect(role("\"s3cret\"", in: text, .bash) == .string)
}
@Test("a quoted string may span lines")
func multiLineString() {
let text = "msg=\"one\ntwo\"\necho x"
#expect(role("two\"", in: text, .bash) == .string)
#expect(role("echo", in: text, .bash) == .number)
}
@Test("dashes in a command name do not start a keyword")
func dashedWords() {
#expect(role("apt-get", in: "apt-get install -y done-thing", .bash) == .plain)
#expect(role("done-thing", in: "apt-get install -y done-thing", .bash) == .plain)
}
}