]> err.no Git - moreutils/blob - check-isutf8
Update name one more place
[moreutils] / check-isutf8
1 #!/bin/bash
2 # Bash needed for the character encodings below.
3 #
4 # Run checks for ./isutf8.
5 #
6 # Lars Wirzenius <liw@iki.fi>
7
8 failed=0
9
10 check() {
11         printf "$2" | ./isutf8 -q
12         ret=$?
13         if [ $ret != $1 ]; then
14                 echo "Failure:"
15                 echo "  input: $2"
16                 echo "  expected: $1"
17                 echo "  got: $ret"
18                 failed=1
19         fi
20         printf "$2" > check-isutf8.tmp.$$ 
21         ./isutf8 -q check-isutf8.tmp.$$
22         ret=$?
23         rm -f check-isutf8.tmp.$$
24         if [ $ret != $1 ]; then
25                 echo "Failure (from file):"
26                 echo "  input: $2"
27                 echo "  expected: $1"
28                 echo "  got: $ret"
29                 failed=1
30         fi
31 }
32
33 check 0 ''
34 check 0 'a'
35 check 0 'ab'
36 check 0 '\xc2\xa9'
37
38 check 1 '\xc2'
39 check 1 '\xc2\x20'
40 check 1 '\x20\xc2'
41 check 1 '\300\200'
42 check 1 '\xed\xa0\x88\xed\xbd\x85' # UTF-16 surrogates
43 check 1 '\xef\xbf\xbe' # 0xFFFE
44 check 1 '\xef\xbf\xbf' # 0xFFFF
45
46 exit $failed