File: sjis-mb

package info (click to toggle)
grep 3.11-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,392 kB
  • sloc: ansic: 95,031; sh: 12,720; perl: 606; makefile: 386; awk: 71; sed: 16
file content (62 lines) | stat: -rwxr-xr-x 1,661 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
# similar to euc-mb and fgrep-infloop, but tests SJIS encoding.
# in this encoding, an ASCII character is both a valid single-byte
# character, and a suffix of a valid double-byte character

. "${srcdir=.}/init.sh"; path_prepend_ ../src

# Add "." to PATH for the use of get-mb-cur-max.
path_prepend_ .

require_compiled_in_MB_support
require_timeout_

# Sequences used in this test ("%" and "@" become 8-bit characters, while "A"
# is the real ASCII character for "A"):
# - "%" becomes an half-width katakana in SJIS, but it is an invalid sequence
#   in UTF-8.
# - "@@" and "@A" are both valid sequences in SJIS.  We try to fool grep into
#   matching "A" against "@A", or mistaking a valid "A" match for the second
#   byte of a multi-byte character.

encode() { echo "$1" | tr @% '\203\301'; }

for locale in ja_JP.SHIFT_JIS ja_JP.SJIS ja_JP.PCK ''; do
  test "$(get-mb-cur-max $locale)" = 2 && break
done
test -n "$locale" || skip_ 'SJIS locale not found'

k=0
test_grep_reject() {
  k=$(expr $k + 1)
  encode "$2" > in || return 1
  returns_ 1 env LC_ALL=$locale timeout 10s \
    grep $1 $(encode "$3") in >out$k 2>&1 \
      && compare /dev/null out$k
}

test_grep() {
  k=$(expr $k + 1)
  encode "$2" > exp$k
  LC_ALL=$locale \
    timeout 10s grep $1 $(encode "$3") exp$k > out$k 2>&1
  test $? = 0 && compare exp$k out$k
}

failure_tests=@A
successful_tests='%%AA @AA @A@@A'

fail=0
for i in $successful_tests; do
  test_grep -F $i A || fail=1
  test_grep -E $i A || fail=1
done

for i in $failure_tests; do
  test_grep_reject -F $i A || fail=1
  test_grep_reject -E $i A || fail=1
done

test_grep_reject -E @A '^$|A' || fail=1

Exit $fail