Skip to content

Commit a4f328b

Browse files
committed
Convert sed tests to ViM
1 parent d98bec2 commit a4f328b

File tree

1 file changed

+179
-1
lines changed

1 file changed

+179
-1
lines changed

tests/test_vim.sh

+179-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/bin/bash
22

3+
export LC_ALL=en_US.UTF-8
4+
35
check(){
46
FILE="$(mktemp)"
57
echo "$2" >"$FILE"
68
exec 3<<<"$3
79
:w! $FILE
810
:q!"
9-
vi - <"$FILE" 2<&3-
11+
vi -u NONE - <"$FILE" 2<&3-
1012
if [ "$(cat "$FILE")" != "$4" ]; then
1113
echo "Test failed: $1" >&2
1214
echo "----- expected -----
@@ -26,3 +28,179 @@ check 'Custom character class' \
2628
aqv' ':%s/[b-eq]/x/g' \
2729
'axn
2830
axv'
31+
32+
check 'Negated custom character class' \
33+
'abcdefgh' \
34+
':%s/[^b-dg-l]/x/g' \
35+
'xbcdxxgh'
36+
37+
check 'Backslash not special in class' \
38+
"a]\\b
39+
a]\\b" \
40+
":1s/[\\m-p]/x/g
41+
:2s/[]]/x/g" \
42+
"a]xb
43+
ax\\b"
44+
45+
check 'Ranges' \
46+
'a-e-i
47+
a-e-i' \
48+
':1s/[d-f]/x/g
49+
:2s/[d-f-]/x/g' \
50+
'a-x-i
51+
axxxi'
52+
53+
check 'Alternation' \
54+
'acd' \
55+
':%s/b\|c/x/g' \
56+
'axd'
57+
58+
check 'Escaped character' \
59+
'abc' \
60+
":%s/\\061\\x62\\x(99)/x/g" \
61+
'abc'
62+
63+
# Charater classes
64+
65+
check 'Any character' \
66+
'a ;d
67+
efg' \
68+
':%s/./x/g' \
69+
'xxxx
70+
xxx'
71+
72+
check 'Word character' \
73+
'hello w0r|_d!' \
74+
':%s/\w/x/g' \
75+
'xxxxx xxx|xx!'
76+
77+
check 'Upper case' \
78+
'Hell0 W0r|_D' \
79+
':%s/[[:upper:]]/X/g' \
80+
'Xell0 X0r|_X'
81+
82+
check 'Lower case' \
83+
'Hell0 W0r|_D' \
84+
':%s/[[:lower:]]/x/g' \
85+
'Hxxx0 W0x|_D'
86+
87+
check 'Whitespace' \
88+
'Hello world !' \
89+
':%s/\s/_/g' \
90+
'Hello_world_!'
91+
92+
check 'Whitespace' \
93+
'Hello world !' \
94+
':%s/[[:space:]]/_/g' \
95+
'Hello_world_!'
96+
97+
check 'Non-whitespace' \
98+
'Hello world !' \
99+
':%s/[^[:space:]]/x/g' \
100+
'xxxxx xxxxx x'
101+
102+
check 'Digit' \
103+
'H3ll0 W0r|_D' \
104+
':%s/[[:digit:]]/+/g' \
105+
'H+ll+ W+r|_D'
106+
107+
check 'Hexadecimal digit' \
108+
'H3ll0 W0r|_D' \
109+
':%s/[[:xdigit:]]/+/g' \
110+
'H+ll+ W+r|_+'
111+
112+
check 'Punctuation' \
113+
'+- 01: hello, world! ;) -+' \
114+
':%s/[[:punct:]]/_/g' \
115+
'__ 01_ hello_ world_ __ __'
116+
117+
check 'Alphabetical characters' \
118+
'+- 01: hello, world! ;) -+' \
119+
':%s/[[:alpha:]]/x/g' \
120+
'+- 01: xxxxx, xxxxx! ;) -+'
121+
122+
check 'Alphanumerical characters' \
123+
'+- 01: hello, world! ;) -+' \
124+
':%s/[[:alnum:]]/x/g' \
125+
'+- xx: xxxxx, xxxxx! ;) -+'
126+
127+
check 'Character equivalents' \
128+
'Rémi est prêt' \
129+
':%s/[[=e=]]/_/g' \
130+
'R_mi _st pr_t'
131+
132+
check 'Word boundary' \
133+
'Hello, world' \
134+
':%s/o\>/x/g' \
135+
'Hellx, world'
136+
137+
check 'Begining of line' \
138+
'testing tests' \
139+
':%s/^t/r/g' \
140+
'resting tests'
141+
142+
check 'End of line' \
143+
'testing tests' \
144+
':%s/s$/x/g' \
145+
'testing testx'
146+
147+
# Captures and groups
148+
149+
check 'Capturing group' \
150+
'Name is Remi!' \
151+
':%s/^.*is \(.*\)!$/\1/' \
152+
'Remi'
153+
154+
check 'Non-capturing parentheses' \
155+
'Some (dumb)text' \
156+
':%s/(.*)//g' \
157+
'Some text'
158+
159+
check 'Backreference' \
160+
'ab be cd cc df' \
161+
':%s/\([a-z]\)\1/xx/g' \
162+
'ab be cd xx df'
163+
164+
# Look-around not supported in POSIX
165+
166+
# Multiplicity
167+
168+
check '0 or 1' \
169+
'bb bab baab baa?b baaab' \
170+
':%s/baa\?b/x/g' \
171+
'bb x x baa?b baaab'
172+
173+
check '0 or 1 (negative)' \
174+
'bb bab baab baa?b baaab' \
175+
':%s/baa?b/x/g' \
176+
'bb bab baab x baaab'
177+
178+
check '1 or more' \
179+
'bb bab baab ba+b baaab' \
180+
':%s/ba\+b/x/g' \
181+
'bb x x ba+b x'
182+
183+
check '1 or more (negative)' \
184+
'bb bab baab ba+b baaab' \
185+
':%s/ba+b/x/g' \
186+
'bb bab baab x baaab'
187+
188+
check 'Specific number (1)' \
189+
'bb bab baab baaab baaaab' \
190+
':%s/ba\{2\}b/x/g' \
191+
'bb bab x baaab baaaab'
192+
193+
check 'Specific number (closed)' \
194+
'bb bab baab baaab baaaab' \
195+
':%s/ba\{1,3\}b/x/g' \
196+
'bb x x x baaaab'
197+
198+
check 'Specific number (open left)' \
199+
'bb bab baaab baaaab' \
200+
':%s/ba\{,3\}b/x/g' \
201+
'x x x baaaab'
202+
203+
check 'Specific number (open right)' \
204+
'bb bab baaab baaaab' \
205+
':%s/ba\{2,\}b/x/g' \
206+
'bb bab x x'

0 commit comments

Comments
 (0)