Permalink
Browse files

[pugs_s02,s03] moved the auto-reversing range tests to the S03-operat…

…ors section. cleaned up the

S02-builtin_data_types to mostly test the auto-reversing ranges can be created. filled in a few
single boundry tests that seemed missing.


git-svn-id: http://svn.pugscode.org/pugs@21525 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent 0946d16 commit a971e660119656e5578ca8ce92232b987cb96139 s1n committed Jul 25, 2008
Showing with 43 additions and 51 deletions.
  1. +10 −39 S02-builtin_data_types/range.t
  2. +33 −12 S03-operators/range.t
@@ -2,7 +2,7 @@ use v6;
use Test;
-plan 87;
+plan 79;
# basic Range
# L<S02/Immutable types/A pair of Ordered endpoints; gens immutables when iterated>
@@ -36,46 +36,17 @@ is (1..1), [1,], 'got the right array';
is ('a'..'a').perl, '"a".."a"', "stationary str .perl ..";
is ('a'..'a'), [< a >], 'got the right array';
-# Decreasing Ranges
-#?rakudo 16 skip 'decreasing ranges are unspecced'
+# Decreasing Ranges - see S03-operators/range for boundry tests
{
- my $r = 5..1;
- is $r.perl, '5..1', "decreasing num .perl ..";
- is @r, [5, 4, 3, 2, 1], 'got the right array';
- my $r = 5^..1;
# XXX unspecced: exact value of Range.perl
- is $r.perl, '5^..1', "decreasing num .perl ^..";
- my @r = $r;
- is @r, [4, 3, 2, 1], 'got the right array';
- my $r = 5..^1;
- # XXX unspecced: exact value of Range.perl
- is $r.perl, '5..^1', "decreasing num .perl ..^";
- my @r = $r;
- is @r, [5, 4, 3, 2], 'got the right array';
- my $r = 5^..^1;
- # XXX unspecced: exact value of Range.perl
- is $r.perl, '5^..^1', "decreasing num .perl ^..^";
- my @r = $r;
- is @r, [4, 3, 2], 'got the right array';
-
- my $r = 'd'..'a';
- is $r.perl, '"d".."a"', "decreasing str .perl ..";
- is @r, [< d c b a >], 'got the right array';
- my $r = 'd'^..'a';
- # XXX unspecced: exact value of Range.perl
- is $r.perl, '"d"^.."a"', "decreasing str .perl ^..";
- my @r = $r;
- is @r, [< d, c, b, a >], 'got the right array';
- my $r = 'd'..^'a';
- # XXX unspecced: exact value of Range.perl
- is $r.perl, '"d"..^"a"', "decreasing str .perl ..^";
- my @r = $r;
- is @r, [< d, c, b >], 'got the right array';
- my $r = 'd'^..^'a';
- # XXX unspecced: exact value of Range.perl
- is $r.perl, '"d"^..^"a"', "decreasing str .perl ^..^";
- my @r = $r;
- is @r, [< c b >], 'got the right array';
+ is (5..1).perl, '5..1', "decreasing num .perl ..";
+ is (5^..1).perl, '5^..1', "decreasing num .perl ^..";
+ is (5..^1).perl, '5..^1', "decreasing num .perl ..^";
+ is (5^..^1).perl, '5^..^1', "decreasing num .perl ^..^";
+ is ('d'..'a').perl, '"d".."a"', "decreasing str .perl ..";
+ is ('d'^..'a').perl, '"d"^.."a"', "decreasing str .perl ^..";
+ is ('d'..^'a').perl, '"d"..^"a"', "decreasing str .perl ..^";
+ is ('d'^..^'a').perl, '"d"^..^"a"', "decreasing str .perl ^..^";
}
# ACCEPTS and equals tests
View
@@ -2,52 +2,69 @@ use v6;
use Test;
-plan 51;
+plan 72;
# 3..2 must *not* produce "3 2". Use reverse to get a reversed range. -lwall
is ~(3..6), "3 4 5 6", "(..) works on numbers (1)";
is ~(3..3), "3", "(..) works on numbers (2)";
-is ~(3..2), "", "(..) works on numbers (3)";
+is ~(3..2), "", "(..) works on auto-rev numbers (3)";
is ~(8..11), "8 9 10 11", "(..) works on carried numbers (3)";
is ~("a".."c"), "a b c", "(..) works on chars (1)";
is ~("a".."a"), "a", "(..) works on chars (2)";
is ~("b".."a"), "", "(..) works on chars (3)";
is ~("Y".."AB"), "Y Z AA AB", "(..) works on carried chars (3)";
+is ~("AB".."Y"), "", "(..) works on auto-rev carried chars (4)";
-is ~('Y'..'z'), 'Y Z', '(..) works on uppercase letter .. lowercase letter';
-is ~('Y'..'_'), 'Y Z', '(..) works on letter .. non-letter';
+is ~('Y'..'z'), 'Y Z', '(..) works on uppercase letter .. lowercase letter (1)';
+is ~('z'..'Y'), '', '(..) works on auto-rev uppercase letter .. lowercase letter (2)';
+is ~('Y'..'_'), 'Y Z', '(..) works on letter .. non-letter (1)';
+is ~('_'..'Y'), '', '(..) works on auto-rev letter .. non-letter (2)';
isnt ~(0..^10), ~(0.. ^10), '(0..^10) is not the same as (0.. ^10)';
is ~(3..9-3), "3 4 5 6", "(..) has correct precedence (1)";
-is ~(2+1..6), "3 4 5 6", "(..) has correct precedence (2)";
+is ~(5..9-5), "", "(..) has correct precedence (2)";
+is ~(2+1..6), "3 4 5 6", "(..) has correct precedence (3)";
+is ~(2+5..6), "", "(..) has correct precedence (4)";
# Test the three exclusive range operators:
# L<S03/Range semantics/range operator has variants>
-is [1^..9], [2..9], "bottom-exclusive range (^..) works";
-is [1 ..^9], [1..8], "top-exclusive range (..^) works";
-is [1^..^9], [2..8], "double-exclusive range (^..^) works";
-is [1^..^2], [], "double-exclusive range (^..^) can produce null range";
+is [1^..9], [2..9], "bottom-exclusive range (^..) works (1)";
+is [2^..2], [], "bottom-exclusive range (^..) works (2)";
+is [3^..2], [], "bottom-exclusive auto-rev range (^..) works (3)";
+is [1 ..^9], [1..8], "top-exclusive range (..^) works (1)";
+is [2 ..^2], [], "top-exclusive range (..^) works (2)";
+is [3 ..^2], [], "top-exclusive auto-rev range (..^) works (3)";
+is [1^..^9], [2..8], "double-exclusive range (^..^) works (1)";
+is [9^..^1], [], "double-exclusive auto-rev range (^..^) works (2)";
+is [1^..^2], [], "double-exclusive range (^..^) can produce null range (1)";
# tests of (x ^..^ x) here and below ensure that our implementation
# of double-exclusive range does not blindly remove an element
# from the head and tail of a list
is [1^..^1], [], "double-exclusive range (x ^..^ x) where x is an int";
is ["a"^.."z"], ["b".."z"], "bottom-exclusive string range (^..) works";
+is ["z"^.."a"], [], "bottom-exclusive string auto-rev range (^..) works";
is ["a"..^"z"], ["a".."y"], "top-exclusive string range (..^) works";
+is ["z"..^"a"], [], "top-exclusive string auto-rev range (..^) works";
is ["a"^..^"z"], ["b".."y"], "double-exclusive string range (^..^) works";
+is ["z"^..^"a"], [], "double-exclusive string auto-rev range (^..^) works";
is ['a'^..^'b'], [], "double-exclusive string range (^..^) can produce null range";
+is ['b'^..^'a'], [], "double-exclusive string auto-rev range (^..^) can produce null range";
is ['a' ^..^ 'a'], [], "double-exclusive range (x ^..^ x) where x is a char";
is 1.5 ~~ 1^..^2, Bool::True, "lazy evaluation of the range operator", :todo<bug>;
# Test the unary ^ operator
is ~(^5), "0 1 2 3 4", "unary ^num produces the range 0..^num";
-is [^1], [0], "unary ^ on the boundary ^1 works";
-is [^0], [], "unary ^0 produces null range";
+is [^1], [0], "unary ^ on the boundary ^1 works";
+is [^0], [], "unary ^0 produces null range";
+is [^-1], [], "unary ^-1 produces null range";
+is [^0.1], [0], "unary ^0.1 produces the range 0..^x where 0 < x < 1";
+is [^'a'], [], "unary ^'a' produces null range";
{
# Test with floats
@@ -91,11 +108,15 @@ is [^0], [], "unary ^0 produces null range";
is ~(@one .. 3) , "1 2 3", "lower inclusive limit is in scalar context";
is ~(@one ^.. 3) , "2 3" , "lower exclusive limit is in scalar context";
+ is ~(3 ^.. @one) , "" , "lower exclusive limit is in scalar context";
is ~(1 .. @three) , "1 2 3", "upper inclusive limit is in scalar context";
+ is ~(4 .. @three) , "" , "upper inclusive limit is in scalar context";
is ~(1 ..^ @three) , "1 2" , "upper exclusive limit is in scalar context";
+ is ~(4 ..^ @three) , "" , "upper exclusive limit is in scalar context";
is ~(@one .. @three), "1 2 3", "both inclusive limits are in scalar context";
- is ~(@one ^..^ @three), "2" , "both exclusive limits are in scalar context";
is ~(@three .. @one), "" , "null range produced with lists forced to scalar context";
+ is ~(@one ^..^ @three), "2" , "both exclusive limits are in scalar context";
+ is ~(@three ^..^ @one), "" , "both exclusive limits are in scalar context";
}
# For tests involving :by, see t/operators/adverbial_modifiers.t

0 comments on commit a971e66

Please sign in to comment.