Permalink
Browse files

More fixes for Range class, now pass S03-operators/range-basic.t .

  • Loading branch information...
1 parent 96cb354 commit f7f0c005056813120a398a3f8df778c0a61214cb @pmichaud pmichaud committed Jul 6, 2011
Showing with 18 additions and 9 deletions.
  1. +15 −6 src/core/Range.pm
  2. +3 −3 t/spectest.data
View
21 src/core/Range.pm
@@ -13,12 +13,16 @@ class Range is Iterable does Positional {
my $new = self.CREATE;
$new.BUILD($min, $Inf, $excludes_min, $excludes_max)
}
+ multi method new(Whatever $min, $max, :$excludes_min, :$excludes_max) {
+ my $new = self.CREATE;
+ $new.BUILD(-$Inf, $max, $excludes_min, $excludes_max)
+ }
method BUILD($min, $max, $excludes_min, $excludes_max) {
$!min = $min;
$!max = $max;
- $!excludes_min = $excludes_min;
- $!excludes_max = $excludes_max;
+ $!excludes_min = $excludes_min.Bool;
+ $!excludes_max = $excludes_max.Bool;
self;
}
@@ -27,6 +31,11 @@ class Range is Iterable does Positional {
method iterator() { self }
method list() { self.flat }
+ method ACCEPTS(Range:D: Mu \$topic) {
+ ($topic cmp $!min) > -(!$!excludes_min)
+ and ($topic cmp $!max) < +(!$!excludes_max)
+ }
+
method reify($n = 10) {
my $count;
if nqp::istype($n, Whatever) {
@@ -108,14 +117,14 @@ sub infix:<..>($min, $max) {
Range.new($min, $max)
}
sub infix:<^..>($min, $max) {
- Range.new($min, $max, :excludes_min(1))
+ Range.new($min, $max, :excludes_min)
}
sub infix:<..^>($min, $max) {
- Range.new($min, $max, :excludes_max(1))
+ Range.new($min, $max, :excludes_max)
}
sub infix:<^..^>($min, $max) {
- Range.new($min, $max, :excludes_min(1), :excludes_max(1))
+ Range.new($min, $max, :excludes_min, :excludes_max)
}
sub prefix:<^>($max) {
- Range.new(0, $max, :excludes_max(1))
+ Range.new(0, $max, :excludes_max)
}
View
6 t/spectest.data
@@ -67,7 +67,7 @@ S02-literals/misc-interpolation.t
S02-literals/numeric.t
S02-literals/pair-boolean.t
# S02-literals/pairs.t
-# S02-literals/quoting.t
+# S02-literals/quoting.t # need rx {} quoting
# S02-literals/quoting-unicode.t # icu
# S02-literals/radix.t
# S02-literals/string-interpolation.t
@@ -118,7 +118,7 @@ S03-metaops/reverse.t
# S03-operators/also.t
S03-operators/arith.t
S03-operators/assign-is-not-binding.t
-# S03-operators/assign.t
+# S03-operators/assign.t # need my ($, $) = ...
# S03-operators/autoincrement-range.t # icu
S03-operators/autoincrement.t
# S03-operators/autovivification.t
@@ -153,7 +153,7 @@ S03-operators/equality.t
S03-operators/not.t
# S03-operators/numeric-context.t
# S03-operators/precedence.t
-# S03-operators/range-basic.t
+S03-operators/range-basic.t
# S03-operators/range-int.t # stress
# S03-operators/range.t
# S03-operators/reduce-le1arg.t

0 comments on commit f7f0c00

Please sign in to comment.