[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.7-1-98-gf19c0e5
James Turnbull
james at lovedthanlost.net
Wed Apr 8 21:48:12 UTC 2009
The following commit has been merged in the master branch:
commit 1bc7404f5e3efa633bb0a5cf10828071cfc4d876
Author: James Turnbull <james at lovedthanlost.net>
Date: Sat Feb 14 02:11:21 2009 +1100
Fixed #1831 - Added sprintf function
diff --git a/CHANGELOG b/CHANGELOG
index cffb3ec..f84c69a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,6 @@
0.24.8
+ Fixed #1831 - Added sprintf function
+
Fixed #1830 - Added regsubst function
Updated up2date and service confines to add support for Oracle EL and VM
diff --git a/lib/puppet/parser/functions/sprintf.rb b/lib/puppet/parser/functions/sprintf.rb
new file mode 100644
index 0000000..7974410
--- /dev/null
+++ b/lib/puppet/parser/functions/sprintf.rb
@@ -0,0 +1,17 @@
+module Puppet::Parser::Functions
+ newfunction(:sprintf, :type => :rvalue,
+ :doc => "\
+ Perform printf-style formatting of text.
+
+ The first parameter is format string describing how the rest of the
+ parameters should be formatted. See the documentation for the
+ ``Kernel::sprintf()`` function in Ruby for all the details.
+ ") \
+ do |args|
+ if args.length < 1
+ raise Puppet::ParseError, 'sprintf() needs at least one argument'
+ end
+ fmt = args.shift()
+ return sprintf(fmt, *args)
+ end
+end
diff --git a/spec/unit/parser/functions/sprintf.rb b/spec/unit/parser/functions/sprintf.rb
new file mode 100644
index 0000000..8654b18
--- /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
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list