Commit | Line | Data |
8d063cd8 |
1 | #!./perl |
2 | |
2ec6af5f |
3 | print "1..37\n"; |
8d063cd8 |
4 | |
5 | # optimized |
6 | |
7 | $_ = 'abc'; |
8 | $c = do foo(); |
a687059c |
9 | if ($c . $_ eq 'cab') {print "ok 1\n";} else {print "not ok 1 $c$_\n";} |
8d063cd8 |
10 | |
11 | # unoptimized |
12 | |
13 | $_ = 'abc'; |
14 | $c = chop($_); |
15 | if ($c . $_ eq 'cab') {print "ok 2\n";} else {print "not ok 2\n";} |
16 | |
17 | sub foo { |
18 | chop; |
19 | } |
a687059c |
20 | |
21 | @foo = ("hi \n","there\n","!\n"); |
22 | @bar = @foo; |
23 | chop(@bar); |
24 | print join('',@bar) eq 'hi there!' ? "ok 3\n" : "not ok 3\n"; |
25 | |
26 | $foo = "\n"; |
27 | chop($foo,@foo); |
28 | print join('',$foo,@foo) eq 'hi there!' ? "ok 4\n" : "not ok 4\n"; |
a0d0e21e |
29 | |
30 | $_ = "foo\n\n"; |
31 | print chomp() == 1 ? "ok 5\n" : "not ok 5\n"; |
32 | print $_ eq "foo\n" ? "ok 6\n" : "not ok 6\n"; |
33 | |
34 | $_ = "foo\n"; |
35 | print chomp() == 1 ? "ok 7\n" : "not ok 7\n"; |
36 | print $_ eq "foo" ? "ok 8\n" : "not ok 8\n"; |
37 | |
38 | $_ = "foo"; |
39 | print chomp() == 0 ? "ok 9\n" : "not ok 9\n"; |
40 | print $_ eq "foo" ? "ok 10\n" : "not ok 10\n"; |
41 | |
42 | $_ = "foo"; |
43 | $/ = "oo"; |
44 | print chomp() == 2 ? "ok 11\n" : "not ok 11\n"; |
45 | print $_ eq "f" ? "ok 12\n" : "not ok 12\n"; |
46 | |
47 | $_ = "bar"; |
48 | $/ = "oo"; |
49 | print chomp() == 0 ? "ok 13\n" : "not ok 13\n"; |
50 | print $_ eq "bar" ? "ok 14\n" : "not ok 14\n"; |
51 | |
52 | $_ = "f\n\n\n\n\n"; |
53 | $/ = ""; |
54 | print chomp() == 5 ? "ok 15\n" : "not ok 15\n"; |
55 | print $_ eq "f" ? "ok 16\n" : "not ok 16\n"; |
56 | |
57 | $_ = "f\n\n"; |
58 | $/ = ""; |
59 | print chomp() == 2 ? "ok 17\n" : "not ok 17\n"; |
60 | print $_ eq "f" ? "ok 18\n" : "not ok 18\n"; |
61 | |
62 | $_ = "f\n"; |
63 | $/ = ""; |
64 | print chomp() == 1 ? "ok 19\n" : "not ok 19\n"; |
65 | print $_ eq "f" ? "ok 20\n" : "not ok 20\n"; |
66 | |
67 | $_ = "f"; |
68 | $/ = ""; |
69 | print chomp() == 0 ? "ok 21\n" : "not ok 21\n"; |
70 | print $_ eq "f" ? "ok 22\n" : "not ok 22\n"; |
c85b29f8 |
71 | |
72 | $_ = "xx"; |
73 | $/ = "xx"; |
74 | print chomp() == 2 ? "ok 23\n" : "not ok 23\n"; |
75 | print $_ eq "" ? "ok 24\n" : "not ok 24\n"; |
76 | |
77 | $_ = "axx"; |
78 | $/ = "xx"; |
79 | print chomp() == 2 ? "ok 25\n" : "not ok 25\n"; |
80 | print $_ eq "a" ? "ok 26\n" : "not ok 26\n"; |
81 | |
82 | $_ = "axx"; |
83 | $/ = "yy"; |
84 | print chomp() == 0 ? "ok 27\n" : "not ok 27\n"; |
85 | print $_ eq "axx" ? "ok 28\n" : "not ok 28\n"; |
4c5a6083 |
86 | |
87 | # This case once mistakenly behaved like paragraph mode. |
88 | $_ = "ab\n"; |
89 | $/ = \3; |
90 | print chomp() == 0 ? "ok 29\n" : "not ok 29\n"; |
91 | print $_ eq "ab\n" ? "ok 30\n" : "not ok 30\n"; |
9b83640a |
92 | |
93 | # Go Unicode. |
94 | |
95 | $_ = "abc\x{1234}"; |
96 | chop; |
97 | print $_ eq "abc" ? "ok 31\n" : "not ok 31\n"; |
98 | |
99 | $_ = "abc\x{1234}d"; |
100 | chop; |
101 | print $_ eq "abc\x{1234}" ? "ok 32\n" : "not ok 32\n"; |
102 | |
103 | $_ = "\x{1234}\x{2345}"; |
104 | chop; |
105 | print $_ eq "\x{1234}" ? "ok 33\n" : "not ok 33\n"; |
37ce32a7 |
106 | |
37ce32a7 |
107 | my @stuff = qw(this that); |
2ec6af5f |
108 | print chop(@stuff[0,1]) eq 't' ? "ok 34\n" : "not ok 34\n"; |
109 | |
110 | # bug id 20010305.012 |
111 | @stuff = qw(ab cd ef); |
112 | print chop(@stuff = @stuff) eq 'f' ? "ok 35\n" : "not ok 35\n"; |
113 | |
114 | @stuff = qw(ab cd ef); |
115 | print chop(@stuff[0, 2]) eq 'f' ? "ok 36\n" : "not ok 36\n"; |
116 | |
117 | my %stuff = (1..4); |
118 | print chop(@stuff{1, 3}) eq '4' ? "ok 37\n" : "not ok 37\n"; |