summaryrefslogtreecommitdiff
path: root/check-isutf8
diff options
context:
space:
mode:
Diffstat (limited to 'check-isutf8')
-rwxr-xr-xcheck-isutf846
1 files changed, 46 insertions, 0 deletions
diff --git a/check-isutf8 b/check-isutf8
new file mode 100755
index 0000000..83a4eed
--- /dev/null
+++ b/check-isutf8
@@ -0,0 +1,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