coreutils/tests/tr/Test.pm

101 lines
4.4 KiB
Perl
Raw Normal View History

1996-08-18 13:20:38 +08:00
package Test;
require 5.002;
1996-08-18 01:29:35 +08:00
use strict;
1996-12-20 13:46:27 +08:00
$Test::input_via_stdin = 1;
1996-08-18 13:20:45 +08:00
@Test::t = (
1996-12-20 13:46:27 +08:00
# test flags 1 or 2 strings input expected output expected return code
1993-03-02 22:10:31 +08:00
#
1996-12-20 13:46:27 +08:00
['1', q|'abcd' '[]*]'|, 'abcd', ']]]]', 0],
['2', q|'abc' '[%*]xyz'|, 'abc', 'xyz', 0],
['3', q|'' '[.*]'|, 'abc', 'abc', 0],
1993-03-02 22:10:31 +08:00
# Test --truncate-set1 behavior when string1 is longer than string2
1996-12-20 13:46:27 +08:00
['4', '-t ' . q|'abcd' 'xy'|, 'abcde', 'xycde', 0],
1993-03-02 22:10:31 +08:00
# Test bsd behavior (the default) when string1 is longer than string2
1996-12-20 13:46:27 +08:00
['5', q|'abcd' 'xy'|, 'abcde', 'xyyye', 0],
1993-03-02 22:10:31 +08:00
# Do it the posix way
1996-12-20 13:46:27 +08:00
['6', q|'abcd' 'x[y*]'|, 'abcde', 'xyyye', 0],
1993-03-02 22:10:31 +08:00
#
1996-12-20 13:46:27 +08:00
['7', '-s ' . q|'a-p' '%[.*]$'|, 'abcdefghijklmnop', '%.$', 0],
['8', '-s ' . q|'a-p' '[.*]$'|, 'abcdefghijklmnop', '.$', 0],
['9', '-s ' . q|'a-p' '%[.*]'|, 'abcdefghijklmnop', '%.', 0],
['a', '-s ' . q|'[a-z]'|, 'aabbcc', 'abc', 0],
['b', '-s ' . q|'[a-c]'|, 'aabbcc', 'abc', 0],
['c', '-s ' . q|'[a-b]'|, 'aabbcc', 'abcc', 0],
['d', '-s ' . q|'[b-c]'|, 'aabbcc', 'aabc', 0],
['e', '-s ' . q|'[\0-\5]'|,
"\0\0a\1\1b\2\2\2c\3\3\3d\4\4\4\4e\5\5",
"\0a\1b\2c\3d\4e\5", 0],
1993-03-02 22:10:31 +08:00
# tests of delete
1996-12-20 13:46:27 +08:00
['f', '-d ' . q|'[=[=]'|, '[[[[[[[]]]]]]]]', ']]]]]]]]', 0],
['g', '-d ' . q|'[=]=]'|, '[[[[[[[]]]]]]]]', '[[[[[[[', 0],
['h', '-d ' . q|'[:xdigit:]'|, '0123456789acbdefABCDEF', '', 0],
['i', '-d ' . q|'[:xdigit:]'|, 'w0x1y2z3456789acbdefABCDEFz', 'wxyzz', 0],
['j', '-d ' . q|'[:digit:]'|, '0123456789', '', 0],
['k', '-d ' . q|'[:digit:]'|, 'a0b1c2d3e4f5g6h7i8j9k', 'abcdefghijk', 0],
['l', '-d ' . q|'[:lower:]'|, 'abcdefghijklmnopqrstuvwxyz', '', 0],
['m', '-d ' . q|'[:upper:]'|, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '', 0],
['n', '-d ' . q|'[:lower:][:upper:]'|,
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', '', 0],
['o', '-d ' . q|'[:alpha:]'|,
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', '', 0],
['p', '-d ' . q|'[:alnum:]'|,
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', '', 0],
['q', '-d ' . q|'[:alnum:]'|,
'.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.', '..', 0],
['r', '-ds ' . q|'[:alnum:]' '.'|,
'.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.', '.', 0],
1993-03-02 22:10:31 +08:00
# The classic example, with string2 BSD-style
1996-12-20 13:46:27 +08:00
['s', '-cs ' . q|'[:alnum:]' '\n'|,
'The big black fox jumped over the fence.',
"The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n", 0],
1993-03-02 22:10:31 +08:00
# The classic example, POSIX-style
1996-12-20 13:46:27 +08:00
['t', '-cs ' . q|'[:alnum:]' '[\n*]'|,
'The big black fox jumped over the fence.',
"The\nbig\nblack\nfox\njumped\nover\nthe\nfence\n", 0],
['u', '-ds ' . q|'b' 'a'|, 'aabbaa', 'a', 0],
['v', '-ds ' . q|'[:xdigit:]' 'Z'|,
'ZZ0123456789acbdefABCDEFZZ', 'Z', 0],
1995-10-20 06:40:10 +08:00
# Try some data with 8th bit set in case something is mistakenly sign-extended.
1996-12-20 13:46:27 +08:00
['w', '-ds ' . q|'\350' '\345'|,
"\300\301\377\345\345\350\345",
"\300\301\377\345", 0],
['x', '-s ' . q|'abcdefghijklmn' '[:*016]'|, 'abcdefghijklmnop', ':op', 0],
['y', '-d ' . q|'a-z'|, 'abc $code', ' $', 0],
['z', '-ds ' . q|'a-z' '$.'|, 'a.b.c $$$$code\\', '. $\\', 0],
1993-03-02 22:10:31 +08:00
# Make sure that a-a is accepted, even though POSIX 1001.2 says it is illegal.
1996-12-20 13:46:27 +08:00
['A', q|'a-a' 'z'|, 'abc', 'zbc', 0],
1993-03-02 22:10:31 +08:00
#
1996-12-20 13:46:27 +08:00
['B', q|'a' ''''|, '', '', 1],
['C', q|'[:lower:]' '[:upper:]'|, 'abcxyzABCXYZ', 'ABCXYZABCXYZ', 0],
['D', q|'[:upper:]' '[:lower:]'|, 'abcxyzABCXYZ', 'abcxyzabcxyz', 0],
1995-12-01 04:26:33 +08:00
#
1996-12-20 13:46:27 +08:00
['E', q|'a[=*2][=c=]' 'xyyz'|, 'a=c', 'xyz', 0],
['F', q|'[:*3][:digit:]' 'a-m'|, ':1239', 'cefgm', 0],
['G', q|'a[b*512]c' '1[x*]2'|, 'abc', '1x2', 0],
['H', q|'a[b*513]c' '1[x*]2'|, 'abc', '1x2', 0],
['I', q|'a\-z' 'A-Z'|, 'abc-z', 'AbcBC', 0],
1996-04-05 04:22:10 +08:00
#
# From Ross
1996-12-20 13:46:27 +08:00
['R0.0', '-cs ' . q|'[:upper:]' 'X[Y*]'|, '', '', 1],
['R0.1', '-cs ' . q|'[:cntrl:]' 'X[Y*]'|, '', '', 1],
['R1.0', '-cs ' . q|'[:upper:]' '[X*]'|, 'AMZamz123.-+AMZ', 'AMZXAMZ', 0],
['R1.1', '-cs ' . q|'[:upper:][:digit:]' '[Z*]'|, '', '', 0],
['R2', '-dcs ' . q|'[:lower:]' 'n-rs-z'|, 'amzAMZ123.-+amz', 'amzamz', 0],
['R3', '-ds ' . q|'[:xdigit:]' '[:alnum:]'|,
'.ZABCDEFGzabcdefg.0123456788899.GG', '.ZGzg..G', 0],
['R4', '-dcs ' . q|'[:alnum:]' '[:digit:]'|, '', '', 0],
['R5', '-dc ' . q|'[:lower:]'|, '', '', 0],
['R6', '-dc ' . q|'[:upper:]'|, '', '', 0],
);
1;