libbb/lineedit: add support for preserving "broken" (non-unicode) chars
[oweals/busybox.git] / testsuite / ash.tests
1 #!/bin/sh
2 #
3 # These are not ash tests, we use ash as a way to test lineedit!
4 #
5 # Copyright 2010 by Denys Vlasenko
6 # Licensed under GPL v2, see file LICENSE for details.
7
8 . ./testing.sh
9
10 test -f "$bindir/.config" && . "$bindir/.config"
11
12 # testing "test name" "options" "expected result" "file input" "stdin"
13
14 if test x"$CONFIG_UNICODE_PRESERVE_BROKEN" = x"y"; then
15 testing "One byte which is not valid unicode char followed by valid input" \
16         "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
17         "\
18 00000000  ff 2d 0a                                          |.-.|
19 00000003
20 " \
21         "" \
22         "echo \xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
23
24 testing "30 bytes which are not valid unicode chars followed by valid input" \
25         "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
26         "\
27 00000000  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  |................|
28 00000010  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff 2d 0a  |..............-.|
29 00000020
30 " \
31         "" \
32         "echo \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
33 else
34 testing "One byte which is not valid unicode char followed by valid input" \
35         "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
36         "\
37 00000000  3f 2d 0a                                          |?-.|
38 00000003
39 " \
40         "" \
41         "echo \xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
42
43 testing "30 bytes which are not valid unicode chars followed by valid input" \
44         "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
45         "\
46 00000000  3f 3f 3f 3f 3f 3f 3f 3f  3f 3f 3f 3f 3f 3f 3f 3f  |????????????????|
47 00000010  3f 3f 3f 3f 3f 3f 3f 3f  3f 3f 3f 3f 3f 3f 2d 0a  |??????????????-.|
48 00000020
49 " \
50         "" \
51         "echo \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff- | hexdump -C >ash.output; exit; exit; exit; exit\n"
52 fi
53
54
55 # Not sure this behavior is perfect: we lose all invalid input which precedes
56 # arrow keys and such. In this example, \xff\xff are lost
57 testing "2 bytes which are not valid unicode chars followed by left arrow key" \
58         "script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
59         "\
60 00000000  3d 2d 0a                                          |=-.|
61 00000003
62 " \
63         "" \
64         "echo =+\xff\xff\x1b\x5b\x44- | hexdump -C >ash.output; exit; exit; exit; exit\n"
65
66 # ash should see "echo \xff\n",pause -> execute it as "echo ?" (which is
67 # not checked by the test), then read and execute the rest: "echo A | ..."
68 # The bug was that ash was eating the beginning of "echo A" despite the pause.
69 testing "Invalid unicode chars followed by a pause do not eat next chars" \
70         "{ echo -ne 'echo \xff\n'; sleep 1; echo -ne 'echo A | hexdump -C >ash.output; exit; exit; exit; exit\n'; } \
71          | script -q -c 'ash' /dev/null >/dev/null; cat ash.output" \
72         "\
73 00000000  41 0a                                             |A.|
74 00000002
75 " \
76         "" ""
77
78 rm ash.output
79
80 exit $FAILCOUNT