VirtualBox

source: kBuild/trunk/src/grep/tests/sjis-mb

Last change on this file was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:executable set to *
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
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
22encode() { echo "$1" | tr @% '\203\301'; }
23
24for locale in ja_JP.SHIFT_JIS ja_JP.SJIS ja_JP.PCK ''; do
25 test "$(get-mb-cur-max $locale)" = 2 && break
26done
27test -n "$locale" || skip_ 'SJIS locale not found'
28
29k=0
30test_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
38test_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
46failure_tests=@A
47successful_tests='%%AA @AA @A@@A'
48
49fail=0
50for i in $successful_tests; do
51 test_grep -F $i A || fail=1
52 test_grep -E $i A || fail=1
53done
54
55for i in $failure_tests; do
56 test_grep_reject -F $i A || fail=1
57 test_grep_reject -E $i A || fail=1
58done
59
60test_grep_reject -E @A '^$|A' || fail=1
61
62Exit $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