Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 188 lines (154 sloc) 5.386 kB
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
1 use v6;
2
3 use Test;
4
5 =begin pod
6
7 C<===> and C<eqv> are 2 distinct operators, where C<===> tests value
8 equivalence for immutable types and reference equivalence for
9 mutable types, and C<eqv> tests value equivalence for snapshots of mutable
10 types. So C<(1,2) === (1,2)> returns true but C<[1,2] === [1,2]> returns
11 false, and C<[1,2] eqv [1,2]> returns true.
12
13 =end pod
14
eda6db1 [t/spec] move smartlinks from POD to ordinary comments
moritz authored
15 # L<S03/"Chaining binary precedence" /Value identity>
16
da526e3 @moritz remove Mu tests for ===
moritz authored
17 plan 74;
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
18
19 # === on values
20 {
21 ok (1 === 1), "=== on values (1)";
22 ok (0 === 0), "=== on values (2)";
8c3b0e3 @moritz test === on non-literal values
moritz authored
23 ok (1 + 1 === 2), '=== on non-literal values';
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
24 ok !(0 === 1), "=== on values (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
25 isa_ok (1 === 1), Bool, "=== on values (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
26 ok ("abc" === "abc"), "=== on values(abc)";
27 ok !("abc" === "ABC"), "=== on values(abc === ABC)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
28 isa_ok ("abc" === "abc"), Bool, "=== on values (abc)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
29 ok !(1 === 1.0), "=== on values (1 === 1.0)";
30 ok !(1 === "1"), '=== on values (1 === "1")';
31 }
32
ae00034 [t/spec] === tests on Rat and Num.
colomon authored
33 # more value tests
34 {
35 ok 1/2 === 1/2, "=== on Rats";
36 ok 1/2 !=== 3/2, "!=== on Rats";
37 isa_ok 1/2 === 1/2, Bool, "=== on Rats yields Bool";
38 isa_ok 1/2 !=== 3/2, Bool, "!=== on Rats yields Bool";
39 ok 0.5e0 === 0.5e0, "=== on Nums";
40 ok 0.5e0 !=== 1.5e0, "!=== on Nums";
41 isa_ok 0.5e0 === 0.5e0, Bool, "=== on Nums yields Bool";
42 isa_ok 0.5e0 !=== 1.5e0, Bool, "!=== on Nums yields Bool";
43 }
44
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
45 # Value types
46 {
47 my $a = 1;
48 my $b = 1;
49
50 ok $a === $a, "=== on value types (1-1)";
51 ok $b === $b, "=== on value types (1-2)";
52 ok $a === $b, "=== on value types (1-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
53 isa_ok $a === $b, Bool, "=== on value types (1-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
54 }
55
56 {
57 my $a = 1;
58 my $b = 2;
59
60 ok ($a === $a), "=== on value types (2-1)";
61 ok ($b === $b), "=== on value types (2-2)";
62 ok !($a === $b), "=== on value types (2-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
63 isa_ok ($a === $a), Bool, "=== on value types (2-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
64 }
65
66 # Reference types
67 {
68 my @a = (1,2,3);
69 my @b = (1,2,3);
70
2a90d08 [t/spec] Fudge value_equivalence.t.
colomon authored
71 #?rakudo 2 todo "=== doesn't work on array references yet"
4bdf17e @coke Convert niecza faux-todo to real todo.
coke authored
72 #?niecza todo
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
73 ok (\@a === \@a), "=== on array references (1)";
4bdf17e @coke Convert niecza faux-todo to real todo.
coke authored
74 #?niecza todo
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
75 ok (\@b === \@b), "=== on array references (2)";
76 ok !(\@a === \@b), "=== on array references (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
77 isa_ok (\@a === \@a), Bool, "=== on array references (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
78 }
79
80 {
81 my $a = \3;
82 my $b = \3;
83
84 ok ($a === $a), "=== on scalar references (1-1)";
85 ok ($b === $b), "=== on scalar references (1-2)";
748c80b @coke pugs fudge
coke authored
86 #?pugs todo
b21f28d [t/spec]: rakudo fudging and test fixes
pmichaud authored
87 ok !($a === $b), "=== on scalar references (1-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
88 isa_ok ($a === $a), Bool, "=== on scalar references (1-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
89 }
90
91 {
92 my $a = { 3 };
93 my $b = { 3 };
94
95 ok ($a === $a), "=== on sub references (1-1)";
96 ok ($b === $b), "=== on sub references (1-2)";
97 ok !($a === $b), "=== on sub references (1-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
98 isa_ok ($a === $a), Bool, "=== on sub references (1-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
99 }
100
101 {
102 ok (&say === &say), "=== on sub references (2-1)";
103 ok (&map === &map), "=== on sub references (2-2)";
104 ok !(&say === &map), "=== on sub references (2-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
105 isa_ok (&say === &say), Bool, "=== on sub references (2-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
106 }
107
108 {
109 my $num = 3;
110 my $a = \$num;
111 my $b = \$num;
112
113 ok ($a === $a), "=== on scalar references (2-1)";
114 ok ($b === $b), "=== on scalar references (2-2)";
2a90d08 [t/spec] Fudge value_equivalence.t.
colomon authored
115 #?rakudo todo "=== fail"
4bdf17e @coke Convert niecza faux-todo to real todo.
coke authored
116 #?niecza todo
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
117 ok ($a === $b), "=== on scalar references (2-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
118 isa_ok ($a === $a), Bool, "=== on scalar references (2-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
119 }
120
121 {
122 ok !([1,2,3] === [4,5,6]), "=== on anonymous array references (1)";
123 ok !([1,2,3] === [1,2,3]), "=== on anonymous array references (2)";
124 ok !([] === []), "=== on anonymous array references (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
125 isa_ok ([1,2,3] === [4,5,6]), Bool, "=== on anonymous array references (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
126 }
127
128 {
129 ok !({a => 1} === {a => 2}), "=== on anonymous hash references (1)";
130 ok !({a => 1} === {a => 1}), "=== on anonymous hash references (2)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
131 isa_ok ({a => 1} === {a => 2}), Bool, "=== on anonymous hash references (3)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
132 }
133
134 {
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
135 ok !(\3 === \4), "=== on anonymous scalar references (1)";
748c80b @coke pugs fudge
coke authored
136 #?pugs todo
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
137 ok !(\3 === \3), "=== on anonymous scalar references (2)";
138 isa_ok (\3 === \4), Bool, "=== on anonymous scalar references (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
139 }
140
141 # Chained === (not specced, but obvious)
142 {
143 ok (3 === 3 === 3), "chained === (1)";
144 ok !(3 === 3 === 4), "chained === (2)";
145 }
146
147 # Subparam binding doesn't affect === test
148 {
149 my $foo;
150 my $test = -> $arg { $foo === $arg };
151
152 $foo = 3;
153 ok $test($foo), "subparam binding doesn't affect === (1)";
154 ok $test(3), "subparam binding doesn't affect === (2)";
155
156 ok !$test(4), "subparam binding doesn't affect === (3)";
157 my $bar = 4;
158 ok !$test($bar), "subparam binding doesn't affect === (4)";
159 }
160
161 {
162 my $a = 1;
163 my $b = 2;
164 is($a === $a, Bool::True, '=== returns Bool::True when true');
165 is($a === $b, Bool::False, '=== returns Bool::False when false');
166 }
167
168 # L<S03/"Chaining binary precedence" /Negated relational operators>
169 {
170 ok !(1 !=== 1), "!=== on values (1)";
171 ok !(0 !=== 0), "!=== on values (2)";
172 ok (1 !=== 0), "!=== on values (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
173 isa_ok (1 !=== 1), Bool, "!=== on values (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
174 ok !("abc" !=== "abc"), "!=== on values(abc)";
175 ok ("abc" !=== "ABC"), "!=== on values(abc !=== ABC)";
176 ok (1 !=== 1.0), "!=== on values (1 !=== 1.0)";
177 ok (1 !=== "1"), '!=== on values (1 !=== "1")';
178 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
179
748c80b @coke pugs fudge
coke authored
180 #?pugs skip "this test alters # of run tests?"
5721b37 @TimToady === is supposed to autothread
TimToady authored
181 ok 1|2 === 1, '=== does autothread (1)';
748c80b @coke pugs fudge
coke authored
182 #?pugs skip "this test alters # of run tests?"
5721b37 @TimToady === is supposed to autothread
TimToady authored
183 isa_ok 1|2 === 1, Junction, '=== does autothread (2)';
8e96ed1 @moritz === does not autothread (RT #61692)
moritz authored
184
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
185 done;
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
186
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
187 # vim: ft=perl6
Something went wrong with that request. Please try again.