restores Helder in all its glory
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user