Commit | Line | Data |
c8e3bb4c |
1 | # tr.t |
2 | |
f05dd7cc |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | unshift @INC, "../lib"; |
6 | } |
a5095b95 |
7 | |
2de7b02f |
8 | print "1..8\n"; |
c8e3bb4c |
9 | |
10 | $_ = "abcdefghijklmnopqrstuvwxyz"; |
11 | |
12 | tr/a-z/A-Z/; |
13 | |
14 | print "not " unless $_ eq "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
15 | print "ok 1\n"; |
16 | |
17 | tr/A-Z/a-z/; |
18 | |
19 | print "not " unless $_ eq "abcdefghijklmnopqrstuvwxyz"; |
20 | print "ok 2\n"; |
21 | |
22 | tr/b-y/B-Y/; |
23 | |
24 | print "not " unless $_ eq "aBCDEFGHIJKLMNOPQRSTUVWXYz"; |
25 | print "ok 3\n"; |
26 | |
27 | # In EBCDIC 'I' is \xc9 and 'J' is \0xd1, 'i' is \x89 and 'j' is \x91. |
28 | # Yes, discontinuities. Regardless, the \xca in the below should stay |
29 | # untouched (and not became \x8a). |
5e037136 |
30 | { |
31 | no utf8; |
32 | $_ = "I\xcaJ"; |
c8e3bb4c |
33 | |
5e037136 |
34 | tr/I-J/i-j/; |
c8e3bb4c |
35 | |
5e037136 |
36 | print "not " unless $_ eq "i\xcaj"; |
37 | print "ok 4\n"; |
38 | } |
c8e3bb4c |
39 | # |
2de7b02f |
40 | |
41 | # make sure that tr cancels IOK and NOK |
42 | ($x = 12) =~ tr/1/3/; |
43 | (my $y = 12) =~ tr/1/3/; |
44 | ($f = 1.5) =~ tr/1/3/; |
45 | (my $g = 1.5) =~ tr/1/3/; |
46 | print "not " unless $x + $y + $f + $g == 71; |
47 | print "ok 5\n"; |
48 | |
49 | # make sure tr is harmless if not updating - see [ID 20000511.005] |
50 | $_ = 'fred'; |
51 | /([a-z]{2})/; |
52 | $1 =~ tr/A-Z//; |
53 | s/^(\s*)f/$1F/; |
54 | print "not " if $_ ne 'Fred'; |
55 | print "ok 6\n"; |
56 | |
57 | # check tr handles UTF8 correctly |
58 | ($x = 256.65.258) =~ tr/a/b/; |
59 | print "not " if $x ne 256.65.258 or length $x != 3; |
60 | print "ok 7\n"; |
61 | $x =~ tr/A/B/; |
62 | print "not " if $x ne 256.66.258 or length $x != 3; |
63 | print "ok 8\n"; |