Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 182 lines (149 sloc) 5.328 kb
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
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
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
17 plan *;
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
18
19 # === on values
20 {
21 ok (1 === 1), "=== on values (1)";
22 ok (0 === 0), "=== on values (2)";
23 ok !(0 === 1), "=== on values (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
24 isa_ok (1 === 1), Bool, "=== on values (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
25 ok ("abc" === "abc"), "=== on values(abc)";
26 ok !("abc" === "ABC"), "=== on values(abc === ABC)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
27 isa_ok ("abc" === "abc"), Bool, "=== on values (abc)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
28 ok !(1 === 1.0), "=== on values (1 === 1.0)";
29 ok !(1 === "1"), '=== on values (1 === "1")';
8f9a119 [t/] unify compartmentalized undef and Object concepts into Mu
lwall authored
30 ok (Mu === Mu), '=== on values (Mu === Mu)';
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
31 isa_ok (Mu === Mu), Bool, '=== on values (Mu === Mu)';
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
32 }
33
ae00034 [t/spec] === tests on Rat and Num.
colomon authored
34 # more value tests
35 {
36 #?rakudo todo "=== broken on Rat"
37 ok 1/2 === 1/2, "=== on Rats";
38 ok 1/2 !=== 3/2, "!=== on Rats";
39 isa_ok 1/2 === 1/2, Bool, "=== on Rats yields Bool";
40 isa_ok 1/2 !=== 3/2, Bool, "!=== on Rats yields Bool";
41 ok 0.5e0 === 0.5e0, "=== on Nums";
42 ok 0.5e0 !=== 1.5e0, "!=== on Nums";
43 #?rakudo todo "=== does not yield Bool on Num"
44 isa_ok 0.5e0 === 0.5e0, Bool, "=== on Nums yields Bool";
45 isa_ok 0.5e0 !=== 1.5e0, Bool, "!=== on Nums yields Bool";
46 }
47
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
48 # Value types
49 {
50 my $a = 1;
51 my $b = 1;
52
53 ok $a === $a, "=== on value types (1-1)";
54 ok $b === $b, "=== on value types (1-2)";
55 ok $a === $b, "=== on value types (1-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
56 isa_ok $a === $b, Bool, "=== on value types (1-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
57 }
58
59 {
60 my $a = 1;
61 my $b = 2;
62
63 ok ($a === $a), "=== on value types (2-1)";
64 ok ($b === $b), "=== on value types (2-2)";
65 ok !($a === $b), "=== on value types (2-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
66 isa_ok ($a === $a), Bool, "=== on value types (2-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
67 }
68
69 # Reference types
70 {
71 my @a = (1,2,3);
72 my @b = (1,2,3);
73
2a90d08 [t/spec] Fudge value_equivalence.t.
colomon authored
74 #?rakudo 2 todo "=== doesn't work on array references yet"
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
75 ok (\@a === \@a), "=== on array references (1)";
76 ok (\@b === \@b), "=== on array references (2)";
77 ok !(\@a === \@b), "=== on array references (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
78 isa_ok (\@a === \@a), Bool, "=== on array references (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
79 }
80
81 {
82 my $a = \3;
83 my $b = \3;
84
85 ok ($a === $a), "=== on scalar references (1-1)";
86 ok ($b === $b), "=== on scalar references (1-2)";
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 ra...
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 ra...
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 ra...
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"
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
116 ok ($a === $b), "=== on scalar references (2-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
117 isa_ok ($a === $a), Bool, "=== on scalar references (2-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
118 }
119
120 {
121 ok !([1,2,3] === [4,5,6]), "=== on anonymous array references (1)";
122 ok !([1,2,3] === [1,2,3]), "=== on anonymous array references (2)";
123 ok !([] === []), "=== on anonymous array references (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
124 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 ra...
Auzon authored
125 }
126
127 {
128 ok !({a => 1} === {a => 2}), "=== on anonymous hash references (1)";
129 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
130 isa_ok ({a => 1} === {a => 2}), Bool, "=== on anonymous hash references (3)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
131 }
132
133 {
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
134 ok !(\3 === \4), "=== on anonymous scalar references (1)";
135 ok !(\3 === \3), "=== on anonymous scalar references (2)";
136 ok !(\Mu === \Mu), "=== on anonymous scalar references (3)";
137 isa_ok (\3 === \4), Bool, "=== on anonymous scalar references (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
138 }
139
140 # Chained === (not specced, but obvious)
141 {
142 ok (3 === 3 === 3), "chained === (1)";
143 ok !(3 === 3 === 4), "chained === (2)";
144 }
145
146 # Subparam binding doesn't affect === test
147 {
148 my $foo;
149 my $test = -> $arg { $foo === $arg };
150
151 $foo = 3;
152 ok $test($foo), "subparam binding doesn't affect === (1)";
153 ok $test(3), "subparam binding doesn't affect === (2)";
154
155 ok !$test(4), "subparam binding doesn't affect === (3)";
156 my $bar = 4;
157 ok !$test($bar), "subparam binding doesn't affect === (4)";
158 }
159
160 {
161 my $a = 1;
162 my $b = 2;
163 is($a === $a, Bool::True, '=== returns Bool::True when true');
164 is($a === $b, Bool::False, '=== returns Bool::False when false');
165 }
166
167 # L<S03/"Chaining binary precedence" /Negated relational operators>
168 {
169 ok !(1 !=== 1), "!=== on values (1)";
170 ok !(0 !=== 0), "!=== on values (2)";
171 ok (1 !=== 0), "!=== on values (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
172 isa_ok (1 !=== 1), Bool, "!=== on values (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
173 ok !("abc" !=== "abc"), "!=== on values(abc)";
174 ok ("abc" !=== "ABC"), "!=== on values(abc !=== ABC)";
175 ok (1 !=== 1.0), "!=== on values (1 !=== 1.0)";
176 ok (1 !=== "1"), '!=== on values (1 !=== "1")';
177 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
178
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
179 done_testing;
180
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
181 # vim: ft=perl6
Something went wrong with that request. Please try again.