Sha256: 769e65f9ba4cd843357547878a71b2f2f4e5c2a1f6f00df7678b365e86176468

Contents?: true

Size: 1.08 KB

Versions: 597

Compression:

Stored size: 1.08 KB

Contents

require 'spec_helper'

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

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

  it 'scans a value and returns an array' do
    expect(compile_to_catalog("$x = '42'.scanf('%i')[0] + 1; notify { \"test$x\": }")).to have_resource('Notify[test43]')
  end

  it 'scans a value and returns result of a code block' do
    expect(compile_to_catalog("$x = '42'.scanf('%i')|$x|{$x[0]} + 1; notify { \"test$x\": }")).to have_resource('Notify[test43]')
  end

  it 'returns empty array if nothing was scanned' do
    expect(compile_to_catalog("$x = 'no'.scanf('%i')[0]; notify { \"test${x}test\": }")).to have_resource('Notify[testtest]')
  end

  it 'produces result up to first unsuccessful scan' do
    expect(compile_to_catalog("$x = '42 no'.scanf('%i'); notify { \"test${x[0]}${x[1]}test\": }")).to have_resource('Notify[test42test]')
  end


  it 'errors when not given enough arguments' do
    expect do
      compile_to_catalog("'42'.scanf()")
    end.to raise_error(/'scanf' expects 2 arguments, got 1/)
  end
end

Version data entries

597 entries across 597 versions & 1 rubygems

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