Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 142 lines (116 sloc) 6.98 kB
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
1 use v6;
2
3 use Test;
4
b0e0a3a [t/spec] test that .first and .reduce work on ranges
moritz authored
5 plan 80;
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
6
7 # 3..2 must *not* produce "3 2". Use reverse to get a reversed range. -lwall
8
9 is ~(3..6), "3 4 5 6", "(..) works on numbers (1)";
10 is ~(3..3), "3", "(..) works on numbers (2)";
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
11 is ~(3..2), "", "(..) works on auto-rev numbers (3)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
12 is ~(8..11), "8 9 10 11", "(..) works on carried numbers (3)";
13
14 is ~("a".."c"), "a b c", "(..) works on chars (1)";
15 is ~("a".."a"), "a", "(..) works on chars (2)";
16 is ~("b".."a"), "", "(..) works on chars (3)";
17 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-operat…
s1n authored
18 is ~("AB".."Y"), "", "(..) works on auto-rev carried chars (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
19
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
20 is ~('Y'..'z'), 'Y Z', '(..) works on uppercase letter .. lowercase letter (1)';
21 is ~('z'..'Y'), '', '(..) works on auto-rev uppercase letter .. lowercase letter (2)';
22 is ~('Y'..'_'), 'Y Z', '(..) works on letter .. non-letter (1)';
23 is ~('_'..'Y'), '', '(..) works on auto-rev letter .. non-letter (2)';
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
24
4c815b6 S03-operators/range.t: correct a syntax error, remove some #?rakudo …
pmichaud authored
25 isnt ~(0..^10), ~(0.. ^10), '(0..^10) is not the same as (0.. ^10)';
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
26
27 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
28 is ~(5..9-5), "", "(..) has correct precedence (2)";
29 is ~(2+1..6), "3 4 5 6", "(..) has correct precedence (3)";
30 is ~(2+5..6), "", "(..) has correct precedence (4)";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
31
32 # Test the three exclusive range operators:
33 # L<S03/Range semantics/range operator has variants>
a971e66 [pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…
s1n authored
34 is [1^..9], [2..9], "bottom-exclusive range (^..) works (1)";
35 is [2^..2], [], "bottom-exclusive range (^..) works (2)";
36 is [3^..2], [], "bottom-exclusive auto-rev range (^..) works (3)";
37 is [1 ..^9], [1..8], "top-exclusive range (..^) works (1)";
38 is [2 ..^2], [], "top-exclusive range (..^) works (2)";
39 is [3 ..^2], [], "top-exclusive auto-rev range (..^) works (3)";
40 is [1^..^9], [2..8], "double-exclusive range (^..^) works (1)";
41 is [9^..^1], [], "double-exclusive auto-rev range (^..^) works (2)";
42 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
43
44 # tests of (x ^..^ x) here and below ensure that our implementation
45 # of double-exclusive range does not blindly remove an element
46 # from the head and tail of a list
47 is [1^..^1], [], "double-exclusive range (x ^..^ x) where x is an int";
48
49 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
50 is ["z"^.."a"], [], "bottom-exclusive string auto-rev range (^..) works";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
51 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
52 is ["z"..^"a"], [], "top-exclusive string auto-rev range (..^) works";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
53 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
54 is ["z"^..^"a"], [], "double-exclusive string auto-rev range (^..^) works";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
55 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
56 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
57 is ['a' ^..^ 'a'], [], "double-exclusive range (x ^..^ x) where x is a char";
58
59 is 1.5 ~~ 1^..^2, Bool::True, "lazy evaluation of the range operator", :todo<bug>;
60
61 # Test the unary ^ operator
62 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
63 is [^1], [0], "unary ^ on the boundary ^1 works";
64 is [^0], [], "unary ^0 produces null range";
65 is [^-1], [], "unary ^-1 produces null range";
66 is [^0.1], [0], "unary ^0.1 produces the range 0..^x where 0 < x < 1";
67 is [^'a'], [], "unary ^'a' produces null range";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
68
e8dc6d6 [t/spec] regression tests for RT #60898 (ranges + infix:<Z>)
moritz authored
69 # test that the zip operator works with ranges
70
71 is (1..5 Z <a b c>).join('|'), '1|a|2|b|3|c', 'Ranges and infix:<Z>';
72 is (1..2 Z <a b c>).join('|'), '1|a|2|b', 'Ranges and infix:<Z>';
73 is (<c b a> Z 1..5).join('|'), 'c|1|b|2|a|3', 'Ranges and infix:<Z>';
74
75 # two ranges
49d046f .join now defaults to ''
lwall authored
76 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
77
78
ba2d31c [spec] fudged and corrected range.t
moritz authored
79 {
80 # Test with floats
81 # 2006-12-05:
82 # 16:16 <TimToady> ~(1.9 ^..^ 4.9) should produce 2.9, 3.9
83 # 16:17 <pmichaud> and ~(1.9 ^..^ 4.5) would produce the same?
84 # 16:17 <TimToady> yes
85 is ~(1.1 .. 4) , "1.1 2.1 3.1", "range with float .min";
86 is ~(1.9 .. 4) , "1.9 2.9 3.9", "range with float .min";
87 is ~(1.1 ^.. 4), "2.1 3.1" , "bottom exclusive range of float";
88 is ~(1.9 ^.. 4), "2.9 3.9" , "bottom exclusive range of float";
89
90 is ~(1 .. 4.1) , "1 2 3 4", "range with float .max";
91 is ~(1 .. 4.9) , "1 2 3 4", "range with float .max";
92 is ~(1 ..^ 4.1), "1 2 3 4", "top exclusive range of float";
93 is ~(1 ..^ 4.9), "1 2 3 4", "top exclusive range of float";
94
95 is ~(1.1 .. 4.1), "1.1 2.1 3.1 4.1", "range with float .min/.max";
96 is ~(1.9 .. 4.1), "1.9 2.9 3.9" , "range with float .min/.max";
97 is ~(1.1 .. 4.9), "1.1 2.1 3.1 4.1", "range with float .min/.max";
98 is ~(1.9 .. 4.9), "1.9 2.9 3.9 4.9", "range with float .min/.max";
99
100 is ~(1.1 ^..^ 4.1), "2.1 3.1" , "both exclusive float range";
101 is ~(1.9 ^..^ 4.1), "2.9 3.9" , "both exclusive float range";
102 is ~(1.1 ^..^ 4.9), "2.1 3.1 4.1", "both exclusive float range";
103 is ~(1.9 ^..^ 4.9), "2.9 3.9" , "both exclusive float range";
104 is [1.1 ^..^ 1.1], [], "double-exclusive range (x ^..^ x) where x is a float";
105 }
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
106
107 # 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
108 ## From pmichaud 2006-06-30: These tests may be incorrect.
109 ## C<@one> in ## item context returns an Array, not a number
110 ## -- use C< +@one > to get the number of elements. So, we
111 ## need to either declare that there's a version of infix:<..>
112 ## that coerces its arguments to numeric context, or we can
113 ## remove these tests from the suite.
ba2d31c [spec] fudged and corrected range.t
moritz authored
114 #?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
115 {
116 my @three = (1, 1, 1);
f07dd23 [t/spec] a test for Range.map
moritz authored
117 my @one = 1;
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
118
119 is ~(@one .. 3) , "1 2 3", "lower inclusive limit is in scalar context";
120 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
121 is ~(3 ^.. @one) , "" , "lower exclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
122 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
123 is ~(4 .. @three) , "" , "upper inclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
124 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
125 is ~(4 ..^ @three) , "" , "upper exclusive limit is in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
126 is ~(@one .. @three), "1 2 3", "both inclusive limits are in scalar context";
127 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
128 is ~(@one ^..^ @three), "2" , "both exclusive limits are in scalar context";
129 is ~(@three ^..^ @one), "" , "both exclusive limits are in scalar context";
9a58617 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
Auzon authored
130 }
131
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
132 # test that .map and .grep work on ranges
f07dd23 [t/spec] a test for Range.map
moritz authored
133 {
3f4b761 [t/spec] test for .grep on Range, and unfudge Range.map test
moritz authored
134 is (0..3).map({$_ * 2}).join('|'), '0|2|4|6', '.map works on ranges';
135 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
136 is (1..3).first({ $_ % 2 == 0}), 2, '.first works on ranges';
137 is (1..3).reduce({ $^a + $^b}), 6, '.reduce works on ranges';
f07dd23 [t/spec] a test for Range.map
moritz authored
138 }
139
3677c42 [t/spec/S03-operators] added range-by.t with tests for ranges modifie…
masak authored
140 # For tests involving :by, see t/spec/S03-operators/range-by.t
141 # and t/operators/adverbial_modifiers.t
Something went wrong with that request. Please try again.