Sha256: d118f9ff922f18d0b6e21eff5b57071fd95589f0bfaf0281301be61db7fa212b

Contents?: true

Size: 1.67 KB

Versions: 99

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'
require 'puppet/pops'

describe 'The enumeration support' do
  it 'produces an enumerator for Array' do
  expect(Puppet::Pops::Types::Enumeration.enumerator([1,2,3]).respond_to?(:next)).to eql(true)
  end

  it 'produces an enumerator for Hash' do
    expect(Puppet::Pops::Types::Enumeration.enumerator({:a=>1}).respond_to?(:next)).to eql(true)
  end

  it 'produces a char enumerator for String' do
    enum = Puppet::Pops::Types::Enumeration.enumerator("abc")
    expect(enum.respond_to?(:next)).to eql(true)
    expect(enum.next).to eql('a')
  end

  it 'produces an enumerator for integer times' do
    enum = Puppet::Pops::Types::Enumeration.enumerator(2)
    expect(enum.next).to eql(0)
    expect(enum.next).to eql(1)
    expect{enum.next}.to raise_error(StopIteration)
  end

  it 'produces an enumerator for Integer range' do
    range = Puppet::Pops::Types::TypeFactory.range(1,2)
    enum = Puppet::Pops::Types::Enumeration.enumerator(range)
    expect(enum.next).to eql(1)
    expect(enum.next).to eql(2)
    expect{enum.next}.to raise_error(StopIteration)
  end

  it 'does not produce an enumerator for infinite Integer range' do
    range = Puppet::Pops::Types::TypeFactory.range(1,:default)
    enum = Puppet::Pops::Types::Enumeration.enumerator(range)
    expect(enum).to be_nil
    range = Puppet::Pops::Types::TypeFactory.range(:default,2)
    enum = Puppet::Pops::Types::Enumeration.enumerator(range)
    expect(enum).to be_nil
  end

  [3.14, /.*/, true, false, nil, :something].each do |x|
    it "does not produce an enumerator for object of type #{x.class}" do
      enum = Puppet::Pops::Types::Enumeration.enumerator(x)
      expect(enum).to be_nil
    end
  end

end

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
puppet-3.7.5 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.5-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.5-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-4.0.0.rc1 spec/unit/pops/types/enumeration_spec.rb
puppet-4.0.0.rc1-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-4.0.0.rc1-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.4 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.4-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.4-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.3 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.3-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.3-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.2 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.2-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.2-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.1 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.1-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.1-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.0 spec/unit/pops/types/enumeration_spec.rb
puppet-3.7.0-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb