This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make % use fmod()
[perl5.git] / t / op / chop.t
CommitLineData
8d063cd8
LW
1#!./perl
2
79072805 3# $RCSfile: chop.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:40 $
8d063cd8 4
c85b29f8 5print "1..28\n";
8d063cd8
LW
6
7# optimized
8
9$_ = 'abc';
10$c = do foo();
a687059c 11if ($c . $_ eq 'cab') {print "ok 1\n";} else {print "not ok 1 $c$_\n";}
8d063cd8
LW
12
13# unoptimized
14
15$_ = 'abc';
16$c = chop($_);
17if ($c . $_ eq 'cab') {print "ok 2\n";} else {print "not ok 2\n";}
18
19sub foo {
20 chop;
21}
a687059c
LW
22
23@foo = ("hi \n","there\n","!\n");
24@bar = @foo;
25chop(@bar);
26print join('',@bar) eq 'hi there!' ? "ok 3\n" : "not ok 3\n";
27
28$foo = "\n";
29chop($foo,@foo);
30print join('',$foo,@foo) eq 'hi there!' ? "ok 4\n" : "not ok 4\n";
a0d0e21e
LW
31
32$_ = "foo\n\n";
33print chomp() == 1 ? "ok 5\n" : "not ok 5\n";
34print $_ eq "foo\n" ? "ok 6\n" : "not ok 6\n";
35
36$_ = "foo\n";
37print chomp() == 1 ? "ok 7\n" : "not ok 7\n";
38print $_ eq "foo" ? "ok 8\n" : "not ok 8\n";
39
40$_ = "foo";
41print chomp() == 0 ? "ok 9\n" : "not ok 9\n";
42print $_ eq "foo" ? "ok 10\n" : "not ok 10\n";
43
44$_ = "foo";
45$/ = "oo";
46print chomp() == 2 ? "ok 11\n" : "not ok 11\n";
47print $_ eq "f" ? "ok 12\n" : "not ok 12\n";
48
49$_ = "bar";
50$/ = "oo";
51print chomp() == 0 ? "ok 13\n" : "not ok 13\n";
52print $_ eq "bar" ? "ok 14\n" : "not ok 14\n";
53
54$_ = "f\n\n\n\n\n";
55$/ = "";
56print chomp() == 5 ? "ok 15\n" : "not ok 15\n";
57print $_ eq "f" ? "ok 16\n" : "not ok 16\n";
58
59$_ = "f\n\n";
60$/ = "";
61print chomp() == 2 ? "ok 17\n" : "not ok 17\n";
62print $_ eq "f" ? "ok 18\n" : "not ok 18\n";
63
64$_ = "f\n";
65$/ = "";
66print chomp() == 1 ? "ok 19\n" : "not ok 19\n";
67print $_ eq "f" ? "ok 20\n" : "not ok 20\n";
68
69$_ = "f";
70$/ = "";
71print chomp() == 0 ? "ok 21\n" : "not ok 21\n";
72print $_ eq "f" ? "ok 22\n" : "not ok 22\n";
c85b29f8
PP
73
74$_ = "xx";
75$/ = "xx";
76print chomp() == 2 ? "ok 23\n" : "not ok 23\n";
77print $_ eq "" ? "ok 24\n" : "not ok 24\n";
78
79$_ = "axx";
80$/ = "xx";
81print chomp() == 2 ? "ok 25\n" : "not ok 25\n";
82print $_ eq "a" ? "ok 26\n" : "not ok 26\n";
83
84$_ = "axx";
85$/ = "yy";
86print chomp() == 0 ? "ok 27\n" : "not ok 27\n";
87print $_ eq "axx" ? "ok 28\n" : "not ok 28\n";