Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 213 lines (182 sloc) 9.398 kB
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
1 use v6;
2
3 use Test;
4
0877354 [t/spec] unfudge tests for RT #67882, and add a few more (because I d…
moritz authored
5 plan 110;
7f76022 [t/spec] forbid lists and ranges as Range end points (as per r28171)
moritz authored
6
7
8 # L<S03/Nonchaining binary precedence/Range object constructor>
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
9
10 # 3..2 must *not* produce "3 2". Use reverse to get a reversed range. -lwall
11
12 is ~(3..6), "3 4 5 6", "(..) works on numbers (1)";
13 is ~(3..3), "3", "(..) works on numbers (2)";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
14 is ~(3..2), "", "(..) works on auto-rev numbers (3)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
15 is ~(8..11), "8 9 10 11", "(..) works on carried numbers (3)";
16
17 is ~("a".."c"), "a b c", "(..) works on chars (1)";
18 is ~("a".."a"), "a", "(..) works on chars (2)";
19 is ~("b".."a"), "", "(..) works on chars (3)";
2bb1c63 [t/spec] Refudge to work with list branch.
colomon authored
20 #?rakudo todo "Think master still gets this one wrong"
21 is ~("Y".."AB"), "", "(..) works on carried chars (3)";
22 #?rakudo todo "This test is now incorrect"
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
23 is ~("AB".."Y"), "", "(..) works on auto-rev carried chars (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
24
2bb1c63 [t/spec] Refudge to work with list branch.
colomon authored
25 #?rakudo 4 skip 'Spec under design here'
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
26 is ~('Y'..'z'), 'Y Z', '(..) works on uppercase letter .. lowercase letter (1)';
27 is ~('z'..'Y'), '', '(..) works on auto-rev uppercase letter .. lowercase letter (2)';
28 is ~('Y'..'_'), 'Y Z', '(..) works on letter .. non-letter (1)';
29 is ~('_'..'Y'), '', '(..) works on auto-rev letter .. non-letter (2)';
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
30
31 is ~(3..9-3), "3 4 5 6", "(..) has correct precedence (1)";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
32 is ~(5..9-5), "", "(..) has correct precedence (2)";
33 is ~(2+1..6), "3 4 5 6", "(..) has correct precedence (3)";
34 is ~(2+5..6), "", "(..) has correct precedence (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
35
36 # Test the three exclusive range operators:
832f178 [t/spec] fix more smartlinks; down to 33 broken links
moritz authored
37 # L<S03/Range and RangeIter semantics/range operator has variants>
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
38 is [1^..9], [2..9], "bottom-exclusive range (^..) works (1)";
39 is [2^..2], [], "bottom-exclusive range (^..) works (2)";
40 is [3^..2], [], "bottom-exclusive auto-rev range (^..) works (3)";
41 is [1 ..^9], [1..8], "top-exclusive range (..^) works (1)";
42 is [2 ..^2], [], "top-exclusive range (..^) works (2)";
43 is [3 ..^2], [], "top-exclusive auto-rev range (..^) works (3)";
44 is [1^..^9], [2..8], "double-exclusive range (^..^) works (1)";
45 is [9^..^1], [], "double-exclusive auto-rev range (^..^) works (2)";
46 is [1^..^2], [], "double-exclusive range (^..^) can produce null range (1)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
47
48 # tests of (x ^..^ x) here and below ensure that our implementation
49 # of double-exclusive range does not blindly remove an element
50 # from the head and tail of a list
51 is [1^..^1], [], "double-exclusive range (x ^..^ x) where x is an int";
52
53 is ["a"^.."z"], ["b".."z"], "bottom-exclusive string range (^..) works";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
54 is ["z"^.."a"], [], "bottom-exclusive string auto-rev range (^..) works";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
55 is ["a"..^"z"], ["a".."y"], "top-exclusive string range (..^) works";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
56 is ["z"..^"a"], [], "top-exclusive string auto-rev range (..^) works";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
57 is ["a"^..^"z"], ["b".."y"], "double-exclusive string range (^..^) works";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
58 is ["z"^..^"a"], [], "double-exclusive string auto-rev range (^..^) works";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
59 is ['a'^..^'b'], [], "double-exclusive string range (^..^) can produce null range";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
60 is ['b'^..^'a'], [], "double-exclusive string auto-rev range (^..^) can produce null range";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
61 is ['a' ^..^ 'a'], [], "double-exclusive range (x ^..^ x) where x is a char";
62
ba8e84a [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
63 #?pugs todo 'bug'
64 is 1.5 ~~ 1^..^2, Bool::True, "lazy evaluation of the range operator";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
65
66 # Test the unary ^ operator
67 is ~(^5), "0 1 2 3 4", "unary ^num produces the range 0..^num";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
68 is [^1], [0], "unary ^ on the boundary ^1 works";
69 is [^0], [], "unary ^0 produces null range";
70 is [^-1], [], "unary ^-1 produces null range";
71 is [^0.1], [0], "unary ^0.1 produces the range 0..^x where 0 < x < 1";
72 is [^'a'], [], "unary ^'a' produces null range";
64b5bba [t/spec] Refudge a tad, add a couple of tests to make sure prefix:<^>…
colomon authored
73 is ~(^"5"), "0 1 2 3 4", 'unary ^"num" produces the range 0..^num';
74
75 {
76 my @a = 3, 5, 3;
77 is (^@a).perl, (0..^3).perl, 'unary ^@a produces 0..^+@a';
78 }
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
79
e8dc6d6 [t/spec] regression tests for RT #60898 (ranges + infix:<Z>)
moritz authored
80 # test that the zip operator works with ranges
81 is (1..5 Z <a b c>).join('|'), '1|a|2|b|3|c', 'Ranges and infix:<Z>';
82 is (1..2 Z <a b c>).join('|'), '1|a|2|b', 'Ranges and infix:<Z>';
83 is (<c b a> Z 1..5).join('|'), 'c|1|b|2|a|3', 'Ranges and infix:<Z>';
84
85 # two ranges
49d046f .join now defaults to ''
lwall authored
86 is (1..6 Z 'a' .. 'c').join, '1a2b3c', 'Ranges and infix:<Z>';
e8dc6d6 [t/spec] regression tests for RT #60898 (ranges + infix:<Z>)
moritz authored
87
ba2d31c [spec] fudged and corrected range.t
moritz authored
88 {
89 # Test with floats
90 # 2006-12-05:
91 # 16:16 <TimToady> ~(1.9 ^..^ 4.9) should produce 2.9, 3.9
92 # 16:17 <pmichaud> and ~(1.9 ^..^ 4.5) would produce the same?
93 # 16:17 <TimToady> yes
94 is ~(1.1 .. 4) , "1.1 2.1 3.1", "range with float .min";
95 is ~(1.9 .. 4) , "1.9 2.9 3.9", "range with float .min";
96 is ~(1.1 ^.. 4), "2.1 3.1" , "bottom exclusive range of float";
97 is ~(1.9 ^.. 4), "2.9 3.9" , "bottom exclusive range of float";
98
99 is ~(1 .. 4.1) , "1 2 3 4", "range with float .max";
100 is ~(1 .. 4.9) , "1 2 3 4", "range with float .max";
101 is ~(1 ..^ 4.1), "1 2 3 4", "top exclusive range of float";
102 is ~(1 ..^ 4.9), "1 2 3 4", "top exclusive range of float";
103
104 is ~(1.1 .. 4.1), "1.1 2.1 3.1 4.1", "range with float .min/.max";
105 is ~(1.9 .. 4.1), "1.9 2.9 3.9" , "range with float .min/.max";
106 is ~(1.1 .. 4.9), "1.1 2.1 3.1 4.1", "range with float .min/.max";
107 is ~(1.9 .. 4.9), "1.9 2.9 3.9 4.9", "range with float .min/.max";
108
109 is ~(1.1 ^..^ 4.1), "2.1 3.1" , "both exclusive float range";
110 is ~(1.9 ^..^ 4.1), "2.9 3.9" , "both exclusive float range";
111 is ~(1.1 ^..^ 4.9), "2.1 3.1 4.1", "both exclusive float range";
112 is ~(1.9 ^..^ 4.9), "2.9 3.9" , "both exclusive float range";
113 is [1.1 ^..^ 1.1], [], "double-exclusive range (x ^..^ x) where x is a float";
114 }
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
115
116 # Test that the operands are forced to scalar context
748e055 S03-operators/range.t: Add note about use of @array as arguments to …
pmichaud authored
117 ## From pmichaud 2006-06-30: These tests may be incorrect.
118 ## C<@one> in ## item context returns an Array, not a number
119 ## -- use C< +@one > to get the number of elements. So, we
120 ## need to either declare that there's a version of infix:<..>
121 ## that coerces its arguments to numeric context, or we can
122 ## remove these tests from the suite.
ba2d31c [spec] fudged and corrected range.t
moritz authored
123 #?rakudo skip 'MMD function __cmp not found for types (101, 95)'
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
124 {
125 my @three = (1, 1, 1);
f07dd23 [t/spec] a test for Range.map
moritz authored
126 my @one = 1;
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
127
128 is ~(@one .. 3) , "1 2 3", "lower inclusive limit is in scalar context";
129 is ~(@one ^.. 3) , "2 3" , "lower exclusive limit is in scalar context";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
130 is ~(3 ^.. @one) , "" , "lower exclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
131 is ~(1 .. @three) , "1 2 3", "upper inclusive limit is in scalar context";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
132 is ~(4 .. @three) , "" , "upper inclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
133 is ~(1 ..^ @three) , "1 2" , "upper exclusive limit is in scalar context";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
134 is ~(4 ..^ @three) , "" , "upper exclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
135 is ~(@one .. @three), "1 2 3", "both inclusive limits are in scalar context";
136 is ~(@three .. @one), "" , "null range produced with lists forced to scalar context";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
137 is ~(@one ^..^ @three), "2" , "both exclusive limits are in scalar context";
138 is ~(@three ^..^ @one), "" , "both exclusive limits are in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
139 }
140
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
141 # test that .map and .grep work on ranges
f07dd23 [t/spec] a test for Range.map
moritz authored
142 {
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
143 is (0..3).map({$_ * 2}).join('|'), '0|2|4|6', '.map works on ranges';
144 is (0..3).grep({$_ == 1|3}).join('|'), '1|3', '.grep works on ranges';
b0e0a3a [t/spec] test that .first and .reduce work on ranges
moritz authored
145 is (1..3).first({ $_ % 2 == 0}), 2, '.first works on ranges';
146 is (1..3).reduce({ $^a + $^b}), 6, '.reduce works on ranges';
f07dd23 [t/spec] a test for Range.map
moritz authored
147 }
148
d4459dc Add another range test case around the match operator, and an equival…
colomon authored
149 # test that range operands are handled in string context if strings
150 {
151 my $range;
152 my $start = "100.B";
153 my $end = "102.B";
154 lives_ok { $range = $start..$end },
155 'can make range from numeric string vars';
0a84065 [t/spec] Fudge for ng.
colomon authored
156 is $range.min, $start, 'range starts at start';
157 is $range.min.WHAT, "Str()", 'range start is a string';
158 is $range.max, $end, 'range ends at end';
159 is $range.max.WHAT, "Str()", 'range end is a string';
d4459dc Add another range test case around the match operator, and an equival…
colomon authored
160 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
161 is ~$range, "100.B 101.B 102.B", 'range is correct';
d4459dc Add another range test case around the match operator, and an equival…
colomon authored
162 }
0a84065 [t/spec] Fudge for ng.
colomon authored
163
b390af6 Tag test with RT number.
colomon authored
164 # RT #67882
82915ee [t/spec] Test bug from colomon++
kyle authored
165 {
166 my $range;
167 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = $0..$1 },
168 'can make range from match vars';
0a84065 [t/spec] Fudge for ng.
colomon authored
169 is $range.min, 1, 'range starts at one';
170 is $range.max, 3, 'range ends at three';
82915ee [t/spec] Test bug from colomon++
kyle authored
171 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
172 is ~$range, "1 2 3", 'range is correct';
82915ee [t/spec] Test bug from colomon++
kyle authored
173 }
0877354 [t/spec] unfudge tests for RT #67882, and add a few more (because I d…
moritz authored
174 # and another set, just for the lulz
175 # RT #67882
176 {
177 ok '1 3' ~~ /(\d) . (\d)/, 'regex sanity';
178 isa_ok $0..$1, Range, '$0..$1 constructs a Range';
179 is ($0..$1).join('|'), '1|2|3', 'range from $0..$1';
180 }
82915ee [t/spec] Test bug from colomon++
kyle authored
181 {
182 my $range;
183 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = +$0..+$1 },
184 'can make range from match vars with numeric context forced';
0a84065 [t/spec] Fudge for ng.
colomon authored
185 is $range.min, 1, 'range starts at one';
186 is $range.max, 3, 'range ends at three';
82915ee [t/spec] Test bug from colomon++
kyle authored
187 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
188 is ~$range, "1 2 3", 'range is correct';
d4459dc Add another range test case around the match operator, and an equival…
colomon authored
189 }
190 {
191 my $range;
192 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = ~$0..~$1 },
193 'can make range from match vars with string context forced';
0a84065 [t/spec] Fudge for ng.
colomon authored
194 is $range.min, 1, 'range starts at one';
195 is $range.min.WHAT, "Str()", 'range start is a string';
196 is $range.max, 3, 'range ends at three';
197 is $range.max.WHAT, "Str()", 'range end is a string';
d4459dc Add another range test case around the match operator, and an equival…
colomon authored
198 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
199 is ~$range, "1 2 3", 'range is correct';
82915ee [t/spec] Test bug from colomon++
kyle authored
200 }
201
7f76022 [t/spec] forbid lists and ranges as Range end points (as per r28171)
moritz authored
202 # L<S03/Nonchaining binary precedence/it is illegal to use a Range or a
203 # List as implicitly numeric:>
204
205 #?rakudo todo 'forbid Ranges and Lists as Range endpoints'
206 {
207 ok !defined(try { 0 .. ^10 }), '0 .. ^10 is illegal';
208 ok !defined(try { 0 .. (0, 1, 2) }), '0 .. List is illegal';
209 }
210
0877354 [t/spec] unfudge tests for RT #67882, and add a few more (because I d…
moritz authored
211
0a84065 [t/spec] Fudge for ng.
colomon authored
212 # # vim: ft=perl6
Something went wrong with that request. Please try again.