Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 181 lines (148 sloc) 5.272 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
643bc98 replace plan *; with number of tests S03
mberends 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)";
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…
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…
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…
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 isa_ok 0.5e0 === 0.5e0, Bool, "=== on Nums yields Bool";
44 isa_ok 0.5e0 !=== 1.5e0, Bool, "!=== on Nums yields Bool";
45 }
46
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
47 # Value types
48 {
49 my $a = 1;
50 my $b = 1;
51
52 ok $a === $a, "=== on value types (1-1)";
53 ok $b === $b, "=== on value types (1-2)";
54 ok $a === $b, "=== on value types (1-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
55 isa_ok $a === $b, Bool, "=== on value types (1-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
56 }
57
58 {
59 my $a = 1;
60 my $b = 2;
61
62 ok ($a === $a), "=== on value types (2-1)";
63 ok ($b === $b), "=== on value types (2-2)";
64 ok !($a === $b), "=== on value types (2-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
65 isa_ok ($a === $a), Bool, "=== on value types (2-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
66 }
67
68 # Reference types
69 {
70 my @a = (1,2,3);
71 my @b = (1,2,3);
72
2a90d08 [t/spec] Fudge value_equivalence.t.
colomon authored
73 #?rakudo 2 todo "=== doesn't work on array references yet"
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
74 ok (\@a === \@a), "=== on array references (1)";
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)";
b21f28d [t/spec]: rakudo fudging and test fixes
pmichaud authored
86 ok !($a === $b), "=== on scalar references (1-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
87 isa_ok ($a === $a), Bool, "=== on scalar references (1-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
88 }
89
90 {
91 my $a = { 3 };
92 my $b = { 3 };
93
94 ok ($a === $a), "=== on sub references (1-1)";
95 ok ($b === $b), "=== on sub references (1-2)";
96 ok !($a === $b), "=== on sub references (1-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
97 isa_ok ($a === $a), Bool, "=== on sub references (1-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
98 }
99
100 {
101 ok (&say === &say), "=== on sub references (2-1)";
102 ok (&map === &map), "=== on sub references (2-2)";
103 ok !(&say === &map), "=== on sub references (2-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
104 isa_ok (&say === &say), Bool, "=== on sub references (2-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
105 }
106
107 {
108 my $num = 3;
109 my $a = \$num;
110 my $b = \$num;
111
112 ok ($a === $a), "=== on scalar references (2-1)";
113 ok ($b === $b), "=== on scalar references (2-2)";
2a90d08 [t/spec] Fudge value_equivalence.t.
colomon authored
114 #?rakudo todo "=== fail"
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
115 ok ($a === $b), "=== on scalar references (2-3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
116 isa_ok ($a === $a), Bool, "=== on scalar references (2-4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
117 }
118
119 {
120 ok !([1,2,3] === [4,5,6]), "=== on anonymous array references (1)";
121 ok !([1,2,3] === [1,2,3]), "=== on anonymous array references (2)";
122 ok !([] === []), "=== on anonymous array references (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
123 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
124 }
125
126 {
127 ok !({a => 1} === {a => 2}), "=== on anonymous hash references (1)";
128 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
129 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
130 }
131
132 {
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
133 ok !(\3 === \4), "=== on anonymous scalar references (1)";
134 ok !(\3 === \3), "=== on anonymous scalar references (2)";
135 ok !(\Mu === \Mu), "=== on anonymous scalar references (3)";
136 isa_ok (\3 === \4), Bool, "=== on anonymous scalar references (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
137 }
138
139 # Chained === (not specced, but obvious)
140 {
141 ok (3 === 3 === 3), "chained === (1)";
142 ok !(3 === 3 === 4), "chained === (2)";
143 }
144
145 # Subparam binding doesn't affect === test
146 {
147 my $foo;
148 my $test = -> $arg { $foo === $arg };
149
150 $foo = 3;
151 ok $test($foo), "subparam binding doesn't affect === (1)";
152 ok $test(3), "subparam binding doesn't affect === (2)";
153
154 ok !$test(4), "subparam binding doesn't affect === (3)";
155 my $bar = 4;
156 ok !$test($bar), "subparam binding doesn't affect === (4)";
157 }
158
159 {
160 my $a = 1;
161 my $b = 2;
162 is($a === $a, Bool::True, '=== returns Bool::True when true');
163 is($a === $b, Bool::False, '=== returns Bool::False when false');
164 }
165
166 # L<S03/"Chaining binary precedence" /Negated relational operators>
167 {
168 ok !(1 !=== 1), "!=== on values (1)";
169 ok !(0 !=== 0), "!=== on values (2)";
170 ok (1 !=== 0), "!=== on values (3)";
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
171 isa_ok (1 !=== 1), Bool, "!=== on values (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
172 ok !("abc" !=== "abc"), "!=== on values(abc)";
173 ok ("abc" !=== "ABC"), "!=== on values(abc !=== ABC)";
174 ok (1 !=== 1.0), "!=== on values (1 !=== 1.0)";
175 ok (1 !=== "1"), '!=== on values (1 !=== "1")';
176 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
177
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
178 done;
60babe2 [t/spec] Add a bunch of tests to make sure === and !=== return Bool.
colomon authored
179
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
180 # vim: ft=perl6
Something went wrong with that request. Please try again.