Sha256: 8a02b5b8899caf5edae9b7cccb175eb791df7daea2b78ac596800a9a7b5736d9

Contents?: true

Size: 1.02 KB

Versions: 348

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'

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

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

  context 'for an integer' do
    [ 0, 1, -1].each do |x|
      it "called as round(#{x}) results in the same value" do
        expect(compile_to_catalog("notify { String( round(#{x}) == #{x}): }")).to have_resource("Notify[true]")
      end
    end
  end

  context 'for a float' do
    {
      0.0 => 0,
      1.1 => 1,
      -1.1 => -1,
      2.9 => 3,
      2.1 => 2,
      2.49 => 2,
      2.50 => 3,
      -2.9 => -3,
    }.each_pair do |x, expected|
      it "called as round(#{x}) results in #{expected}" do
        expect(compile_to_catalog("notify { String( round(#{x}) == #{expected}): }")).to have_resource("Notify[true]")
      end
    end
  end

  [[1,2,3], {'a' => 10}, '"42"'].each do |x|
    it "errors for a value of class #{x.class}" do
      expect{ compile_to_catalog("round(#{x})") }.to raise_error(/expects a Numeric value/)
    end
  end

end

Version data entries

348 entries across 348 versions & 1 rubygems

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