VirtualBox

source: kBuild/vendor/grep/2.12/tests/sjis-mb@ 3627

Last change on this file since 3627 was 2595, checked in by bird, 13 years ago

gnu grep version 2.12 (grep-2.12.tar.xz, md5sum=8d2f0346d08b13c18afb81f0e8aa1e2f)

File size: 1.6 KB
Line 
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.
9path_prepend_ .
10
11require_compiled_in_MB_support
12require_timeout_
13
14locale=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
24encode() { echo "$1" | tr @% '\203\301'; }
25
26k=0
27test_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
35test_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
43test "$(get-mb-cur-max $locale)" = 2 || skip_ 'SJIS locale not found'
44
45failure_tests=@A
46successful_tests='%%AA @AA @A@@A'
47
48fail=0
49for i in $successful_tests; do
50 test_grep -F $i A || fail=1
51 test_grep -E $i A || fail=1
52done
53
54test_grep_reject -F @@ @ || fail=1
55test_grep_reject -E @@ @ || fail=1
56for i in $failure_tests; do
57 test_grep_reject -F $i A || fail=1
58 test_grep_reject -E $i A || fail=1
59done
60
61Exit $fail
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette