Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 131 lines (96 sloc) 3.775 kb
aa3b73a [t] move misc operator tests to spec/
moritz authored
1 use v6;
2
3 use Test;
4
5 =begin kwid
6
7 Tests for Synopsis 3
8 =end kwid
9
64c247e [t/spec] test that (undef min 2) doesn't die
moritz authored
10 plan 51;
aa3b73a [t] move misc operator tests to spec/
moritz authored
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
54 # L<S03/Tight or precedence/short-circuit inclusive-or>
aa3b73a [t] move misc operator tests to spec/
moritz authored
55 is(2 || 3, 2, "|| returns first true value");
56 ok(!(defined( 0 || undef)), "|| returns last false value of list?");
57
58 is(2 ?| 3, True, "boolean or (?|) returns True or False");
59 is(0 ?| undef, False, "boolean or (?|) returns True or False");
60
61 # L<S03/Junctive operators/They thread through operations>
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");
64
65
66 ok( 7 > any(4..12), "any test against scalar" );
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
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" );
80
81 ok(42 > 12 & 20 & 32, "test the all infix operator");
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
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
88 is(~@rv, "2 4 6 8", 'hyper-add');
1f08579 [t/spec] a bit of fiddeling in S03-operators/
moritz authored
89 }
aa3b73a [t] move misc operator tests to spec/
moritz authored
90
91 { # L<S03/Changes to Perl 5 operators/ "?| is a logical OR">
92 # work with pure Bool's
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');
97
98 ok( '' ?| 0 == False, '?| works');
99 ok( 1 ?| 0 == True, '?| works');
100 }
101 { # L<S03/Changes to Perl 5 operators/ "?& is a logical AND">
102 # work with pure Bool's
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');
111 }
112 { ## L<S03/Changes to Perl 5 operators/ "?^ is a logical XOR">
113 # work with pure Bool's
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');
122
123 }
64c247e [t/spec] test that (undef min 2) doesn't die
moritz authored
124
125 # L<S03/Tight or precedence/"min +Inf"/>
126 #?rakudo todo 'RT #61836'
127 {
128 lives_ok { (2 min undef) }, 'can do (2 min undef)';
129 lives_ok { (undef min 2) }, 'can do (undef min 2)';
130 }
Something went wrong with that request. Please try again.