Sha256: 20a236e2f7539efbb99ea40fdb08e3060303181fed70a2fc00b7cfc51c6f1ef1

Contents?: true

Size: 998 Bytes

Versions: 39

Compression:

Stored size: 998 Bytes

Contents

require 'test_helper'


class EnumeratorTest < Test::Unit::TestCase
  context "Enumerator" do
    context "#with_object" do
      should "conform to doc" do
        animals = %w(cat dog wombat).to_enum 
        hash = animals.with_object({}).each do |item, memo| 
          memo[item] = item.upcase.reverse 
        end 
        assert_equal({"cat"=>"TAC", "dog"=>"GOD", "wombat"=>"TABMOW"}, hash)
      end
    end
    
    context "#new" do
      should "should accept block" do
        enum = Enumerator.new do |yielder|
          yielder.yield "This syntax is"
          yielder.yield "cool!"
        end
        assert enum.is_a?(Enumerator)
        2.times do
          assert_equal ["This syntax is", "cool!"], enum.to_a
        end
      end
    end
    
    context "#next" do
      should "conform to doc" do
        enum = [10, 20].to_enum 
        assert_equal 10, enum.next
        assert_equal 20, enum.next
        assert_raise(StopIteration){ enum.next} 
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 2 rubygems

Version Path
marcandre-backports-1.8.0 test/enumerator_test.rb
marcandre-backports-1.8.1 test/enumerator_test.rb
marcandre-backports-1.8.2 test/enumerator_test.rb
marcandre-backports-1.8.3 test/enumerator_test.rb
marcandre-backports-1.8.4 test/enumerator_test.rb
marcandre-backports-1.9.0 test/enumerator_test.rb
backports-1.17.1 test/enumerator_test.rb
backports-1.17.0 test/enumerator_test.rb
backports-1.16.7 test/enumerator_test.rb
backports-1.16.6 test/enumerator_test.rb
backports-1.16.5 test/enumerator_test.rb
backports-1.16.4 test/enumerator_test.rb
backports-1.16.3 test/enumerator_test.rb
backports-1.16.2 test/enumerator_test.rb
backports-1.16.1 test/enumerator_test.rb
backports-1.15.0 test/enumerator_test.rb
backports-1.14.1 test/enumerator_test.rb
backports-1.14.0 test/enumerator_test.rb
backports-1.13.3 test/enumerator_test.rb
backports-1.13.2 test/enumerator_test.rb