Skip to content

Commit

Permalink
Provide fixes for the recently added Array.uniq! test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
treed committed Jul 27, 2009
1 parent 634d0ba commit eed56d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/classes/Array.pir
Expand Up @@ -270,9 +270,23 @@ Return a sorted copy of the list
.end

.sub 'uniq!' :method
.param pmc block :optional :named("!BLOCK")
.param int block_flag :opt_flag
if block_flag goto with_block
$P0 = self.'uniq'()
goto done
with_block:
$P0 = self.'uniq'(block :named("!BLOCK"))
done:
$I0 = elements $P0
$I1 = elements self
if $I0 == $I1 goto no_change
self = 0
self.'concat'($P0)
.return (self)
no_change:
$P0 = get_hll_global 'nil'
.return ($P0)
.end

.sub reject :method
Expand Down
8 changes: 2 additions & 6 deletions t/array/uniq.t
Expand Up @@ -22,15 +22,11 @@ c = [3,13,2,25,5,9]
c = c.uniq {|x| x % 10}
is c, [3,2,25,9], "uniq with block"

todo "Array#uniq! with block"
# The call to uniq! with a block fails.
# This is wrong because in Ruby every method will work when a block is passed, even when it is ignored.
d = [3,13,2,25,5,9]
#d = c.uniq! {|x| x % 10}
c = [3,13,2,25,5,9]
d = c.uniq! {|x| x % 10}
is d, [3,2,25,9], "uniq! with block"

# uniq! returns nil when nothing is changed
todo "Array#uniq! where nothing is changed should return nil"
e = [4, 5, 6]
e = e.uniq!
is e, nil, "uniq! removing nothing"

0 comments on commit eed56d9

Please sign in to comment.