From eed56d9f98b05a23700c4e7cb39c734ab0f0b0b4 Mon Sep 17 00:00:00 2001 From: Ted Reed Date: Mon, 27 Jul 2009 14:27:39 -0700 Subject: [PATCH] Provide fixes for the recently added Array.uniq! test cases. --- src/classes/Array.pir | 14 ++++++++++++++ t/array/uniq.t | 8 ++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/classes/Array.pir b/src/classes/Array.pir index 24940a8..b31d82f 100644 --- a/src/classes/Array.pir +++ b/src/classes/Array.pir @@ -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 diff --git a/t/array/uniq.t b/t/array/uniq.t index 2335afc..2112fe1 100644 --- a/t/array/uniq.t +++ b/t/array/uniq.t @@ -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"