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

Version Path
polyphony-1.6 test/test_enumerator.rb
polyphony-1.5 test/test_enumerator.rb
polyphony-1.4 test/test_enumerator.rb
polyphony-1.3 test/test_enumerator.rb
polyphony-1.2.1 test/test_enumerator.rb
polyphony-1.2 test/test_enumerator.rb
polyphony-1.1.1 test/test_enumerator.rb
polyphony-1.1 test/test_enumerator.rb
polyphony-1.0.2 test/test_enumerator.rb
polyphony-1.0.1 test/test_enumerator.rb
polyphony-1.0 test/test_enumerator.rb
polyphony-0.99.6 test/test_enumerator.rb
polyphony-0.99.5 test/test_enumerator.rb
polyphony-0.99.4 test/test_enumerator.rb
polyphony-0.99.3 test/test_enumerator.rb
polyphony-0.99.2 test/test_enumerator.rb
polyphony-0.99.1 test/test_enumerator.rb
polyphony-0.99 test/test_enumerator.rb
polyphony-0.98 test/test_enumerator.rb
polyphony-0.97 test/test_enumerator.rb