Sha256: 1df0094f8342e93f5da0d2abc36de633c2e45655003b60c39b2acff358d616f9

Contents?: true

Size: 1.48 KB

Versions: 432

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'
require 'puppet/pops'

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

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

  it 'produces a char enumerator for String' do
    enum = 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 = 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 = TypeFactory.range(1,2)
    enum = 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 = TypeFactory.range(1,:default)
    enum = Enumeration.enumerator(range)
    expect(enum).to be_nil
    range = TypeFactory.range(:default,2)
    enum = 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 = Enumeration.enumerator(x)
      expect(enum).to be_nil
    end
  end
end
end

Version data entries

432 entries across 432 versions & 1 rubygems

Version Path
puppet-6.29.0 spec/unit/pops/types/enumeration_spec.rb
puppet-6.29.0-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.29.0-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.29.0-universal-darwin spec/unit/pops/types/enumeration_spec.rb
puppet-6.28.0 spec/unit/pops/types/enumeration_spec.rb
puppet-6.28.0-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.28.0-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.28.0-universal-darwin spec/unit/pops/types/enumeration_spec.rb
puppet-6.27.0 spec/unit/pops/types/enumeration_spec.rb
puppet-6.27.0-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.27.0-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.27.0-universal-darwin spec/unit/pops/types/enumeration_spec.rb
puppet-6.26.0 spec/unit/pops/types/enumeration_spec.rb
puppet-6.26.0-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.26.0-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.26.0-universal-darwin spec/unit/pops/types/enumeration_spec.rb
puppet-6.25.1 spec/unit/pops/types/enumeration_spec.rb
puppet-6.25.1-x86-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.25.1-x64-mingw32 spec/unit/pops/types/enumeration_spec.rb
puppet-6.25.1-universal-darwin spec/unit/pops/types/enumeration_spec.rb