xref: /openbsd-src/regress/lib/libedit/read/test_read_char.sh (revision d4e67a97b48f1b52d1ab469d4665694e452560c5)
1#!/bin/sh
2# $OpenBSD: test_read_char.sh,v 1.3 2017/07/05 15:31:45 bluhm Exp $
3#
4# Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
5#
6# Permission to use, copy, modify, and distribute this software for any
7# purpose with or without fee is hereby granted, provided that the above
8# copyright notice and this permission notice appear in all copies.
9#
10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18testrc()
19{
20	stdin=$1
21	e_utf8=$2
22	e_ascii=$3
23	[ -n "$e_ascii" ] || e_ascii=$e_utf8
24	result=`echo -n "$stdin" | LC_CTYPE=en_US.UTF-8 ./test_read_char`
25	if [ "$result" != "${e_utf8}" ]; then
26		echo "input:    >>>$stdin<<<"
27		echo "expected: >>>$e_utf8<<< UTF-8"
28		echo "result:   >>>$result<<<"
29		exit 1;
30	fi
31	result=`echo -n "$stdin" | LC_CTYPE=C ./test_read_char`
32	if [ "$result" != "${e_ascii}" ]; then
33		echo "input:    >>>$stdin<<<"
34		echo "expected: >>>$e_ascii<<< ASCII"
35		echo "result:   >>>$result<<<"
36		exit 1;
37	fi
38}
39
40# Valid ASCII.
41testrc "" "0."
42testrc "a" "61,0."
43testrc "ab" "61,62,0."
44
45# Valid UTF-8.
46testrc "\0303\0251" "e9,0." "c3,a9,0."
47
48# Incomplete UTF-8.
49testrc "\0303" "0." "c3,0."
50testrc "\0303a" "*61,0." "c3,61,0."
51testrc "\0303ab" "*61,62,0." "c3,61,62,0."
52
53# UTF-16 surrogate.
54testrc "\0355\0277\0277ab" "*61,62,0." "ed,bf,bf,61,62,0."
55
56# Isolated UTF-8 continuation bytes.
57testrc "\0200" "*0." "80,0."
58testrc "\0200ab" "*61,62,0." "80,61,62,0."
59testrc "a\0200bc" "61,*62,63,0." "61,80,62,63,0."
60testrc "\0200\0303\0251" "*e9,0." "80,c3,a9,0."
61testrc "\0200\0303ab" "*61,62,0." "80,c3,61,62,0."
62
63# Invalid bytes.
64testrc "\0377ab" "*61,62,0." "ff,61,62,0."
65testrc "\0355\0277\0377ab" "*61,62,0." "ed,bf,ff,61,62,0."
66
67exit 0
68