-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathabbr-add.ztr.zsh
156 lines (123 loc) · 6.16 KB
/
abbr-add.ztr.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env zsh
main() {
emulate -LR zsh
{
ZTR_TEARDOWN_FN() {
emulate -LR zsh
abbr erase $test_abbr_abbreviation
}
abbr add $test_abbr_abbreviation=$test_abbr_expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $test_abbr_expansion ]]' \
"Can add an abbreviation with the add subcommand" \
"Dependencies: erase, expand"
abbr -S add $test_abbr_abbreviation=$test_abbr_expansion
ztr test '[[ $(abbr -S expand $test_abbr_abbreviation) == $test_abbr_expansion ]]' \
"Can add a regular session abbreviation with the add subcommand, with the flag before the command" \
"Dependencies: erase, expand"
abbr add $test_abbr_abbreviation=$test_abbr_expansion -S
ztr test '[[ $(abbr -S expand $test_abbr_abbreviation) == $test_abbr_expansion ]]' \
"Can add a regular session abbreviation with the add subcommand, with the flag after the command args" \
"Dependencies: erase, expand"
abbr add -S $test_abbr_abbreviation=$test_abbr_expansion
ztr test '[[ $(abbr -S expand $test_abbr_abbreviation) == $test_abbr_expansion ]]' \
"Can add a regular session abbreviation with the add subcommand, with the flag between the command and its args" \
"Dependencies: erase, expand"
# Manual
echo "abbr \"$test_abbr_abbreviation\"=\"$test_abbr_expansion\"" > $ABBR_USER_ABBREVIATIONS_FILE
abbr load
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $test_abbr_expansion ]]' \
"Can add a user abbreviation from outside abbr without data loss" \
"Dependencies: erase, expand"
# Implicit
abbr $test_abbr_abbreviation=$test_abbr_expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $test_abbr_expansion ]]' \
"Can add an abbreviation without the add subcommand" \
"Dependencies: erase, expand"
abbr $test_abbr_abbreviation_multiword=$test_abbr_expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation_multiword) == $test_abbr_expansion ]]' \
"Can add a multi-word abbreviation without the add subcommand" \
"Dependencies: erase, expand"
abbr erase $test_abbr_abbreviation_multiword
# Global
abbr add -g $test_abbr_abbreviation=$test_abbr_expansion
ztr test '[[ $(abbr -g expand $test_abbr_abbreviation) == $test_abbr_expansion ]]' \
"Can add a global abbreviation with the add subcommand" \
"Dependencies: erase, expand"
abbr add -S -g $test_abbr_abbreviation=$test_abbr_expansion
ztr test '[[ $(abbr -g -S expand $test_abbr_abbreviation) == $test_abbr_expansion ]]' \
"Can add a global session abbreviation with the add subcommand" \
"Dependencies: erase, expand"
# Multiword
abbr add $test_abbr_abbreviation_multiword=$test_abbr_expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation_multiword) == $test_abbr_expansion ]]' \
"Can add a multi-word abbreviation with the add subcommand" \
"Dependencies: erase, expand"
abbr erase $test_abbr_abbreviation_multiword
abbr add -S $test_abbr_abbreviation_multiword=$test_abbr_expansion
ztr test '[[ $(abbr -S expand $test_abbr_abbreviation_multiword) == $test_abbr_expansion ]]' \
"Can add a multi-word regular session abbreviation with the add subcommand" \
"Dependencies: erase, expand"
abbr erase $test_abbr_abbreviation_multiword
# Multiword global
abbr add -g $test_abbr_abbreviation_multiword=$test_abbr_expansion
ztr test '[[ $(abbr -g expand $test_abbr_abbreviation_multiword) == $test_abbr_expansion ]]' \
"Can add a multi-word global abbreviation with the add subcommand" \
"Dependencies: erase, expand"
abbr erase $test_abbr_abbreviation_multiword
abbr add -S -g $test_abbr_abbreviation_multiword=$test_abbr_expansion
ztr test '[[ $(abbr -g -S expand $test_abbr_abbreviation_multiword) == $test_abbr_expansion ]]' \
"Can add a multi-word global session abbreviation with the add subcommand" \
"Dependencies: erase, expand"
abbr erase $test_abbr_abbreviation_multiword
# Quotes
expansion='b'cd
abbr $test_abbr_abbreviation=$expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $expansion ]]' \
"Bare single quotes at the start of the expansion are swallowed" \
"Dependencies: erase, expand"
expansion=b'c'd
abbr $test_abbr_abbreviation=$expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $expansion ]]' \
"Bare single quotes in the middle of the expansion are swallowed" \
"Dependencies: erase, expand"
expansion='b"c"d'
abbr $test_abbr_abbreviation=$expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $expansion ]]' \
"Single-quoted double quotes in the expansion are preserved" \
"Dependencies: erase, expand"
expansion="b"cd
abbr $test_abbr_abbreviation=$expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $expansion ]]' \
"Bare double quotes at the start of the expansion are swallowed" \
"Dependencies: erase, expand"
expansion=b"c"d
abbr $test_abbr_abbreviation=$expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $expansion ]]' \
"Bare double quotes in the middle of the expansion are swallowed" \
"Dependencies: erase, expand"
expansion="b'c'd"
abbr $test_abbr_abbreviation=$expansion
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $expansion ]]' \
"Double-quoted single quotes in the expansion are preserved" \
"Dependencies: erase, expand"
# Force
abbr add $test_abbr_abbreviation=$test_abbr_expansion
abbr add $test_abbr_abbreviation=$test_abbr_expansion_2
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $test_abbr_expansion ]]' \
"Cannot change an abbreviation's expansion" \
"Dependencies: erase, expand"
abbr add $test_abbr_abbreviation=$test_abbr_expansion
abbr add --force $test_abbr_abbreviation=$test_abbr_expansion_2
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $test_abbr_expansion_2 ]]' \
"Cannot change an abbreviation's expansion with --force" \
"Dependencies: erase, expand"
abbr add $test_abbr_abbreviation=$test_abbr_expansion
abbr add -f $test_abbr_abbreviation=$test_abbr_expansion_2
ztr test '[[ $(abbr expand $test_abbr_abbreviation) == $test_abbr_expansion_2 ]]' \
"Cannot change an abbreviation's expansion with -f" \
"Dependencies: erase, expand"
} always {
unfunction -m ZTR_TEARDOWN_FN
}
}
main