Skip to content
Browse files

t/range/to_s.t now passes.

Add another multi method for initialization of Range to handle three parameters,
fix a bug in Range#to_s, and since Symbols are not yet implemented, use key=value
pair instead of Symbol in t/range/to_s.t, so that t/range/to_s.t now passes.
  • Loading branch information...
1 parent df0b3aa commit 41b18e13cdb7ecf43d91d18a36972dde7d725e5e @qiuhw qiuhw committed
Showing with 19 additions and 5 deletions.
  1. +17 −4 src/classes/Range.pir
  2. +2 −1 t/range/to_s.t
View
21 src/classes/Range.pir
@@ -134,10 +134,8 @@ Gets the beginning or end of the range.
.end
.sub 'to_s' :method
- $P0 = getattribute self, '$!from_exclusive'
- $P1 = getattribute self, '$!to_exclusive'
- $P2 = $P0 && $P1
- if $P2 > 0 goto build_exclusive
+ $P0 = getattribute self, '$!to_exclusive'
+ if $P0 goto build_exclusive
$S0 = '..'
goto build_return
build_exclusive:
@@ -391,6 +389,21 @@ Return true if there are any more values to iterate over.
setattribute self, '$!to', to
.end
+.sub 'initialize' :method :multi(_,_,_,_)
+ .param pmc from
+ .param pmc to
+ .param pmc exclusive
+ if exclusive goto exclusive_true
+ $P0 = new 'FalseClass'
+ goto finish
+ exclusive_true:
+ $P0 = new 'TrueClass'
+ finish:
+ setattribute self, '$!from', from
+ setattribute self, '$!to', to
+ setattribute self, '$!to_exclusive', $P0
+.end
+
=item each(block)
Run C<block> once for each item in C<self>, with the item passed as an arg.
View
3 t/range/to_s.t
@@ -6,6 +6,7 @@ r = Range.new(1,10)
range_str = r.to_s
is range_str, '1..10', '.to_s on Range'
-r = Range.new(1, 10, :exclusive)
+#r = Range.new(1, 10, :exclusive)
+r = Range.new(1, 10, exclusive=true)
range_str = r.to_s
is range_str, '1...10', '.to_s on Range'

0 comments on commit 41b18e1

Please sign in to comment.
Something went wrong with that request. Please try again.