Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 152 lines (122 sloc) 3.957 kb
9a586172 »
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
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
85884858 »
2008-08-04 [t/spec] unfudge and s/skip/todo/ some tests for rakudo
54 #?rakudo 2 todo 'prefix:<\\>'
9a586172 »
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
55 ok (\@a === \@a), "=== on array references (1)";
56 ok (\@b === \@b), "=== on array references (2)";
57 ok !(\@a === \@b), "=== on array references (3)";
58 }
59
60 {
61 my $a = \3;
62 my $b = \3;
63
64 ok ($a === $a), "=== on scalar references (1-1)";
65 ok ($b === $b), "=== on scalar references (1-2)";
b21f28db »
2008-12-16 [t/spec]: rakudo fudging and test fixes
66 #?rakudo todo 'scalar reference equivalence'
67 ok !($a === $b), "=== on scalar references (1-3)";
9a586172 »
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
68 }
69
70 {
71 my $a = { 3 };
72 my $b = { 3 };
73
74 ok ($a === $a), "=== on sub references (1-1)";
75 ok ($b === $b), "=== on sub references (1-2)";
76 ok !($a === $b), "=== on sub references (1-3)";
77 }
78
79 {
80 ok (&say === &say), "=== on sub references (2-1)";
81 ok (&map === &map), "=== on sub references (2-2)";
82 ok !(&say === &map), "=== on sub references (2-3)";
83 }
84
85 {
86 my $num = 3;
87 my $a = \$num;
88 my $b = \$num;
89
90 ok ($a === $a), "=== on scalar references (2-1)";
91 ok ($b === $b), "=== on scalar references (2-2)";
85884858 »
2008-08-04 [t/spec] unfudge and s/skip/todo/ some tests for rakudo
92 #?rakudo todo 'prefix:<\\>'
9a586172 »
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
93 ok ($a === $b), "=== on scalar references (2-3)";
94 }
95
96 {
97 ok !([1,2,3] === [4,5,6]), "=== on anonymous array references (1)";
98 ok !([1,2,3] === [1,2,3]), "=== on anonymous array references (2)";
99 ok !([] === []), "=== on anonymous array references (3)";
100 }
101
102 {
103 ok !({a => 1} === {a => 2}), "=== on anonymous hash references (1)";
104 ok !({a => 1} === {a => 1}), "=== on anonymous hash references (2)";
105 }
106
107 {
108 ok !(\3 === \4), "=== on anonymous scalar references (1)";
b21f28db »
2008-12-16 [t/spec]: rakudo fudging and test fixes
109 #?rakudo todo 'scalar reference equivalence'
110 ok !(\3 === \3), "=== on anonymous scalar references (2)";
111 ok !(\undef === \undef), "=== on anonymous scalar references (3)";
9a586172 »
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
112 }
113
114 # Chained === (not specced, but obvious)
115 {
116 ok (3 === 3 === 3), "chained === (1)";
117 ok !(3 === 3 === 4), "chained === (2)";
118 }
119
120 # Subparam binding doesn't affect === test
3cd8f82b »
2008-06-30 [spec] fudged value_equivalence.t. Rakudo now parses it, but doesn't
121 #?rakudo skip 'pointy blocks as expressions'
9a586172 »
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
122 {
123 my $foo;
124 my $test = -> $arg { $foo === $arg };
125
126 $foo = 3;
127 ok $test($foo), "subparam binding doesn't affect === (1)";
128 ok $test(3), "subparam binding doesn't affect === (2)";
129
130 ok !$test(4), "subparam binding doesn't affect === (3)";
131 my $bar = 4;
132 ok !$test($bar), "subparam binding doesn't affect === (4)";
133 }
134
135 {
136 my $a = 1;
137 my $b = 2;
138 is($a === $a, Bool::True, '=== returns Bool::True when true');
139 is($a === $b, Bool::False, '=== returns Bool::False when false');
140 }
141
142 # L<S03/"Chaining binary precedence" /Negated relational operators>
143 {
144 ok !(1 !=== 1), "!=== on values (1)";
145 ok !(0 !=== 0), "!=== on values (2)";
146 ok (1 !=== 0), "!=== on values (3)";
147 ok !("abc" !=== "abc"), "!=== on values(abc)";
148 ok ("abc" !=== "ABC"), "!=== on values(abc !=== ABC)";
149 ok (1 !=== 1.0), "!=== on values (1 !=== 1.0)";
150 ok (1 !=== "1"), '!=== on values (1 !=== "1")';
151 }
Something went wrong with that request. Please try again.