Sha256: 5895fd2a1aeab26267429ac8209d9a5498ac9b82f295f4657e0bdd7f72681a1e

Contents?: true

Size: 1.42 KB

Versions: 348

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

require 'puppet_spec/compiler'
require 'matchers/resource'

describe 'the chop function' do
  include PuppetSpec::Compiler
  include Matchers::Resource

  it 'removes last character in a string' do
    expect(compile_to_catalog("notify { String('abc'.chop == 'ab'): }")).to have_resource('Notify[true]')
  end

  it 'returns empty string for an empty string' do
    expect(compile_to_catalog("notify { String(''.chop == ''): }")).to have_resource('Notify[true]')
  end

  it 'removes both CR LF if both are the last characters in a string' do
    expect(compile_to_catalog("notify { String(\"abc\r\n\".chop == 'abc'): }")).to have_resource('Notify[true]')
  end

  it 'returns the value if Numeric' do
    expect(compile_to_catalog("notify { String(42.chop == 42): }")).to have_resource('Notify[true]')
  end

  it 'returns chopped version of each entry in an array' do
    expect(compile_to_catalog("notify { String(['aa', 'ba', 'ca'].chop == ['a', 'b', 'c']): }")).to have_resource('Notify[true]')
  end

  it 'returns chopped version of each entry in an Iterator' do
    expect(compile_to_catalog("notify { String(['aa', 'bb', 'cc'].reverse_each.chop == ['c', 'b', 'a']): }")).to have_resource('Notify[true]')
  end

  it 'errors when given a a nested Array' do
    expect { compile_to_catalog("['a', 'b', ['c']].chop")}.to raise_error(/'chop' parameter 'arg' expects a value of type Numeric, String, or Iterable/)
  end

end

Version data entries

348 entries across 348 versions & 1 rubygems

Version Path
puppet-8.3.0 spec/unit/functions/chop_spec.rb
puppet-8.3.0-x86-mingw32 spec/unit/functions/chop_spec.rb
puppet-8.3.0-x64-mingw32 spec/unit/functions/chop_spec.rb
puppet-8.3.0-universal-darwin spec/unit/functions/chop_spec.rb
puppet-8.4.0 spec/unit/functions/chop_spec.rb
puppet-8.4.0-x86-mingw32 spec/unit/functions/chop_spec.rb
puppet-8.4.0-x64-mingw32 spec/unit/functions/chop_spec.rb
puppet-8.4.0-universal-darwin spec/unit/functions/chop_spec.rb
puppet-7.28.0 spec/unit/functions/chop_spec.rb
puppet-7.28.0-x86-mingw32 spec/unit/functions/chop_spec.rb
puppet-7.28.0-x64-mingw32 spec/unit/functions/chop_spec.rb
puppet-7.28.0-universal-darwin spec/unit/functions/chop_spec.rb
puppet-8.3.1 spec/unit/functions/chop_spec.rb
puppet-8.3.1-x86-mingw32 spec/unit/functions/chop_spec.rb
puppet-8.3.1-x64-mingw32 spec/unit/functions/chop_spec.rb
puppet-8.3.1-universal-darwin spec/unit/functions/chop_spec.rb
puppet-7.27.0 spec/unit/functions/chop_spec.rb
puppet-7.27.0-x86-mingw32 spec/unit/functions/chop_spec.rb
puppet-7.27.0-x64-mingw32 spec/unit/functions/chop_spec.rb
puppet-7.27.0-universal-darwin spec/unit/functions/chop_spec.rb