diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | test/ruby/test_enumerator.rb | 19 |
2 files changed, 16 insertions, 8 deletions
@@ -1,3 +1,8 @@ +Tue Aug 26 19:25:44 2008 Akinori MUSHA <knu@iDaemons.org> + + * test/ruby/test_enumerator.rb (TestEnumerator#test_with_object): + Add (back) the test for Enumerable#with_object. + Tue Aug 26 16:16:43 2008 NARUSE, Yui <naruse@ruby-lang.org> * test/cgi/test_cgi_tag_helper.rb: add more tests for html3. diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 135ed38249..53b70c33da 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -96,16 +96,18 @@ class TestEnumerator < Test::Unit::TestCase assert_equal([[1,0],[2,1],[3,2]], @obj.to_enum(:foo, 1, 2, 3).with_index.to_a) end - def test_with_memo - r = 1..10 - return unless r.each.respond_to? :with_memo - assert_equal([55, 3628800], (1..10).each.with_memo([0,1]) {|i, memo| - memo[0] += i - memo[1] *= i - }) + def test_with_object + obj = [0, 1] + ret = (1..10).each.with_object(obj) {|i, memo| + memo[0] += i + memo[1] *= i + } + assert_same(obj, ret) + assert_equal([55, 3628800], ret) a = [2,5,2,1,5,3,4,2,1,0] - a.delete_if.with_memo({}) {|i, seen| + obj = {} + ret = a.delete_if.with_object(obj) {|i, seen| if seen.key?(i) true else @@ -113,6 +115,7 @@ class TestEnumerator < Test::Unit::TestCase false end } + assert_same(obj, ret) assert_equal([2, 5, 1, 3, 4, 0], a) end |