Sha256: d844e56710b86611585c6684e00b21d79723d908372aa566484f1c2ac4125b5c

Contents?: true

Size: 829 Bytes

Versions: 14

Compression:

Stored size: 829 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 cool new syntax is sponsored by"
          yielder.yield yielder.class
        end
        assert enum.is_a?(Enumerator)
        2.times do
          assert_equal ["This cool new syntax is sponsored by", Enumerator::Yielder], enum.to_a
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
marcandre-backports-1.6.0 test/enumerator_test.rb
marcandre-backports-1.6.1 test/enumerator_test.rb
marcandre-backports-1.6.3 test/enumerator_test.rb
marcandre-backports-1.6.4 test/enumerator_test.rb
marcandre-backports-1.6.6 test/enumerator_test.rb
marcandre-backports-1.6.7 test/enumerator_test.rb
marcandre-backports-1.6.8 test/enumerator_test.rb
backports-1.6.7 test/enumerator_test.rb
backports-1.6.6 test/enumerator_test.rb
backports-1.6.0 test/enumerator_test.rb
backports-1.6.3 test/enumerator_test.rb
backports-1.6.4 test/enumerator_test.rb
backports-1.6.1 test/enumerator_test.rb
backports-1.6.8 test/enumerator_test.rb