-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·31 lines (26 loc) · 875 Bytes
/
test.sh
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
#!/bin/sh
. ./format.sh
assert() {
expected=$1
actual=$2
if test "$actual" = "$expected"; then
echo "OK: $expected"
else
echo "FAIL: $expected != $actual"
fi
}
assert_fmt() {
assert "$(printf "$1" "$3")" "$(fmt "$2" "$3")"
}
assert_fmt '\033[;31m%s\033[;0m\n' red xxx
assert_fmt '\033[;31;1m%s\033[;0m\n' red,bold xxx
assert_fmt '\033[;1;31m%s\033[;0m\n' bold,red xxx
assert_fmt '\033[;41m%s\033[;0m\n' bg,red xxx
assert_fmt '\033[;21m%s\033[;0m\n' not,bold xxx
assert_fmt '\033[;21;31m%s\033[;0m\n' not,bold,red xxx
assert_fmt '\033[;23;4m%s\033[;0m\n' not,em,u xxx
assert_fmt '\033[;23;4m%s\033[;0m\n' not-em,u xxx
assert_fmt '\033[;41m%s\033[;0m\n' bg-red xxx
assert_fmt '\033[;31m%s\033[;0m\n' fg-red xxx
assert "$(printf '\033[;31mone two\033[;0m\n')" "$(fmt fg-red one two)"
assert "$(printf '\033[;31mone_two\033[;0m\n')" "$(IFS=_ fmt fg-red one two)"