diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-26 10:26:45 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-26 10:26:45 +0000 |
| commit | 6415fdb24b91eb17c387f76c0079f7a81d7e387b (patch) | |
| tree | 8498e61729113bbfda98b4c8550fbfe96fd6aee2 /test/ruby | |
| parent | ce51ed90e9c5bd644d82d6e49aa39fbefc8f1ea5 (diff) | |
| download | ruby-6415fdb24b91eb17c387f76c0079f7a81d7e387b.tar.gz ruby-6415fdb24b91eb17c387f76c0079f7a81d7e387b.tar.xz ruby-6415fdb24b91eb17c387f76c0079f7a81d7e387b.zip | |
* test/ruby/test_enumerator.rb (TestEnumerator#test_with_object):
Add (back) the test for Enumerable#with_object.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_enumerator.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 135ed3824..53b70c33d 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 |
