diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-21 15:51:35 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-21 15:51:35 +0000 |
commit | 461bd62fec54d1026ef2496fbc9b9fd676f4d9d9 (patch) | |
tree | 6bf4c687fefbf5e371d535f8284adb1906153681 /test | |
parent | 7609494ffdd74aad9fe9aa4ce6da55e8e50300fb (diff) |
* enumerator.c (ary2sv): add dup argument.
(enumerator_next): call ary2sv with dup=0.
(enumerator_peek): call ary2sv with dup=1 to return duplicated array.
(enumerator_peek_values_m): new function to return duplicated array.
(Init_Enumerator): use enumerator_peek_values_m as
Enumerator#peek_value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_enumerator.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index e70a783a00..fe8a573b2b 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -141,6 +141,28 @@ class TestEnumerator < Test::Unit::TestCase assert_raise(StopIteration) { e.peek } end + def test_peek_modify + o = Object.new + def o.each + yield 1,2 + end + e = o.to_enum + a = e.peek + a << 3 + assert_equal([1,2], e.peek) + end + + def test_peek_values_modify + o = Object.new + def o.each + yield 1,2 + end + e = o.to_enum + a = e.peek_values + a << 3 + assert_equal([1,2], e.peek) + end + def test_next_after_stopiteration a = [1] e = a.each |