mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
7609494ffd
commit
461bd62fec
3 changed files with 50 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue