Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 231 lines (197 sloc) 9.727 kB
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
1 use v6;
2
3 use Test;
4
62713eb @moritz [range.t] fix plan
moritz authored
5 plan 113;
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)";
b5ee073 [t/spec] Unfudge series / Range tests Rakudo now passes, and add a fe…
colomon authored
20 is ~("a".."z"), "a b c d e f g h i j k l m n o p q r s t u v w x y z", "(..) works on char range ending in z";
21 is ~("A".."Z"), "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z", "(..) works on char range ending in Z";
2bb1c63 [t/spec] Refudge to work with list branch.
colomon authored
22 is ~("Y".."AB"), "", "(..) works on carried chars (3)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
23
2bb1c63 [t/spec] Refudge to work with list branch.
colomon authored
24 #?rakudo 4 skip 'Spec under design here'
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
25 is ~('Y'..'z'), 'Y Z', '(..) works on uppercase letter .. lowercase letter (1)';
26 is ~('z'..'Y'), '', '(..) works on auto-rev uppercase letter .. lowercase letter (2)';
27 is ~('Y'..'_'), 'Y Z', '(..) works on letter .. non-letter (1)';
28 is ~('_'..'Y'), '', '(..) works on auto-rev letter .. non-letter (2)';
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
29
3da5e46 [t/spec] test for RT #76226, all-whitespace range
moritz authored
30 is ~(' '..' '), ' ', 'all-whitespace range works';
31
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
32 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
33 is ~(5..9-5), "", "(..) has correct precedence (2)";
34 is ~(2+1..6), "3 4 5 6", "(..) has correct precedence (3)";
35 is ~(2+5..6), "", "(..) has correct precedence (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
36
37 # Test the three exclusive range operators:
832f178 [t/spec] fix more smartlinks; down to 33 broken links
moritz authored
38 # 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
39 is [1^..9], [2..9], "bottom-exclusive range (^..) works (1)";
40 is [2^..2], [], "bottom-exclusive range (^..) works (2)";
41 is [3^..2], [], "bottom-exclusive auto-rev range (^..) works (3)";
42 is [1 ..^9], [1..8], "top-exclusive range (..^) works (1)";
43 is [2 ..^2], [], "top-exclusive range (..^) works (2)";
44 is [3 ..^2], [], "top-exclusive auto-rev range (..^) works (3)";
45 is [1^..^9], [2..8], "double-exclusive range (^..^) works (1)";
46 is [9^..^1], [], "double-exclusive auto-rev range (^..^) works (2)";
47 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
48
49 # tests of (x ^..^ x) here and below ensure that our implementation
50 # of double-exclusive range does not blindly remove an element
51 # from the head and tail of a list
52 is [1^..^1], [], "double-exclusive range (x ^..^ x) where x is an int";
53
54 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
55 is ["z"^.."a"], [], "bottom-exclusive string auto-rev range (^..) works";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
56 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
57 is ["z"..^"a"], [], "top-exclusive string auto-rev range (..^) works";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
58 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
59 is ["z"^..^"a"], [], "double-exclusive string auto-rev range (^..^) works";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
60 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
61 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
62 is ['a' ^..^ 'a'], [], "double-exclusive range (x ^..^ x) where x is a char";
63
ba8e84a [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
64 #?pugs todo 'bug'
65 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
66
67 # Test the unary ^ operator
68 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
69 is [^1], [0], "unary ^ on the boundary ^1 works";
70 is [^0], [], "unary ^0 produces null range";
71 is [^-1], [], "unary ^-1 produces null range";
72 is [^0.1], [0], "unary ^0.1 produces the range 0..^x where 0 < x < 1";
73 is [^'a'], [], "unary ^'a' produces null range";
64b5bba [t/spec] Refudge a tad, add a couple of tests to make sure prefix:<^>…
colomon authored
74 is ~(^"5"), "0 1 2 3 4", 'unary ^"num" produces the range 0..^num';
75
76 {
77 my @a = 3, 5, 3;
78 is (^@a).perl, (0..^3).perl, 'unary ^@a produces 0..^+@a';
79 }
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
80
b5ee073 [t/spec] Unfudge series / Range tests Rakudo now passes, and add a fe…
colomon authored
81 # test iterating on infinite ranges
82 is (1..*).[^5].join('|'), '1|2|3|4|5', '1..*';
83 is ('a'..*).[^5].join('|'), 'a|b|c|d|e', '"a"..*';
84
e8dc6d6 [t/spec] regression tests for RT #60898 (ranges + infix:<Z>)
moritz authored
85 # test that the zip operator works with ranges
86 is (1..5 Z <a b c>).join('|'), '1|a|2|b|3|c', 'Ranges and infix:<Z>';
87 is (1..2 Z <a b c>).join('|'), '1|a|2|b', 'Ranges and infix:<Z>';
88 is (<c b a> Z 1..5).join('|'), 'c|1|b|2|a|3', 'Ranges and infix:<Z>';
89
90 # two ranges
49d046f .join now defaults to ''
lwall authored
91 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
92
ba2d31c [spec] fudged and corrected range.t
moritz authored
93 {
94 # Test with floats
95 # 2006-12-05:
96 # 16:16 <TimToady> ~(1.9 ^..^ 4.9) should produce 2.9, 3.9
97 # 16:17 <pmichaud> and ~(1.9 ^..^ 4.5) would produce the same?
98 # 16:17 <TimToady> yes
99 is ~(1.1 .. 4) , "1.1 2.1 3.1", "range with float .min";
100 is ~(1.9 .. 4) , "1.9 2.9 3.9", "range with float .min";
101 is ~(1.1 ^.. 4), "2.1 3.1" , "bottom exclusive range of float";
102 is ~(1.9 ^.. 4), "2.9 3.9" , "bottom exclusive range of float";
103
104 is ~(1 .. 4.1) , "1 2 3 4", "range with float .max";
105 is ~(1 .. 4.9) , "1 2 3 4", "range with float .max";
106 is ~(1 ..^ 4.1), "1 2 3 4", "top exclusive range of float";
107 is ~(1 ..^ 4.9), "1 2 3 4", "top exclusive range of float";
108
109 is ~(1.1 .. 4.1), "1.1 2.1 3.1 4.1", "range with float .min/.max";
110 is ~(1.9 .. 4.1), "1.9 2.9 3.9" , "range with float .min/.max";
111 is ~(1.1 .. 4.9), "1.1 2.1 3.1 4.1", "range with float .min/.max";
112 is ~(1.9 .. 4.9), "1.9 2.9 3.9 4.9", "range with float .min/.max";
113
114 is ~(1.1 ^..^ 4.1), "2.1 3.1" , "both exclusive float range";
115 is ~(1.9 ^..^ 4.1), "2.9 3.9" , "both exclusive float range";
116 is ~(1.1 ^..^ 4.9), "2.1 3.1 4.1", "both exclusive float range";
117 is ~(1.9 ^..^ 4.9), "2.9 3.9" , "both exclusive float range";
118 is [1.1 ^..^ 1.1], [], "double-exclusive range (x ^..^ x) where x is a float";
119 }
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
120
121 # 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
122 ## From pmichaud 2006-06-30: These tests may be incorrect.
123 ## C<@one> in ## item context returns an Array, not a number
124 ## -- use C< +@one > to get the number of elements. So, we
125 ## need to either declare that there's a version of infix:<..>
126 ## that coerces its arguments to numeric context, or we can
127 ## remove these tests from the suite.
ffc88f9 [t/spec] add RT #58018 marker to tests in range.t
moritz authored
128 # RT #58018
d37e5d1 [range.t] Marked tests for RT #76950.
Kodi Arfer authored
129 # RT #76950
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
130 {
131 my @three = (1, 1, 1);
f07dd23 [t/spec] a test for Range.map
moritz authored
132 my @one = 1;
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
133
134 is ~(@one .. 3) , "1 2 3", "lower inclusive limit is in scalar context";
135 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
136 is ~(3 ^.. @one) , "" , "lower exclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
137 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
138 is ~(4 .. @three) , "" , "upper inclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
139 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
140 is ~(4 ..^ @three) , "" , "upper exclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
141 }
142
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
143 # test that .map and .grep work on ranges
f07dd23 [t/spec] a test for Range.map
moritz authored
144 {
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
145 is (0..3).map({$_ * 2}).join('|'), '0|2|4|6', '.map works on ranges';
146 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
147 is (1..3).first({ $_ % 2 == 0}), 2, '.first works on ranges';
148 is (1..3).reduce({ $^a + $^b}), 6, '.reduce works on ranges';
f07dd23 [t/spec] a test for Range.map
moritz authored
149 }
150
d4459dc Add another range test case around the match operator, and an equival…
colomon authored
151 # test that range operands are handled in string context if strings
152 {
153 my $range;
154 my $start = "100.B";
155 my $end = "102.B";
156 lives_ok { $range = $start..$end },
157 'can make range from numeric string vars';
0a84065 [t/spec] Fudge for ng.
colomon authored
158 is $range.min, $start, 'range starts at start';
159 is $range.min.WHAT, "Str()", 'range start is a string';
160 is $range.max, $end, 'range ends at end';
161 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
162 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
163 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
164 }
0a84065 [t/spec] Fudge for ng.
colomon authored
165
b390af6 Tag test with RT number.
colomon authored
166 # RT #67882
82915ee [t/spec] Test bug from colomon++
kyle authored
167 {
168 my $range;
169 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = $0..$1 },
170 'can make range from match vars';
0a84065 [t/spec] Fudge for ng.
colomon authored
171 is $range.min, 1, 'range starts at one';
172 is $range.max, 3, 'range ends at three';
cd24cb2 @pmichaud Adjust range.t to avoid tests that require non-existent .succ capabil…
pmichaud authored
173 #?rakudo 2 skip 'range stringification'
82915ee [t/spec] Test bug from colomon++
kyle authored
174 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
175 is ~$range, "1 2 3", 'range is correct';
82915ee [t/spec] Test bug from colomon++
kyle authored
176 }
0877354 [t/spec] unfudge tests for RT #67882, and add a few more (because I d…
moritz authored
177 # and another set, just for the lulz
178 # RT #67882
179 {
180 ok '1 3' ~~ /(\d) . (\d)/, 'regex sanity';
181 isa_ok $0..$1, Range, '$0..$1 constructs a Range';
cd24cb2 @pmichaud Adjust range.t to avoid tests that require non-existent .succ capabil…
pmichaud authored
182 #?rakudo skip 'range with match object endpoints'
0877354 [t/spec] unfudge tests for RT #67882, and add a few more (because I d…
moritz authored
183 is ($0..$1).join('|'), '1|2|3', 'range from $0..$1';
184 }
82915ee [t/spec] Test bug from colomon++
kyle authored
185 {
186 my $range;
187 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = +$0..+$1 },
188 'can make range from match vars with numeric context forced';
0a84065 [t/spec] Fudge for ng.
colomon authored
189 is $range.min, 1, 'range starts at one';
190 is $range.max, 3, 'range ends at three';
82915ee [t/spec] Test bug from colomon++
kyle authored
191 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
192 is ~$range, "1 2 3", 'range is correct';
d4459dc Add another range test case around the match operator, and an equival…
colomon authored
193 }
194 {
195 my $range;
196 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = ~$0..~$1 },
197 'can make range from match vars with string context forced';
0a84065 [t/spec] Fudge for ng.
colomon authored
198 is $range.min, 1, 'range starts at one';
199 is $range.min.WHAT, "Str()", 'range start is a string';
200 is $range.max, 3, 'range ends at three';
201 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
202 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
203 is ~$range, "1 2 3", 'range is correct';
82915ee [t/spec] Test bug from colomon++
kyle authored
204 }
205
7f76022 [t/spec] forbid lists and ranges as Range end points (as per r28171)
moritz authored
206 # L<S03/Nonchaining binary precedence/it is illegal to use a Range or a
207 # List as implicitly numeric:>
208
209 #?rakudo todo 'forbid Ranges and Lists as Range endpoints'
210 {
211 ok !defined(try { 0 .. ^10 }), '0 .. ^10 is illegal';
212 ok !defined(try { 0 .. (0, 1, 2) }), '0 .. List is illegal';
213 }
214
7509d77 [t/spec] tests for RT #68788 segmentation fault on the "say 1..{$_}"
bbkr authored
215 # RT #68788
216 {
217 $_ = Any; # unsetting $_ to reproduce bug literally
48f7ecf @moritz [range.t] fudge a test that my next rakudo commit will break
moritz authored
218 #?rakudo todo 'lives_ok and warnings'
7509d77 [t/spec] tests for RT #68788 segmentation fault on the "say 1..{$_}"
bbkr authored
219 lives_ok {(1..$_)}, '(1..$_) lives';
220 isa_ok (1..$_), Range, '(..) works on Int .. Any';
221 }
0877354 [t/spec] unfudge tests for RT #67882, and add a few more (because I d…
moritz authored
222
b2c7760 @felliott [range.t] add test for RT #82620 (range exposing Parrot types)
felliott authored
223 # RT #82620
3f869dd [range.t] Fixed fudge syntax.
Kodi Arfer authored
224 #?rakudo skip 'range leaking Parrot types'
b2c7760 @felliott [range.t] add test for RT #82620 (range exposing Parrot types)
felliott authored
225 {
226 lives_ok {("a".."b").map({.trans(""=>"")}).perl},
227 "range doesn't leak Parrot types";
228 }
229
0a84065 [t/spec] Fudge for ng.
colomon authored
230 # # vim: ft=perl6
Something went wrong with that request. Please try again.