Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 202 lines (170 sloc) 9.064 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)";
20 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
21 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
22
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operators...
s1n authored
23 is ~('Y'..'z'), 'Y Z', '(..) works on uppercase letter .. lowercase letter (1)';
24 is ~('z'..'Y'), '', '(..) works on auto-rev uppercase letter .. lowercase letter (2)';
25 is ~('Y'..'_'), 'Y Z', '(..) works on letter .. non-letter (1)';
26 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
27
28 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
29 is ~(5..9-5), "", "(..) has correct precedence (2)";
30 is ~(2+1..6), "3 4 5 6", "(..) has correct precedence (3)";
31 is ~(2+5..6), "", "(..) has correct precedence (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
32
33 # Test the three exclusive range operators:
971ba26 fix some smartlinks
szabgab authored
34 # 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
35 is [1^..9], [2..9], "bottom-exclusive range (^..) works (1)";
36 is [2^..2], [], "bottom-exclusive range (^..) works (2)";
37 is [3^..2], [], "bottom-exclusive auto-rev range (^..) works (3)";
38 is [1 ..^9], [1..8], "top-exclusive range (..^) works (1)";
39 is [2 ..^2], [], "top-exclusive range (..^) works (2)";
40 is [3 ..^2], [], "top-exclusive auto-rev range (..^) works (3)";
41 is [1^..^9], [2..8], "double-exclusive range (^..^) works (1)";
42 is [9^..^1], [], "double-exclusive auto-rev range (^..^) works (2)";
43 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
44
45 # tests of (x ^..^ x) here and below ensure that our implementation
46 # of double-exclusive range does not blindly remove an element
47 # from the head and tail of a list
48 is [1^..^1], [], "double-exclusive range (x ^..^ x) where x is an int";
49
50 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
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 is ['a' ^..^ 'a'], [], "double-exclusive range (x ^..^ x) where x is a char";
59
ba8e84a [t/spec] Change more Pugs todo flags to fudge commands
kyle authored
60 #?pugs todo 'bug'
61 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
62
63 # Test the unary ^ operator
64 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
65 is [^1], [0], "unary ^ on the boundary ^1 works";
66 is [^0], [], "unary ^0 produces null range";
67 is [^-1], [], "unary ^-1 produces null range";
68 is [^0.1], [0], "unary ^0.1 produces the range 0..^x where 0 < x < 1";
69 is [^'a'], [], "unary ^'a' produces null range";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
70
e8dc6d6 [t/spec] regression tests for RT #60898 (ranges + infix:<Z>)
moritz authored
71 # test that the zip operator works with ranges
72
73 is (1..5 Z <a b c>).join('|'), '1|a|2|b|3|c', 'Ranges and infix:<Z>';
74 is (1..2 Z <a b c>).join('|'), '1|a|2|b', 'Ranges and infix:<Z>';
75 is (<c b a> Z 1..5).join('|'), 'c|1|b|2|a|3', 'Ranges and infix:<Z>';
76
77 # two ranges
49d046f .join now defaults to ''
lwall authored
78 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
79
80
ba2d31c [spec] fudged and corrected range.t
moritz authored
81 {
82 # Test with floats
83 # 2006-12-05:
84 # 16:16 <TimToady> ~(1.9 ^..^ 4.9) should produce 2.9, 3.9
85 # 16:17 <pmichaud> and ~(1.9 ^..^ 4.5) would produce the same?
86 # 16:17 <TimToady> yes
87 is ~(1.1 .. 4) , "1.1 2.1 3.1", "range with float .min";
88 is ~(1.9 .. 4) , "1.9 2.9 3.9", "range with float .min";
89 is ~(1.1 ^.. 4), "2.1 3.1" , "bottom exclusive range of float";
90 is ~(1.9 ^.. 4), "2.9 3.9" , "bottom exclusive range of float";
91
92 is ~(1 .. 4.1) , "1 2 3 4", "range with float .max";
93 is ~(1 .. 4.9) , "1 2 3 4", "range with float .max";
94 is ~(1 ..^ 4.1), "1 2 3 4", "top exclusive range of float";
95 is ~(1 ..^ 4.9), "1 2 3 4", "top exclusive range of float";
96
97 is ~(1.1 .. 4.1), "1.1 2.1 3.1 4.1", "range with float .min/.max";
98 is ~(1.9 .. 4.1), "1.9 2.9 3.9" , "range with float .min/.max";
99 is ~(1.1 .. 4.9), "1.1 2.1 3.1 4.1", "range with float .min/.max";
100 is ~(1.9 .. 4.9), "1.9 2.9 3.9 4.9", "range with float .min/.max";
101
102 is ~(1.1 ^..^ 4.1), "2.1 3.1" , "both exclusive float range";
103 is ~(1.9 ^..^ 4.1), "2.9 3.9" , "both exclusive float range";
104 is ~(1.1 ^..^ 4.9), "2.1 3.1 4.1", "both exclusive float range";
105 is ~(1.9 ^..^ 4.9), "2.9 3.9" , "both exclusive float range";
106 is [1.1 ^..^ 1.1], [], "double-exclusive range (x ^..^ x) where x is a float";
107 }
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
108
109 # 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
110 ## From pmichaud 2006-06-30: These tests may be incorrect.
111 ## C<@one> in ## item context returns an Array, not a number
112 ## -- use C< +@one > to get the number of elements. So, we
113 ## need to either declare that there's a version of infix:<..>
114 ## that coerces its arguments to numeric context, or we can
115 ## remove these tests from the suite.
ba2d31c [spec] fudged and corrected range.t
moritz authored
116 #?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
117 {
118 my @three = (1, 1, 1);
f07dd23 [t/spec] a test for Range.map
moritz authored
119 my @one = 1;
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and ra...
Auzon authored
120
121 is ~(@one .. 3) , "1 2 3", "lower inclusive limit is in scalar context";
122 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
123 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
124 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
125 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
126 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
127 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
128 is ~(@one .. @three), "1 2 3", "both inclusive limits are in scalar context";
129 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
130 is ~(@one ^..^ @three), "2" , "both exclusive limits are in scalar context";
131 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
132 }
133
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
134 # test that .map and .grep work on ranges
f07dd23 [t/spec] a test for Range.map
moritz authored
135 {
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
136 is (0..3).map({$_ * 2}).join('|'), '0|2|4|6', '.map works on ranges';
137 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
138 is (1..3).first({ $_ % 2 == 0}), 2, '.first works on ranges';
139 is (1..3).reduce({ $^a + $^b}), 6, '.reduce works on ranges';
f07dd23 [t/spec] a test for Range.map
moritz authored
140 }
141
d4459dc Add another range test case around the match operator, and an equivalent...
colomon authored
142 # test that range operands are handled in string context if strings
143 {
144 my $range;
145 my $start = "100.B";
146 my $end = "102.B";
147 lives_ok { $range = $start..$end },
148 'can make range from numeric string vars';
149 is $range.from, $start, 'range starts at start';
150 is $range.from.WHAT, "Str()", 'range start is a string';
151 is $range.to, $end, 'range ends at end';
152 is $range.to.WHAT, "Str()", 'range end is a string';
153 lives_ok { "$range" }, 'can stringify range';
154 is $range.list, ("100.B","101.B","102.B"), 'range is correct';
155 }
156
b390af6 Tag test with RT number.
colomon authored
157 # RT #67882
82915ee [t/spec] Test bug from colomon++
kyle authored
158 {
159 my $range;
160 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = $0..$1 },
161 'can make range from match vars';
162 is $range.from, 1, 'range starts at one';
163 is $range.to, 3, 'range ends at three';
b58447e [t/spec] avoid segfault at test end by fudging a previously TODOed test ...
moritz authored
164 #?rakudo 2 skip 'range from match vars'
82915ee [t/spec] Test bug from colomon++
kyle authored
165 lives_ok { "$range" }, 'can stringify range';
d4459dc Add another range test case around the match operator, and an equivalent...
colomon authored
166 is $range.list, (1,2,3), 'range is correct';
82915ee [t/spec] Test bug from colomon++
kyle authored
167 }
168 {
169 my $range;
170 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = +$0..+$1 },
171 'can make range from match vars with numeric context forced';
172 is $range.from, 1, 'range starts at one';
173 is $range.to, 3, 'range ends at three';
174 lives_ok { "$range" }, 'can stringify range';
d4459dc Add another range test case around the match operator, and an equivalent...
colomon authored
175 is $range.list, (1,2,3), 'range is correct';
176 }
177 {
178 my $range;
179 lives_ok { '1 3' ~~ /(\d+) \s (\d+)/; $range = ~$0..~$1 },
180 'can make range from match vars with string context forced';
181 is $range.from, 1, 'range starts at one';
182 is $range.from.WHAT, "Str()", 'range start is a string';
183 is $range.to, 3, 'range ends at three';
184 is $range.to.WHAT, "Str()", 'range end is a string';
185 lives_ok { "$range" }, 'can stringify range';
186 is $range.list, <1 2 3>, 'range is correct';
82915ee [t/spec] Test bug from colomon++
kyle authored
187 }
188
7f76022 [t/spec] forbid lists and ranges as Range end points (as per r28171)
moritz authored
189 # L<S03/Nonchaining binary precedence/it is illegal to use a Range or a
190 # List as implicitly numeric:>
191
192 #?rakudo todo 'forbid Ranges and Lists as Range endpoints'
193 {
194 ok !defined(try { 0 .. ^10 }), '0 .. ^10 is illegal';
195 ok !defined(try { 0 .. (0, 1, 2) }), '0 .. List is illegal';
196 }
197
3677c42 [t/spec/S03-operators] added range-by.t with tests for ranges modified w...
masak authored
198 # For tests involving :by, see t/spec/S03-operators/range-by.t
199 # and t/operators/adverbial_modifiers.t
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
200
201 # vim: ft=perl6
Something went wrong with that request. Please try again.