summaryrefslogtreecommitdiff
path: root/test/ruby/test_enum.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-03 01:29:44 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-03 01:29:44 +0000
commit78a59da8bc242413c58723203aa007d0f3beecf0 (patch)
treeb25770d859fee7a5f3dcf2d53aa5c8c49de24f23 /test/ruby/test_enum.rb
parentb386fe21eca01e03a5ca447792354632e549c94e (diff)
* enumerator.c: move implementation of each_slice, each_cons,
each_with_object to enum.c. * enum.c (each_slice_i): convert multiple values from yield into an array. * enum.c (each_cons_i): ditto. * enum.c (each_with_object_i): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_enum.rb')
-rw-r--r--test/ruby/test_enum.rb19
1 files changed, 11 insertions, 8 deletions
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb
index 945661f4b9..7e490a1212 100644
--- a/test/ruby/test_enum.rb
+++ b/test/ruby/test_enum.rb
@@ -197,6 +197,14 @@ class TestEnumerable < Test::Unit::TestCase
assert(!([1,2,3].member?(4)))
end
+ class Foo
+ include Enumerable
+ def each
+ yield 1
+ yield 1,2
+ end
+ end
+
def test_each_with_index
a = []
@obj.each_with_index {|x, i| a << [x, i] }
@@ -207,6 +215,7 @@ class TestEnumerable < Test::Unit::TestCase
hash[item] = index
end
assert_equal({"cat"=>0, "wombat"=>2, "dog"=>1}, hash)
+ assert_equal([[1, 0], [[1, 2], 1]], Foo.new.each_with_index.to_a)
end
def test_each_with_object
@@ -217,17 +226,11 @@ class TestEnumerable < Test::Unit::TestCase
}
assert_same(obj, ret)
assert_equal([55, 3628800], ret)
- end
-
- class Foo
- include Enumerable
- def each
- yield 1
- yield 1,2
- end
+ assert_equal([[1, nil], [[1, 2], nil]], Foo.new.each_with_object(nil).to_a)
end
def test_each_entry
+ assert_equal([1, 2, 3], [1, 2, 3].each_entry.to_a)
assert_equal([1, [1, 2]], Foo.new.each_entry.to_a)
end