Skip to content

Commit 8e55b95

Browse files
committed
Add tests
1 parent 06d6fe0 commit 8e55b95

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

tests/test_sed.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
check_(){
4+
RESULT="$(echo "$3" | sed "$1" "$4")"
5+
if [ "$RESULT" != "$5" ]; then
6+
echo "Test failed: $2" >&2
7+
echo "----- expected -----
8+
$5
9+
----- returned -----"
10+
echo "$RESULT"
11+
exit 1
12+
fi
13+
}
14+
15+
# Check BRE
16+
checkb(){
17+
check_ "-e" "$@"
18+
}
19+
# Check ERE
20+
checke(){
21+
check_ "-E" "$@"
22+
}
23+
# Check both
24+
check(){
25+
checkb "$@"
26+
checke "$@"
27+
}
28+
29+
# Basics
30+
31+
check 'Custom character class' \
32+
'adn
33+
aqv' 's/[b-eq]/x/g' \
34+
'axn
35+
axv'

tests/test_vim.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
check(){
4+
FILE="$(mktemp)"
5+
echo "$2" >"$FILE"
6+
exec 3<<<"$3
7+
:w! $FILE
8+
:q!"
9+
vi - <"$FILE" 2<&3-
10+
if [ "$(cat "$FILE")" != "$4" ]; then
11+
echo "Test failed: $1" >&2
12+
echo "----- expected -----
13+
$4
14+
----- returned -----"
15+
cat "$FILE"
16+
rm "$FILE"
17+
exit 1
18+
fi
19+
rm "$FILE"
20+
}
21+
22+
# Basics
23+
24+
check 'Custom character class' \
25+
'adn
26+
aqv' ':%s/[b-eq]/x/g' \
27+
'axn
28+
axv'

0 commit comments

Comments
 (0)