diff options
author | James Turnbull <james@lovedthanlost.net> | 2009-02-14 02:11:21 +1100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-02-14 02:11:21 +1100 |
commit | 1bc7404f5e3efa633bb0a5cf10828071cfc4d876 (patch) | |
tree | 97a71a66d524a8d934552cd95ec4f229b6183e0d /spec/unit/parser/functions/sprintf.rb | |
parent | 336b6458a2264c550adf8e6799162380822e0d97 (diff) | |
download | puppet-1bc7404f5e3efa633bb0a5cf10828071cfc4d876.tar.gz puppet-1bc7404f5e3efa633bb0a5cf10828071cfc4d876.tar.xz puppet-1bc7404f5e3efa633bb0a5cf10828071cfc4d876.zip |
Fixed #1831 - Added sprintf function
Diffstat (limited to 'spec/unit/parser/functions/sprintf.rb')
-rw-r--r-- | spec/unit/parser/functions/sprintf.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/unit/parser/functions/sprintf.rb b/spec/unit/parser/functions/sprintf.rb new file mode 100644 index 000000000..8654b18fc --- /dev/null +++ b/spec/unit/parser/functions/sprintf.rb @@ -0,0 +1,42 @@ +#! /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 |