Sha256: 3647e00984599b41aaa979be929d6fa7d90f10f055d4dc4a28d3af374409a7fe
Contents?: true
Size: 699 Bytes
Versions: 22
Compression:
Stored size: 699 Bytes
Contents
# frozen_string_literal: true require_relative 'helper' class EnumeratorTest < MiniTest::Test def test_each_enumerator o = [1, 2, 3] e = o.each r = [] loop do r << e.next rescue StopIteration break end assert_equal o, r end def test_custom_io_enumerator i, o = IO.pipe spin do 10.times { o.puts 'foo' } o.close end e_fiber = nil e = Enumerator.new do |y| e_fiber ||= Fiber.current while (l = i.gets) y << l end end r = [] loop do r << e.next rescue StopIteration break end assert_equal ["foo\n"] * 10, r assert Fiber.current != e_fiber end end
Version data entries
22 entries across 22 versions & 1 rubygems