Skip to content
Newer
Older
100644 139 lines (103 sloc) 4.05 KB
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
1 use v6;
2
3 use Test;
4
5 =begin kwid
6
7 Tests for Synopsis 3
8 =end kwid
9
b90d9fe [t/spec] test for RT #64474
moritz authored Apr 23, 2009
10 plan 52;
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
11
12 my $str1 = "foo";
13 my $str2 = "bar";
14 my $str3 = "foobar";
15 my $str4 = $str1~$str2;
16
17 # L<S03/Concatenation>
18 is($str3, $str4, "~");
19
20 # L<S03/Conditional operator precedence/Also known as the ternary or trinary operator>
21 my $bar = "";
22 ($str3 eq $str4) ?? ($bar = 1) !! ($bar = 0);
23
24 ok($bar, "?? !!");
25
26 # L<S03/Chaining binary precedence/==>
27 my $five = 5;
28 my $four = 4;
29 my $wibble = 4;
30
31 ok(!($five == $four), "== (false)");
32 ok($wibble == $four, "== (true)");
33 ok(!($wibble != $four), "== (false)");
34 ok($five != $four, "!= (true)");
35
36 ok($five == 5, "== (const on rhs)");
37 ok(!($five != 5), "!= (const on rhs)");
38
39 ok(5 == $five, "== (const on lhs)");
40 ok(!(5 != $five), "!= (const on lhs)");
41
42 ok($five == (2 + 3), "== (sum on rhs)");
43 ok(!($five != (2 + 3)), "== (sum on rhs)");
44
45 is(2 + 3, $five, "== (sum on lhs)");
46 ok((2 + 3) == 5, "== (sum on lhs)");
47 ok(!((2 + 3) != $five), "== (sum on lhs)");
48
49 # L<S03/Concatenation>
50 is("text " ~ "stitching", "text stitching", 'concatenation with ~ operator');
51
52 # Bit Stitching
53
4846880 [t/spec] fix nearly all broken smartlinks, two remain
moritz authored Sep 29, 2008
54 # L<S03/Tight or precedence/short-circuit inclusive-or>
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
55 is(2 || 3, 2, "|| returns first true value");
56 ok(!(defined( 0 || undef)), "|| returns last false value of list?");
57
e97f6d5 [t/spec] avoid autohreading through ok()
moritz authored Jan 19, 2009
58 is(?(2 ?| 3), True, "boolean or (?|) returns True or False");
59 is(?(0 ?| undef), False, "boolean or (?|) returns True or False");
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
60
61 # L<S03/Junctive operators/They thread through operations>
e97f6d5 [t/spec] avoid autohreading through ok()
moritz authored Jan 19, 2009
62 ok(?((all((4|5|6) + 3) == one(7|8|9))), "all elements in junction are incremented");
63 ok(?((any(1..6) == one(1|2|3|4|5|6))), "any elements will match via junction");
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
64
65
e97f6d5 [t/spec] avoid autohreading through ok()
moritz authored Jan 19, 2009
66 ok( ?(7 > any(4..12)), "any test against scalar" );
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
67
68
69 my @oldval = (5, 8, 12);
70
71 my @newval1 = (17, 15, 14); # all greater
72 my @newval2 = (15, 7, 20); # some less some greater
73 my @newval3 = (3, 1, 4); # all less
74 my @newval4 = (1,2,40);
75
e97f6d5 [t/spec] avoid autohreading through ok()
moritz authored Jan 19, 2009
76 ok( ?(any(@newval4) > any(@oldval)), "any test array against any array" );
77 ok( ?(any(@newval4) > all(@oldval)), "any test array against all array" );
78 ok( ?(all(@newval2) > any(@oldval)), "all test array against any array" );
79 ok( ?(all(@newval1) > all(@oldval)), "all test array against all array" );
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
80
e97f6d5 [t/spec] avoid autohreading through ok()
moritz authored Jan 19, 2009
81 ok(?(42 > 12 & 20 & 32), "test the all infix operator");
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
82
83
84 # L<S03/Hyper operators/hyper operator distributes over them as lists>
1f08579 [t/spec] a bit of fiddeling in S03-operators/
moritz authored Sep 3, 2008
85 {
86 my @rv;
87 @rv = (1,2,3,4) >>+<< (1,2,3,4);
8208469 [t/spec]: Unfudge a rakudo test in S03-operators/misc.t .
pmichaud authored Dec 21, 2008
88 is(~@rv, "2 4 6 8", 'hyper-add');
1f08579 [t/spec] a bit of fiddeling in S03-operators/
moritz authored Sep 3, 2008
89 }
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
90
91 { # L<S03/Changes to Perl 5 operators/ "?| is a logical OR">
92 # work with pure Bool's
e97f6d5 [t/spec] avoid autohreading through ok()
moritz authored Jan 19, 2009
93 ok( ?(False?|False == False), '?| works with Bools');
94 ok( ?(False?|True == True), '?| works with Bools');
95 ok( ?(True ?|False == True), '?| works with Bools');
96 ok( ?(True ?|True == True), '?| works with Bools');
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
97
e97f6d5 [t/spec] avoid autohreading through ok()
moritz authored Jan 19, 2009
98 ok( ?('' ?| 0 == False), '?| works');
99 ok( ?(1 ?| 0 == True), '?| works');
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
100 }
101 { # L<S03/Changes to Perl 5 operators/ "?& is a logical AND">
102 # work with pure Bool's
e97f6d5 [t/spec] avoid autohreading through ok()
moritz authored Jan 19, 2009
103 ok( ?(False?&False == False), '?& works with Bools');
104 ok( ?(False?&True == False), '?& works with Bools');
105 ok( ?(True ?&False == False), '?& works with Bools');
106 ok( ?(True ?&True == True), '?& works with Bools');
107
108 ok( ?('' ?& 'yes' == False), '?& works');
109 ok( ?(1 ?& False == False), '?& works');
110 ok( ?(42 ?& 42 == True), '?& works');
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
111 }
112 { ## L<S03/Changes to Perl 5 operators/ "?^ is a logical XOR">
113 # work with pure Bool's
e97f6d5 [t/spec] avoid autohreading through ok()
moritz authored Jan 19, 2009
114 ok( ?(False?^False == False), '?^ works with Bools');
115 ok( ?(False?^True == True), '?^ works with Bools');
116 ok( ?(True ?^False == True), '?^ works with Bools');
117 ok( ?(True ?^True == False), '?^ works with Bools');
118
119 ok( ?('' ?^'' == False), '?^ works');
120 ok( ?(undef?^ 1 == True), '?^ works');
121 ok( ?(-1 ?^undef == True), '?^ works');
aa3b73a [t] move misc operator tests to spec/
moritz authored Sep 2, 2008
122
123 }
64c247e [t/spec] test that (undef min 2) doesn't die
moritz authored Jan 5, 2009
124
e13d57a [t/spec] add and fix a few smartlinks
moritz authored Jan 8, 2009
125 # L<S03/Tight or precedence/"any value of any type may be compared with +Inf
126 # or -Inf values">
64c247e [t/spec] test that (undef min 2) doesn't die
moritz authored Jan 5, 2009
127 #?rakudo todo 'RT #61836'
128 {
129 lives_ok { (2 min undef) }, 'can do (2 min undef)';
130 lives_ok { (undef min 2) }, 'can do (undef min 2)';
131 }
b90d9fe [t/spec] test for RT #64474
moritz authored Apr 23, 2009
132
133 # L<S03/Hyper operators/"but a short list may always be extended arbitrarily">
134 #?rakudo todo 'RT #64474'
135 {
136 is (1, 2, * Z <a b c d>).join('|'),
137 '1a2b2c2d', 'A * as the last value extends lists for infix:<Z> (zip)';
138 }
Something went wrong with that request. Please try again.