File: check-isutf8

package info (click to toggle)
moreutils 0.52
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 232 kB
  • ctags: 184
  • sloc: ansic: 1,977; perl: 423; makefile: 35; sh: 35
file content (46 lines) | stat: -rwxr-xr-x 806 bytes parent folder | download | duplicates (3)
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
#!/bin/bash
# Bash needed for the character encodings below.
#
# Run checks for ./isutf8.
#
# Lars Wirzenius <liw@iki.fi>

failed=0

check() {
	printf "$2" | ./isutf8 -q
	ret=$?
	if [ $ret != $1 ]; then
		echo "Failure:"
		echo "  input: $2"
		echo "  expected: $1"
		echo "  got: $ret"
		failed=1
	fi
	printf "$2" > check-isutf8.tmp.$$ 
	./isutf8 -q check-isutf8.tmp.$$
	ret=$?
	rm -f check-isutf8.tmp.$$
	if [ $ret != $1 ]; then
		echo "Failure (from file):"
		echo "  input: $2"
		echo "  expected: $1"
		echo "  got: $ret"
		failed=1
	fi
}

check 0 ''
check 0 'a'
check 0 'ab'
check 0 '\xc2\xa9'

check 1 '\xc2'
check 1 '\xc2\x20'
check 1 '\x20\xc2'
check 1 '\300\200'
check 1 '\xed\xa0\x88\xed\xbd\x85' # UTF-16 surrogates
check 1 '\xef\xbf\xbe' # 0xFFFE
check 1 '\xef\xbf\xbf' # 0xFFFF

exit $failed