-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.zsh
executable file
·42 lines (38 loc) · 978 Bytes
/
test.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env zsh
source ./toggle-command-prefix.zsh
setopt extendedglob
autoload _sudo
# replacements
tests=(
'basic cmd' 'sudo basic cmd'
'sudo basic cmd' 'basic cmd'
'sudo -u user --group=foo basic cmd' 'basic cmd'
'after ; cmd' 'after ; sudo cmd'
'after ; sudo cmd' 'after ; cmd'
'after; cmd' 'after; sudo cmd'
'after; sudo cmd' 'after; cmd'
'after;cmd' 'after;sudo cmd'
'after;sudo cmd' 'after;cmd'
'after ; if cmd' 'after ; if sudo cmd'
'after ; if sudo cmd' 'after ; if cmd'
'var=val cmd' 'var=val sudo cmd'
'var=val sudo cmd' 'var=val cmd'
'"var=val" foo' 'sudo "var=val" foo'
)
# false positives
tests+=(
'bad if cmd' 'sudo bad if cmd'
'sudo bad if cmd' 'bad if cmd'
'bad sudo cmd' 'sudo bad sudo cmd'
'sudo bad sudo cmd' 'bad sudo cmd'
)
for test out in $tests; do
BUFFER=$test
integer CURSOR=$#test
.toggle-sudo
if [[ $BUFFER != $out ]]; then
print "test failed: $test"
print "Should be : $out"
print "actual : $BUFFER"
fi
done