Sha256: a9ab7884d52d9e7679a5f523e72ed713040a4e9a31f2bd6e25f53039afbe237c

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

#! /usr/bin/env ruby

require File.dirname(__FILE__) + '/../../../spec_helper'

describe "the sprintf function" do

    before :each do
        @scope = Puppet::Parser::Scope.new()
    end

    it "should exist" do
        Puppet::Parser::Functions.function("sprintf").should == "function_sprintf"
    end

    it "should raise a ParseError if there is less than 1 argument" do
        lambda { @scope.function_sprintf([]) }.should(
            raise_error(Puppet::ParseError))
    end

    it "should format integers" do
        result = @scope.function_sprintf(["%+05d", "23"])
        result.should(eql("+0023"))
    end

    it "should format floats" do
        result = @scope.function_sprintf(["%+.2f", "2.7182818284590451"])
        result.should(eql("+2.72"))
    end

    it "should format large floats" do
        result = @scope.function_sprintf(["%+.2e", "27182818284590451"])
        result.should(eql("+2.72e+16"))
    end

    it "should perform more complex formatting" do
        result = @scope.function_sprintf(
            [ "<%.8s:%#5o %#8X (%-8s)>",
              "overlongstring", "23", "48879", "foo" ])
        result.should(eql("<overlong:  027   0XBEEF (foo     )>"))
    end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puppet-0.25.5 spec/unit/parser/functions/sprintf.rb
puppet-0.25.4 spec/unit/parser/functions/sprintf.rb
puppet-0.25.3 spec/unit/parser/functions/sprintf.rb
puppet-0.25.2 spec/unit/parser/functions/sprintf.rb
puppet-0.25.1 spec/unit/parser/functions/sprintf.rb
puppet-0.25.0 spec/unit/parser/functions/sprintf.rb