Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 147 lines (117 sloc) 3.792 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 L<S03/"Chaining binary precedence" /Value identity>
8
9 C<===> and C<eqv> are 2 distinct operators, where C<===> tests value
10 equivalence for immutable types and reference equivalence for
11 mutable types, and C<eqv> tests value equivalence for snapshots of mutable
12 types. So C<(1,2) === (1,2)> returns true but C<[1,2] === [1,2]> returns
13 false, and C<[1,2] eqv [1,2]> returns true.
14
15 =end pod
16
17 plan 51;
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)";
24 ok ("abc" === "abc"), "=== on values(abc)";
25 ok !("abc" === "ABC"), "=== on values(abc === ABC)";
26 ok !(1 === 1.0), "=== on values (1 === 1.0)";
27 ok !(1 === "1"), '=== on values (1 === "1")';
28 }
29
30 # Value types
31 {
32 my $a = 1;
33 my $b = 1;
34
35 ok $a === $a, "=== on value types (1-1)";
36 ok $b === $b, "=== on value types (1-2)";
37 ok $a === $b, "=== on value types (1-3)";
38 }
39
40 {
41 my $a = 1;
42 my $b = 2;
43
44 ok ($a === $a), "=== on value types (2-1)";
45 ok ($b === $b), "=== on value types (2-2)";
46 ok !($a === $b), "=== on value types (2-3)";
47 }
48
49 # Reference types
50 {
51 my @a = (1,2,3);
52 my @b = (1,2,3);
53
54 ok (\@a === \@a), "=== on array references (1)";
55 ok (\@b === \@b), "=== on array references (2)";
56 ok !(\@a === \@b), "=== on array references (3)";
57 }
58
59 {
60 my $a = \3;
61 my $b = \3;
62
63 ok ($a === $a), "=== on scalar references (1-1)";
64 ok ($b === $b), "=== on scalar references (1-2)";
65 ok !($a === $b), "=== on scalar references (1-3)", :todo<bug>;
66 }
67
68 {
69 my $a = { 3 };
70 my $b = { 3 };
71
72 ok ($a === $a), "=== on sub references (1-1)";
73 ok ($b === $b), "=== on sub references (1-2)";
74 ok !($a === $b), "=== on sub references (1-3)";
75 }
76
77 {
78 ok (&say === &say), "=== on sub references (2-1)";
79 ok (&map === &map), "=== on sub references (2-2)";
80 ok !(&say === &map), "=== on sub references (2-3)";
81 }
82
83 {
84 my $num = 3;
85 my $a = \$num;
86 my $b = \$num;
87
88 ok ($a === $a), "=== on scalar references (2-1)";
89 ok ($b === $b), "=== on scalar references (2-2)";
90 ok ($a === $b), "=== on scalar references (2-3)";
91 }
92
93 {
94 ok !([1,2,3] === [4,5,6]), "=== on anonymous array references (1)";
95 ok !([1,2,3] === [1,2,3]), "=== on anonymous array references (2)";
96 ok !([] === []), "=== on anonymous array references (3)";
97 }
98
99 {
100 ok !({a => 1} === {a => 2}), "=== on anonymous hash references (1)";
101 ok !({a => 1} === {a => 1}), "=== on anonymous hash references (2)";
102 }
103
104 {
105 ok !(\3 === \4), "=== on anonymous scalar references (1)";
106 ok !(\3 === \3), "=== on anonymous scalar references (2)", :todo<bug>;
107 ok !(\undef === \undef), "=== on anonymous scalar references (3)", :todo<bug>;
108 }
109
110 # Chained === (not specced, but obvious)
111 {
112 ok (3 === 3 === 3), "chained === (1)";
113 ok !(3 === 3 === 4), "chained === (2)";
114 }
115
116 # Subparam binding doesn't affect === test
117 {
118 my $foo;
119 my $test = -> $arg { $foo === $arg };
120
121 $foo = 3;
122 ok $test($foo), "subparam binding doesn't affect === (1)";
123 ok $test(3), "subparam binding doesn't affect === (2)";
124
125 ok !$test(4), "subparam binding doesn't affect === (3)";
126 my $bar = 4;
127 ok !$test($bar), "subparam binding doesn't affect === (4)";
128 }
129
130 {
131 my $a = 1;
132 my $b = 2;
133 is($a === $a, Bool::True, '=== returns Bool::True when true');
134 is($a === $b, Bool::False, '=== returns Bool::False when false');
135 }
136
137 # L<S03/"Chaining binary precedence" /Negated relational operators>
138 {
139 ok !(1 !=== 1), "!=== on values (1)";
140 ok !(0 !=== 0), "!=== on values (2)";
141 ok (1 !=== 0), "!=== on values (3)";
142 ok !("abc" !=== "abc"), "!=== on values(abc)";
143 ok ("abc" !=== "ABC"), "!=== on values(abc !=== ABC)";
144 ok (1 !=== 1.0), "!=== on values (1 !=== 1.0)";
145 ok (1 !=== "1"), '!=== on values (1 !=== "1")';
146 }
Something went wrong with that request. Please try again.