Debian Codegraph @

tests/sjis-mb

raw
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 # Sequences used in this test ("%" and "@" become 8-bit characters, while "A"
15 # is the real ASCII character for "A"):
16 # - "%" becomes an half-width katakana in SJIS, but it is an invalid sequence
17 # in UTF-8.
18 # - "@@" and "@A" are both valid sequences in SJIS. We try to fool grep into
19 # matching "A" against "@A", or mistaking a valid "A" match for the second
20 # byte of a multi-byte character.
21
22 encode() { echo "$1" | tr @% '\203\301'; }
23
24 for locale in ja_JP.SHIFT_JIS ja_JP.SJIS ja_JP.PCK ''; do
25 test "$(get-mb-cur-max $locale)" = 2 && break
26 done
27 test -n "$locale" || skip_ 'SJIS locale not found'
28
29 k=0
30 test_grep_reject() {
31 k=$(expr $k + 1)
32 encode "$2" > in || return 1
33 returns_ 1 env LC_ALL=$locale timeout 10s \
34 grep $1 $(encode "$3") in >out$k 2>&1 \
35 && compare /dev/null out$k
36 }
37
38 test_grep() {
39 k=$(expr $k + 1)
40 encode "$2" > exp$k
41 LC_ALL=$locale \
42 timeout 10s grep $1 $(encode "$3") exp$k > out$k 2>&1
43 test $? = 0 && compare exp$k out$k
44 }
45
46 failure_tests=@A
47 successful_tests='%%AA @AA @A@@A'
48
49 fail=0
50 for i in $successful_tests; do
51 test_grep -F $i A || fail=1
52 test_grep -E $i A || fail=1
53 done
54
55 for i in $failure_tests; do
56 test_grep_reject -F $i A || fail=1
57 test_grep_reject -E $i A || fail=1
58 done
59
60 test_grep_reject -E @A '^$|A' || fail=1
61
62 Exit $fail