summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-21 15:51:35 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-08-21 15:51:35 +0000
commit2f16501a1333936a71baf8709ed94dd437acd51a (patch)
tree6bf4c687fefbf5e371d535f8284adb1906153681 /test
parent640a02729597a4e0f668b644da69ffe764b80aab (diff)
downloadruby-2f16501a1333936a71baf8709ed94dd437acd51a.tar.gz
ruby-2f16501a1333936a71baf8709ed94dd437acd51a.tar.xz
ruby-2f16501a1333936a71baf8709ed94dd437acd51a.zip
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@24619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_enumerator.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index e70a783a0..fe8a573b2 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