summaryrefslogtreecommitdiff
path: root/regress/usr.bin/colrm/colrm.sh
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2015-12-22 22:37:58 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2015-12-22 22:37:58 +0000
commit3b0ffdfc72b9d7b6ad81fd7e1a785ada06f1bfd1 (patch)
tree6fb82ac9427600f9a911bfd16a3055c09a62a896 /regress/usr.bin/colrm/colrm.sh
parentbb6f8e5337a9af40f4e8874cb3c4e1073c6dae10 (diff)
Test suite for colrm(1) including tests for single byte characters,
tabs, backspaces, multibyte characters of width 1, 0, and 2, invalid bytes and non-printable characters. All tests are run both with the UTF-8 and the C locale. About half the tests are currently broken, and not only the multibyte tests, but also half of the tab and backspace tests. The program is expected to be fixed soon, and the suite will be hooked up after that.
Diffstat (limited to 'regress/usr.bin/colrm/colrm.sh')
-rw-r--r--regress/usr.bin/colrm/colrm.sh100
1 files changed, 100 insertions, 0 deletions
diff --git a/regress/usr.bin/colrm/colrm.sh b/regress/usr.bin/colrm/colrm.sh
new file mode 100644
index 00000000000..f50e95b276e
--- /dev/null
+++ b/regress/usr.bin/colrm/colrm.sh
@@ -0,0 +1,100 @@
+#!/bin/sh
+#
+# Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+unset LC_ALL
+
+test_colrm()
+{
+ args=$1
+ stdin=$2
+ expected=`echo -n "$3."`
+ export LC_CTYPE=en_US.UTF-8
+ result=`echo -n "$stdin" | colrm $args ; echo -n .`
+ if [ "$result" != "${expected}" ]; then
+ echo "echo -n \"$stdin\" | colrm $args"
+ echo "expected: \"$expected\""
+ echo "result: \"$result\""
+ exit 1;
+ fi
+
+ if [ -n "$4" ]; then
+ expected=`echo -n "$4."`
+ fi
+ export LC_CTYPE=C
+ result=`echo -n "$stdin" | colrm $args ; echo -n .`
+ if [ "$result" != "${expected}" ]; then
+ echo "[C] echo -n \"$stdin\" | colrm $args"
+ echo "expected: \"$expected\""
+ echo "result: \"$result\""
+ exit 1;
+ fi
+}
+
+# single byte characters
+test_colrm "" "abcd" "abcd"
+test_colrm "2" "abcd" "a"
+test_colrm "5" "abcd" "abcd"
+test_colrm "2 3" "abcd" "ad"
+test_colrm "5 6" "abcd" "abcd"
+
+# tab characters
+test_colrm "" "a\tb" "a\tb"
+test_colrm "10" "\tab" "\ta"
+test_colrm "9" "\tab" "\t"
+test_colrm "8" "\tab" " "
+test_colrm "3 7" "a\tb" "a b"
+test_colrm "7 9" "abcd\txe" "abcd e"
+test_colrm "3 6" "abcd\tef" "ab ef"
+
+# zero width
+test_colrm "2 2" "ax̀b" "ab" "àb"
+test_colrm "3 3" "ax̀bx̀c" "ax̀x̀c" \
+ "ax€bxÌ€c"
+
+# double width
+test_colrm "2 3" "aì¿¿b" "ab" "a¿b"
+test_colrm "2 2" "aì¿¿b" "a b" "a¿¿b"
+test_colrm "3 3" "aì¿¿b" "a b" "aì¿b"
+test_colrm "4 4" "aì¿¿bì¿¿c" "aì¿¿ì¿¿c" \
+ "aì¿bì¿¿c"
+
+# backspaces
+test_colrm "3 3" "ab_cd_e" "ab_d_e"
+test_colrm "2 2" "ab_c" "ac"
+test_colrm "2 2" "ax̀b" "ab" "àb"
+test_colrm "3 3" "ax̀bx̀c" "ax̀x̀c" \
+ "ax€bxÌ€c"
+test_colrm "2 3" "aì¿¿bcde" "ade" "a¿bcde"
+test_colrm "2 2" "aì¿¿bcde" "acde" "a¿¿bcde"
+test_colrm "3 3" "aì¿¿bcde" "abde" "aì¿bcde"
+test_colrm "4 4" "aì¿¿bì¿¿c" "aì¿¿ì¿¿c" \
+ "aì¿bì¿¿c"
+test_colrm "" "\bx" "\bx"
+test_colrm "1" "\bx" "\b"
+
+# invalid bytes and non-printable characters
+test_colrm "3 3" "aÿbÿc" "aÿÿc"
+test_colrm "2 2" "aÿb" "ab"
+test_colrm "3 3" "abc" "ac"
+test_colrm "2 2" "ab" "ab"
+test_colrm "3 3" "a͸b͸c" "a͸͸c" "aÍb͸c"
+test_colrm "2 2" "a͸b" "ab" "a¸b"
+
+# edge cases
+test_colrm "" "" ""
+test_colrm "2 2" "\n" "\n"
+
+exit 0