Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 207 lines (178 sloc) 9.447 kb
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
1 use v6;
2
3 use Test;
4
7f76022 [t/spec] forbid lists and ranges as Range end points (as per r28171)
moritz authored
5 plan 105;
6
7
8 # L<S03/Nonchaining binary precedence/Range object constructor>
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
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-operators...
s1n authored
14 is ~(3..2), "", "(..) works on auto-rev numbers (3)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
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)";
0a84065 [t/spec] Fudge for ng.
colomon authored
20 #?rakudo 2 todo "Alphabetic ranges misbehave in ng"
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
21 is ~("Y".."AB"), "Y Z AA AB", "(..) works on carried chars (3)";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operators...
s1n authored
22 is ~("AB".."Y"), "", "(..) works on auto-rev carried chars (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
23
0a84065 [t/spec] Fudge for ng.
colomon authored
24 #?rakudo skip "Bad things happen to this in ng"
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operators...
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)';
0a84065 [t/spec] Fudge for ng.
colomon authored
27 #?rakudo skip "Bad things happen to this in ng"
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operators...
s1n authored
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 ra...
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-operators...
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 ra...
Auzon authored
35
36 # Test the three exclusive range operators:
971ba26 fix some smartlinks
szabgab authored
37 # L<S03/Range and RangeIterator semantics/range operator has variants>
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operators...
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 ra...
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-operators...
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 ra...
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-operators...
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 ra...
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-operators...
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 ra...
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-operators...
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 ra...
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 ra...
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-operators...
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";
0a84065 [t/spec] Fudge for ng.
colomon authored
72 #?rakudo skip "Bad things happen to this in ng"
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operators...
s1n authored
73 is [^'a'], [], "unary ^'a' produces null range";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
74
e8dc6d6 [t/spec] regression tests for RT #60898 (ranges + infix:<Z>)
moritz authored
75 # test that the zip operator works with ranges
0a84065 [t/spec] Fudge for ng.
colomon authored
76 #?rakudo 4 skip "ng does not yet have zip operator"
e8dc6d6 [t/spec] regression tests for RT #60898 (ranges + infix:<Z>)
moritz authored
77 is (1..5 Z <a b c>).join('|'), '1|a|2|b|3|c', 'Ranges and infix:<Z>';
78 is (1..2 Z <a b c>).join('|'), '1|a|2|b', 'Ranges and infix:<Z>';
79 is (<c b a> Z 1..5).join('|'), 'c|1|b|2|a|3', 'Ranges and infix:<Z>';
80
81 # two ranges
49d046f .join now defaults to ''
lwall authored
82 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
83
ba2d31c [spec] fudged and corrected range.t
moritz authored
84 {
85 # Test with floats
86 # 2006-12-05:
87 # 16:16 <TimToady> ~(1.9 ^..^ 4.9) should produce 2.9, 3.9
88 # 16:17 <pmichaud> and ~(1.9 ^..^ 4.5) would produce the same?
89 # 16:17 <TimToady> yes
90 is ~(1.1 .. 4) , "1.1 2.1 3.1", "range with float .min";
91 is ~(1.9 .. 4) , "1.9 2.9 3.9", "range with float .min";
92 is ~(1.1 ^.. 4), "2.1 3.1" , "bottom exclusive range of float";
93 is ~(1.9 ^.. 4), "2.9 3.9" , "bottom exclusive range of float";
94
95 is ~(1 .. 4.1) , "1 2 3 4", "range with float .max";
96 is ~(1 .. 4.9) , "1 2 3 4", "range with float .max";
97 is ~(1 ..^ 4.1), "1 2 3 4", "top exclusive range of float";
98 is ~(1 ..^ 4.9), "1 2 3 4", "top exclusive range of float";
99
100 is ~(1.1 .. 4.1), "1.1 2.1 3.1 4.1", "range with float .min/.max";
101 is ~(1.9 .. 4.1), "1.9 2.9 3.9" , "range with float .min/.max";
102 is ~(1.1 .. 4.9), "1.1 2.1 3.1 4.1", "range with float .min/.max";
103 is ~(1.9 .. 4.9), "1.9 2.9 3.9 4.9", "range with float .min/.max";
104
105 is ~(1.1 ^..^ 4.1), "2.1 3.1" , "both exclusive float range";
106 is ~(1.9 ^..^ 4.1), "2.9 3.9" , "both exclusive float range";
107 is ~(1.1 ^..^ 4.9), "2.1 3.1 4.1", "both exclusive float range";
108 is ~(1.9 ^..^ 4.9), "2.9 3.9" , "both exclusive float range";
109 is [1.1 ^..^ 1.1], [], "double-exclusive range (x ^..^ x) where x is a float";
110 }
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
111
112 # Test that the operands are forced to scalar context
748e055 S03-operators/range.t: Add note about use of @array as arguments to inf...
pmichaud authored
113 ## From pmichaud 2006-06-30: These tests may be incorrect.
114 ## C<@one> in ## item context returns an Array, not a number
115 ## -- use C< +@one > to get the number of elements. So, we
116 ## need to either declare that there's a version of infix:<..>
117 ## that coerces its arguments to numeric context, or we can
118 ## remove these tests from the suite.
ba2d31c [spec] fudged and corrected range.t
moritz authored
119 #?rakudo skip 'MMD function __cmp not found for types (101, 95)'
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
120 {
121 my @three = (1, 1, 1);
f07dd23 [t/spec] a test for Range.map
moritz authored
122 my @one = 1;
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
123
124 is ~(@one .. 3) , "1 2 3", "lower inclusive limit is in scalar context";
125 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-operators...
s1n authored
126 is ~(3 ^.. @one) , "" , "lower exclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
127 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-operators...
s1n authored
128 is ~(4 .. @three) , "" , "upper inclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
129 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-operators...
s1n authored
130 is ~(4 ..^ @three) , "" , "upper exclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
131 is ~(@one .. @three), "1 2 3", "both inclusive limits are in scalar context";
132 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-operators...
s1n authored
133 is ~(@one ^..^ @three), "2" , "both exclusive limits are in scalar context";
134 is ~(@three ^..^ @one), "" , "both exclusive limits are in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
135 }
136
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
137 # test that .map and .grep work on ranges
f07dd23 [t/spec] a test for Range.map
moritz authored
138 {
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
139 is (0..3).map({$_ * 2}).join('|'), '0|2|4|6', '.map works on ranges';
0a84065 [t/spec] Fudge for ng.
colomon authored
140 #?rakudo skip "Probles using grep with junctions"
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
141 is (0..3).grep({$_ == 1|3}).join('|'), '1|3', '.grep works on ranges';
0a84065 [t/spec] Fudge for ng.
colomon authored
142 #?rakudo todo '.first suffers from the bug where code blocks get the wrong $_'
b0e0a3a [t/spec] test that .first and .reduce work on ranges
moritz authored
143 is (1..3).first({ $_ % 2 == 0}), 2, '.first works on ranges';
0a84065 [t/spec] Fudge for ng.
colomon authored
144 #?rakudo skip ".reduce NYI"
b0e0a3a [t/spec] test that .first and .reduce work on ranges
moritz authored
145 is (1..3).reduce({ $^a + $^b}), 6, '.reduce works on ranges';
f07dd23 [t/spec] a test for Range.map
moritz authored
146 }
147
d4459dc Add another range test case around the match operator, and an equivalent...
colomon authored
148 # test that range operands are handled in string context if strings
149 {
150 my $range;
151 my $start = "100.B";
152 my $end = "102.B";
153 lives_ok { $range = $start..$end },
154 'can make range from numeric string vars';
0a84065 [t/spec] Fudge for ng.
colomon authored
155 is $range.min, $start, 'range starts at start';
156 is $range.min.WHAT, "Str()", 'range start is a string';
157 is $range.max, $end, 'range ends at end';
158 is $range.max.WHAT, "Str()", 'range end is a string';
d4459dc Add another range test case around the match operator, and an equivalent...
colomon authored
159 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
160 is ~$range, "100.B 101.B 102.B", 'range is correct';
d4459dc Add another range test case around the match operator, and an equivalent...
colomon authored
161 }
0a84065 [t/spec] Fudge for ng.
colomon authored
162
b390af6 Tag test with RT number.
colomon authored
163 # RT #67882
0a84065 [t/spec] Fudge for ng.
colomon authored
164 #?rakudo skip "Causes parsing failure in ng"
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 }
0a84065 [t/spec] Fudge for ng.
colomon authored
174 #?rakudo skip "Causes parsing failure in ng"
82915ee [t/spec] Test bug from colomon++
kyle authored
175 {
176 my $range;
177 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = +$0..+$1 },
178 'can make range from match vars with numeric context forced';
0a84065 [t/spec] Fudge for ng.
colomon authored
179 is $range.min, 1, 'range starts at one';
180 is $range.max, 3, 'range ends at three';
82915ee [t/spec] Test bug from colomon++
kyle authored
181 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
182 is ~$range, "1 2 3", 'range is correct';
d4459dc Add another range test case around the match operator, and an equivalent...
colomon authored
183 }
0a84065 [t/spec] Fudge for ng.
colomon authored
184 #?rakudo skip "Causes parsing failure in ng"
d4459dc Add another range test case around the match operator, and an equivalent...
colomon authored
185 {
186 my $range;
187 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = ~$0..~$1 },
188 'can make range from match vars with string context forced';
0a84065 [t/spec] Fudge for ng.
colomon authored
189 is $range.min, 1, 'range starts at one';
190 is $range.min.WHAT, "Str()", 'range start is a string';
191 is $range.max, 3, 'range ends at three';
192 is $range.max.WHAT, "Str()", 'range end is a string';
d4459dc Add another range test case around the match operator, and an equivalent...
colomon authored
193 lives_ok { "$range" }, 'can stringify range';
0a84065 [t/spec] Fudge for ng.
colomon authored
194 is ~$range, "1 2 3", 'range is correct';
82915ee [t/spec] Test bug from colomon++
kyle authored
195 }
196
7f76022 [t/spec] forbid lists and ranges as Range end points (as per r28171)
moritz authored
197 # L<S03/Nonchaining binary precedence/it is illegal to use a Range or a
198 # List as implicitly numeric:>
199
200 #?rakudo todo 'forbid Ranges and Lists as Range endpoints'
201 {
202 ok !defined(try { 0 .. ^10 }), '0 .. ^10 is illegal';
203 ok !defined(try { 0 .. (0, 1, 2) }), '0 .. List is illegal';
204 }
205
0a84065 [t/spec] Fudge for ng.
colomon authored
206 # # vim: ft=perl6
Something went wrong with that request. Please try again.