Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 101 lines (81 sloc) 4.663 kb
9a586172 » Auzon
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
1 use v6;
2
3 use Test;
4
5 plan 51;
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)";
11 is ~(3..2), "", "(..) works on numbers (3)";
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)";
18
ba2d31cf » moritz
2008-06-30 [spec] fudged and corrected range.t
19 is ~('Y'..'z'), 'Y Z', '(..) works on uppercase letter .. lowercase letter';
20 is ~('Y'..'_'), 'Y Z', '(..) works on letter .. non-letter';
9a586172 » Auzon
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
21
4c815b69 » pmichaud
2008-06-30 S03-operators/range.t: correct a syntax error, remove some #?rakudo s…
22 isnt ~(0..^10), ~(0.. ^10), '(0..^10) is not the same as (0.. ^10)';
9a586172 » Auzon
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
23
24 is ~(3..9-3), "3 4 5 6", "(..) has correct precedence (1)";
25 is ~(2+1..6), "3 4 5 6", "(..) has correct precedence (2)";
26
27 # Test the three exclusive range operators:
28 # L<S03/Range semantics/range operator has variants>
29 is [1^..9], [2..9], "bottom-exclusive range (^..) works";
30 is [1 ..^9], [1..8], "top-exclusive range (..^) works";
31 is [1^..^9], [2..8], "double-exclusive range (^..^) works";
32 is [1^..^2], [], "double-exclusive range (^..^) can produce null range";
33
34 # tests of (x ^..^ x) here and below ensure that our implementation
35 # of double-exclusive range does not blindly remove an element
36 # from the head and tail of a list
37 is [1^..^1], [], "double-exclusive range (x ^..^ x) where x is an int";
38
39 is ["a"^.."z"], ["b".."z"], "bottom-exclusive string range (^..) works";
40 is ["a"..^"z"], ["a".."y"], "top-exclusive string range (..^) works";
41 is ["a"^..^"z"], ["b".."y"], "double-exclusive string range (^..^) works";
42 is ['a'^..^'b'], [], "double-exclusive string range (^..^) can produce null range";
43 is ['a' ^..^ 'a'], [], "double-exclusive range (x ^..^ x) where x is a char";
44
45 is 1.5 ~~ 1^..^2, Bool::True, "lazy evaluation of the range operator", :todo<bug>;
46
47 # Test the unary ^ operator
48 is ~(^5), "0 1 2 3 4", "unary ^num produces the range 0..^num";
49 is [^1], [0], "unary ^ on the boundary ^1 works";
50 is [^0], [], "unary ^0 produces null range";
51
ba2d31cf » moritz
2008-06-30 [spec] fudged and corrected range.t
52 {
53 # Test with floats
54 # 2006-12-05:
55 # 16:16 <TimToady> ~(1.9 ^..^ 4.9) should produce 2.9, 3.9
56 # 16:17 <pmichaud> and ~(1.9 ^..^ 4.5) would produce the same?
57 # 16:17 <TimToady> yes
58 is ~(1.1 .. 4) , "1.1 2.1 3.1", "range with float .min";
59 is ~(1.9 .. 4) , "1.9 2.9 3.9", "range with float .min";
60 is ~(1.1 ^.. 4), "2.1 3.1" , "bottom exclusive range of float";
61 is ~(1.9 ^.. 4), "2.9 3.9" , "bottom exclusive range of float";
62
63 is ~(1 .. 4.1) , "1 2 3 4", "range with float .max";
64 is ~(1 .. 4.9) , "1 2 3 4", "range with float .max";
65 is ~(1 ..^ 4.1), "1 2 3 4", "top exclusive range of float";
66 is ~(1 ..^ 4.9), "1 2 3 4", "top exclusive range of float";
67
68 is ~(1.1 .. 4.1), "1.1 2.1 3.1 4.1", "range with float .min/.max";
69 is ~(1.9 .. 4.1), "1.9 2.9 3.9" , "range with float .min/.max";
70 is ~(1.1 .. 4.9), "1.1 2.1 3.1 4.1", "range with float .min/.max";
71 is ~(1.9 .. 4.9), "1.9 2.9 3.9 4.9", "range with float .min/.max";
72
73 is ~(1.1 ^..^ 4.1), "2.1 3.1" , "both exclusive float range";
74 is ~(1.9 ^..^ 4.1), "2.9 3.9" , "both exclusive float range";
75 is ~(1.1 ^..^ 4.9), "2.1 3.1 4.1", "both exclusive float range";
76 is ~(1.9 ^..^ 4.9), "2.9 3.9" , "both exclusive float range";
77 is [1.1 ^..^ 1.1], [], "double-exclusive range (x ^..^ x) where x is a float";
78 }
9a586172 » Auzon
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
79
80 # Test that the operands are forced to scalar context
748e055f » pmichaud
2008-06-30 S03-operators/range.t: Add note about use of @array as arguments to i…
81 ## From pmichaud 2006-06-30: These tests may be incorrect.
82 ## C<@one> in ## item context returns an Array, not a number
83 ## -- use C< +@one > to get the number of elements. So, we
84 ## need to either declare that there's a version of infix:<..>
85 ## that coerces its arguments to numeric context, or we can
86 ## remove these tests from the suite.
ba2d31cf » moritz
2008-06-30 [spec] fudged and corrected range.t
87 #?rakudo skip 'MMD function __cmp not found for types (101, 95)'
9a586172 » Auzon
2008-06-30 [gsoc_spectest] reorganization and a few more tests for ===, eqv, and…
88 {
89 my @one = (1,);
90 my @three = (1, 1, 1);
91
92 is ~(@one .. 3) , "1 2 3", "lower inclusive limit is in scalar context";
93 is ~(@one ^.. 3) , "2 3" , "lower exclusive limit is in scalar context";
94 is ~(1 .. @three) , "1 2 3", "upper inclusive limit is in scalar context";
95 is ~(1 ..^ @three) , "1 2" , "upper exclusive limit is in scalar context";
96 is ~(@one .. @three), "1 2 3", "both inclusive limits are in scalar context";
97 is ~(@one ^..^ @three), "2" , "both exclusive limits are in scalar context";
98 is ~(@three .. @one), "" , "null range produced with lists forced to scalar context";
99 }
100
101 # For tests involving :by, see t/operators/adverbial_modifiers.t
Something went wrong with that request. Please try again.