This commit is contained in:
ge
2025-07-12 03:07:50 +03:00
commit a5f7006065
6 changed files with 403 additions and 0 deletions

27
shell_test.v Normal file
View File

@@ -0,0 +1,27 @@
import shell
// TODO: pass all tests from https://github.com/python/cpython/blob/main/Lib/test/test_shlex.py
fn test_quote() {
assert shell.quote("janna d'arc") == '\'janna d\'"\'"\'arc\''
}
fn test_join() {
assert shell.join(['sh', '-c', 'hostname -f']) == "sh -c 'hostname -f'"
}
fn test_split() {
assert shell.split("sh -c 'hostname -f'") == ['sh', '-c', 'hostname -f']
assert shell.split('sh -c hostname') == ['sh', '-c', 'hostname']
assert shell.split('hostname -f # some comment') == ['hostname', '-f', '#', 'some', 'comment']
assert shell.split('hostname -f # some comment', comments: true) == ['hostname', '-f']
assert shell.split('grep -rn "#"') == ['grep', '-rn', '#']
assert shell.split('grep -rn "#"', comments: true) == ['grep', '-rn', '#']
// FIXME: both assertions fails
// s := 'grep -rn hello # search hello
// awk --help
// '.trim_indent()
// assert shell.split(s) == ['grep', '-rn', 'hello', '#', 'search', 'hello', 'awk', '--help']
// assert shell.split(s, comments: true) == ['grep', '-rn', 'hello', 'awk', '--help']
}