1 | #!/bin/sh
|
---|
2 | # similar to euc-mb and fgrep-infloop, but tests SJIS encoding.
|
---|
3 | # in this encoding, an ASCII character is both a valid single-byte
|
---|
4 | # character, and a suffix of a valid double-byte character
|
---|
5 |
|
---|
6 | . "${srcdir=.}/init.sh"; path_prepend_ ../src
|
---|
7 |
|
---|
8 | # Add "." to PATH for the use of get-mb-cur-max.
|
---|
9 | path_prepend_ .
|
---|
10 |
|
---|
11 | require_compiled_in_MB_support
|
---|
12 | require_timeout_
|
---|
13 |
|
---|
14 | locale=ja_JP.SHIFT_JIS
|
---|
15 |
|
---|
16 | # Sequences used in this test ("%" and "@" become 8-bit characters, while "A"
|
---|
17 | # is the real ASCII character for "A"):
|
---|
18 | # - "%" becomes an half-width katakana in SJIS, but it is an invalid sequence
|
---|
19 | # in UTF-8.
|
---|
20 | # - "@@" and "@A" are both valid sequences in SJIS. We try to fool grep into
|
---|
21 | # matching "A" against "@A", or mistaking a valid "A" match for the second
|
---|
22 | # byte of a multi-byte character.
|
---|
23 |
|
---|
24 | encode() { echo "$1" | tr @% '\203\301'; }
|
---|
25 |
|
---|
26 | k=0
|
---|
27 | test_grep_reject() {
|
---|
28 | k=$(expr $k + 1)
|
---|
29 | encode "$2" | \
|
---|
30 | LC_ALL=$locale \
|
---|
31 | timeout 10s grep $1 $(encode "$3") > out$k 2>&1
|
---|
32 | test $? = 1 && compare /dev/null out$k
|
---|
33 | }
|
---|
34 |
|
---|
35 | test_grep() {
|
---|
36 | k=$(expr $k + 1)
|
---|
37 | encode "$2" > exp$k
|
---|
38 | LC_ALL=$locale \
|
---|
39 | timeout 10s grep $1 $(encode "$3") exp$k > out$k 2>&1
|
---|
40 | test $? = 0 && compare exp$k out$k
|
---|
41 | }
|
---|
42 |
|
---|
43 | test "$(get-mb-cur-max $locale)" = 2 || skip_ 'SJIS locale not found'
|
---|
44 |
|
---|
45 | failure_tests=@A
|
---|
46 | successful_tests='%%AA @AA @A@@A'
|
---|
47 |
|
---|
48 | fail=0
|
---|
49 | for i in $successful_tests; do
|
---|
50 | test_grep -F $i A || fail=1
|
---|
51 | test_grep -E $i A || fail=1
|
---|
52 | done
|
---|
53 |
|
---|
54 | test_grep_reject -F @@ @ || fail=1
|
---|
55 | test_grep_reject -E @@ @ || fail=1
|
---|
56 | for i in $failure_tests; do
|
---|
57 | test_grep_reject -F $i A || fail=1
|
---|
58 | test_grep_reject -E $i A || fail=1
|
---|
59 | done
|
---|
60 |
|
---|
61 | Exit $fail
|
---|