summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/functions
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /spec/unit/parser/functions
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'spec/unit/parser/functions')
-rwxr-xr-xspec/unit/parser/functions/defined_spec.rb86
-rw-r--r--spec/unit/parser/functions/fqdn_rand_spec.rb110
-rwxr-xr-xspec/unit/parser/functions/generate_spec.rb68
-rwxr-xr-xspec/unit/parser/functions/inline_template_spec.rb74
-rwxr-xr-xspec/unit/parser/functions/realize_spec.rb60
-rwxr-xr-xspec/unit/parser/functions/regsubst_spec.rb260
-rwxr-xr-xspec/unit/parser/functions/require_spec.rb102
-rwxr-xr-xspec/unit/parser/functions/shellquote_spec.rb146
-rwxr-xr-xspec/unit/parser/functions/split_spec.rb82
-rwxr-xr-xspec/unit/parser/functions/sprintf_spec.rb66
-rwxr-xr-xspec/unit/parser/functions/tag_spec.rb26
-rwxr-xr-xspec/unit/parser/functions/template_spec.rb80
-rwxr-xr-xspec/unit/parser/functions/versioncmp_spec.rb32
13 files changed, 596 insertions, 596 deletions
diff --git a/spec/unit/parser/functions/defined_spec.rb b/spec/unit/parser/functions/defined_spec.rb
index 90f2f5239..cf3f66e17 100755
--- a/spec/unit/parser/functions/defined_spec.rb
+++ b/spec/unit/parser/functions/defined_spec.rb
@@ -4,47 +4,47 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the 'defined' function" do
- before :each do
- Puppet::Node::Environment.stubs(:current).returns(nil)
- @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
- @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
- end
-
- it "should exist" do
- Puppet::Parser::Functions.function("defined").should == "function_defined"
- end
-
- it "should be true when the name is defined as a class" do
- @scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "yayness")
- @scope.function_defined("yayness").should be_true
- end
-
- it "should be true when the name is defined as a definition" do
- @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness")
- @scope.function_defined("yayness").should be_true
- end
-
- it "should be true when the name is defined as a builtin type" do
- @scope.function_defined("file").should be_true
- end
-
-
- it "should be true when any of the provided names are defined" do
- @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness")
- @scope.function_defined(["meh", "yayness", "booness"]).should be_true
- end
-
- it "should be false when a single given name is not defined" do
- @scope.function_defined("meh").should be_false
- end
-
- it "should be false when none of the names are defined" do
- @scope.function_defined(["meh", "yayness", "booness"]).should be_false
- end
-
- it "should be true when a resource reference is provided and the resource is in the catalog" do
- resource = Puppet::Resource.new("file", "/my/file")
- @compiler.add_resource(@scope, resource)
- @scope.function_defined(resource).should be_true
- end
+ before :each do
+ Puppet::Node::Environment.stubs(:current).returns(nil)
+ @compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo"))
+ @scope = Puppet::Parser::Scope.new(:compiler => @compiler)
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("defined").should == "function_defined"
+ end
+
+ it "should be true when the name is defined as a class" do
+ @scope.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "yayness")
+ @scope.function_defined("yayness").should be_true
+ end
+
+ it "should be true when the name is defined as a definition" do
+ @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness")
+ @scope.function_defined("yayness").should be_true
+ end
+
+ it "should be true when the name is defined as a builtin type" do
+ @scope.function_defined("file").should be_true
+ end
+
+
+ it "should be true when any of the provided names are defined" do
+ @scope.known_resource_types.add Puppet::Resource::Type.new(:definition, "yayness")
+ @scope.function_defined(["meh", "yayness", "booness"]).should be_true
+ end
+
+ it "should be false when a single given name is not defined" do
+ @scope.function_defined("meh").should be_false
+ end
+
+ it "should be false when none of the names are defined" do
+ @scope.function_defined(["meh", "yayness", "booness"]).should be_false
+ end
+
+ it "should be true when a resource reference is provided and the resource is in the catalog" do
+ resource = Puppet::Resource.new("file", "/my/file")
+ @compiler.add_resource(@scope, resource)
+ @scope.function_defined(resource).should be_true
+ end
end
diff --git a/spec/unit/parser/functions/fqdn_rand_spec.rb b/spec/unit/parser/functions/fqdn_rand_spec.rb
index 07390ed42..81c12c6a7 100644
--- a/spec/unit/parser/functions/fqdn_rand_spec.rb
+++ b/spec/unit/parser/functions/fqdn_rand_spec.rb
@@ -4,59 +4,59 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the fqdn_rand function" do
- before :each do
- @scope = Puppet::Parser::Scope.new
- end
-
- it "should exist" do
- Puppet::Parser::Functions.function("fqdn_rand").should == "function_fqdn_rand"
- end
-
- it "should handle 0 arguments" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
- lambda { @scope.function_fqdn_rand([]) }.should_not raise_error(Puppet::ParseError)
- end
-
- it "should handle 1 argument'}" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
- lambda { @scope.function_fqdn_rand([3]) }.should_not raise_error(Puppet::ParseError)
- end
-
-
- (1..10).each { |n|
- it "should handle #{n} additional arguments" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
- lambda { @scope.function_fqdn_rand([3,1,2,3,4,5,6,7,8,9,10][0..n]) }.should_not raise_error(Puppet::ParseError)
- end
- it "should handle #{n} additional string arguments" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
- lambda { @scope.function_fqdn_rand([3,%w{ 1 2 3 4 5 6 7 8 9 10}].flatten[0..n]) }.should_not raise_error(Puppet::ParseError)
- end
- }
-
- it "should return a value less than max" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
- @scope.function_fqdn_rand([3]).should satisfy {|n| n.to_i < 3 }
- end
-
- it "should return the same values on subsequent invocations for the same host" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1").twice
- @scope.function_fqdn_rand([3,4]).should eql(@scope.function_fqdn_rand([3, 4]))
- end
-
- it "should return different sequences of value for different hosts" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
- val1 = @scope.function_fqdn_rand([10000000,4])
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.2")
- val2 = @scope.function_fqdn_rand([10000000,4])
- val1.should_not eql(val2)
- end
-
- it "should return different values for the same hosts with different seeds" do
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
- val1 = @scope.function_fqdn_rand([10000000,4])
- @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
- val2 = @scope.function_fqdn_rand([10000000,42])
- val1.should_not eql(val2)
- end
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("fqdn_rand").should == "function_fqdn_rand"
+ end
+
+ it "should handle 0 arguments" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ lambda { @scope.function_fqdn_rand([]) }.should_not raise_error(Puppet::ParseError)
+ end
+
+ it "should handle 1 argument'}" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ lambda { @scope.function_fqdn_rand([3]) }.should_not raise_error(Puppet::ParseError)
+ end
+
+
+ (1..10).each { |n|
+ it "should handle #{n} additional arguments" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ lambda { @scope.function_fqdn_rand([3,1,2,3,4,5,6,7,8,9,10][0..n]) }.should_not raise_error(Puppet::ParseError)
+ end
+ it "should handle #{n} additional string arguments" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ lambda { @scope.function_fqdn_rand([3,%w{ 1 2 3 4 5 6 7 8 9 10}].flatten[0..n]) }.should_not raise_error(Puppet::ParseError)
+ end
+ }
+
+ it "should return a value less than max" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ @scope.function_fqdn_rand([3]).should satisfy {|n| n.to_i < 3 }
+ end
+
+ it "should return the same values on subsequent invocations for the same host" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1").twice
+ @scope.function_fqdn_rand([3,4]).should eql(@scope.function_fqdn_rand([3, 4]))
+ end
+
+ it "should return different sequences of value for different hosts" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ val1 = @scope.function_fqdn_rand([10000000,4])
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.2")
+ val2 = @scope.function_fqdn_rand([10000000,4])
+ val1.should_not eql(val2)
+ end
+
+ it "should return different values for the same hosts with different seeds" do
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ val1 = @scope.function_fqdn_rand([10000000,4])
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
+ val2 = @scope.function_fqdn_rand([10000000,42])
+ val1.should_not eql(val2)
+ end
end
diff --git a/spec/unit/parser/functions/generate_spec.rb b/spec/unit/parser/functions/generate_spec.rb
index 27a11aabf..27aabe261 100755
--- a/spec/unit/parser/functions/generate_spec.rb
+++ b/spec/unit/parser/functions/generate_spec.rb
@@ -4,38 +4,38 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the generate function" do
- before :each do
- @scope = Puppet::Parser::Scope.new
- end
-
- it "should exist" do
- Puppet::Parser::Functions.function("generate").should == "function_generate"
- end
-
- it "should accept a fully-qualified path as a command" do
- command = File::SEPARATOR + "command"
- Puppet::Util.expects(:execute).with([command]).returns("yay")
- lambda { @scope.function_generate([command]) }.should_not raise_error(Puppet::ParseError)
- end
-
- it "should not accept a relative path as a command" do
- command = "command"
- lambda { @scope.function_generate([command]) }.should raise_error(Puppet::ParseError)
- end
-
- # Really not sure how to implement this test, just sure it needs
- # to be implemented.
- it "should not accept a command containing illegal characters"
-
- it "should not accept a command containing '..'" do
- command = File::SEPARATOR + "command#{File::SEPARATOR}..#{File::SEPARATOR}"
- lambda { @scope.function_generate([command]) }.should raise_error(Puppet::ParseError)
- end
-
- it "should execute the generate script with the correct working directory" do
- command = File::SEPARATOR + "command"
- Dir.expects(:chdir).with(File.dirname(command)).yields
- Puppet::Util.expects(:execute).with([command]).returns("yay")
- lambda { @scope.function_generate([command]) }.should_not raise_error(Puppet::ParseError)
- end
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("generate").should == "function_generate"
+ end
+
+ it "should accept a fully-qualified path as a command" do
+ command = File::SEPARATOR + "command"
+ Puppet::Util.expects(:execute).with([command]).returns("yay")
+ lambda { @scope.function_generate([command]) }.should_not raise_error(Puppet::ParseError)
+ end
+
+ it "should not accept a relative path as a command" do
+ command = "command"
+ lambda { @scope.function_generate([command]) }.should raise_error(Puppet::ParseError)
+ end
+
+ # Really not sure how to implement this test, just sure it needs
+ # to be implemented.
+ it "should not accept a command containing illegal characters"
+
+ it "should not accept a command containing '..'" do
+ command = File::SEPARATOR + "command#{File::SEPARATOR}..#{File::SEPARATOR}"
+ lambda { @scope.function_generate([command]) }.should raise_error(Puppet::ParseError)
+ end
+
+ it "should execute the generate script with the correct working directory" do
+ command = File::SEPARATOR + "command"
+ Dir.expects(:chdir).with(File.dirname(command)).yields
+ Puppet::Util.expects(:execute).with([command]).returns("yay")
+ lambda { @scope.function_generate([command]) }.should_not raise_error(Puppet::ParseError)
+ end
end
diff --git a/spec/unit/parser/functions/inline_template_spec.rb b/spec/unit/parser/functions/inline_template_spec.rb
index 1da85513a..62f389e5d 100755
--- a/spec/unit/parser/functions/inline_template_spec.rb
+++ b/spec/unit/parser/functions/inline_template_spec.rb
@@ -4,56 +4,56 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the inline_template function" do
- before :each do
- @scope = Puppet::Parser::Scope.new
- end
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
- it "should exist" do
- Puppet::Parser::Functions.function("inline_template").should == "function_inline_template"
- end
+ it "should exist" do
+ Puppet::Parser::Functions.function("inline_template").should == "function_inline_template"
+ end
- it "should create a TemplateWrapper when called" do
- tw = stub_everything 'template_wrapper'
+ it "should create a TemplateWrapper when called" do
+ tw = stub_everything 'template_wrapper'
- Puppet::Parser::TemplateWrapper.expects(:new).returns(tw)
+ Puppet::Parser::TemplateWrapper.expects(:new).returns(tw)
- @scope.function_inline_template("test")
- end
+ @scope.function_inline_template("test")
+ end
- it "should pass the template string to TemplateWrapper.result" do
- tw = stub_everything 'template_wrapper'
- Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
+ it "should pass the template string to TemplateWrapper.result" do
+ tw = stub_everything 'template_wrapper'
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
- tw.expects(:result).with("test")
+ tw.expects(:result).with("test")
- @scope.function_inline_template("test")
- end
+ @scope.function_inline_template("test")
+ end
- it "should return what TemplateWrapper.result returns" do
- tw = stub_everything 'template_wrapper'
- Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
+ it "should return what TemplateWrapper.result returns" do
+ tw = stub_everything 'template_wrapper'
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
- tw.expects(:result).returns("template contents evaluated")
+ tw.expects(:result).returns("template contents evaluated")
- @scope.function_inline_template("test").should == "template contents evaluated"
- end
+ @scope.function_inline_template("test").should == "template contents evaluated"
+ end
- it "should concatenate template wrapper outputs for multiple templates" do
- tw1 = stub_everything "template_wrapper1"
- tw2 = stub_everything "template_wrapper2"
- Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw1,tw2)
- tw1.stubs(:result).returns("result1")
- tw2.stubs(:result).returns("result2")
+ it "should concatenate template wrapper outputs for multiple templates" do
+ tw1 = stub_everything "template_wrapper1"
+ tw2 = stub_everything "template_wrapper2"
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw1,tw2)
+ tw1.stubs(:result).returns("result1")
+ tw2.stubs(:result).returns("result2")
- @scope.function_inline_template(["1","2"]).should == "result1result2"
- end
+ @scope.function_inline_template(["1","2"]).should == "result1result2"
+ end
- it "should raise an error if the template raises an error" do
- tw = stub_everything 'template_wrapper'
- Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
- tw.stubs(:result).raises
+ it "should raise an error if the template raises an error" do
+ tw = stub_everything 'template_wrapper'
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
+ tw.stubs(:result).raises
- lambda { @scope.function_inline_template("1") }.should raise_error(Puppet::ParseError)
- end
+ lambda { @scope.function_inline_template("1") }.should raise_error(Puppet::ParseError)
+ end
end \ No newline at end of file
diff --git a/spec/unit/parser/functions/realize_spec.rb b/spec/unit/parser/functions/realize_spec.rb
index 4a55ad417..82f4fa251 100755
--- a/spec/unit/parser/functions/realize_spec.rb
+++ b/spec/unit/parser/functions/realize_spec.rb
@@ -4,48 +4,48 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the realize function" do
- before :each do
- @collector = stub_everything 'collector'
- @scope = Puppet::Parser::Scope.new
- @compiler = stub 'compiler'
- @compiler.stubs(:add_collection).with(@collector)
- @scope.stubs(:compiler).returns(@compiler)
- end
+ before :each do
+ @collector = stub_everything 'collector'
+ @scope = Puppet::Parser::Scope.new
+ @compiler = stub 'compiler'
+ @compiler.stubs(:add_collection).with(@collector)
+ @scope.stubs(:compiler).returns(@compiler)
+ end
- it "should exist" do
- Puppet::Parser::Functions.function("realize").should == "function_realize"
- end
+ it "should exist" do
+ Puppet::Parser::Functions.function("realize").should == "function_realize"
+ end
- it "should create a Collector when called" do
+ it "should create a Collector when called" do
- Puppet::Parser::Collector.expects(:new).returns(@collector)
+ Puppet::Parser::Collector.expects(:new).returns(@collector)
- @scope.function_realize("test")
- end
+ @scope.function_realize("test")
+ end
- it "should assign the passed-in resources to the collector" do
- Puppet::Parser::Collector.stubs(:new).returns(@collector)
+ it "should assign the passed-in resources to the collector" do
+ Puppet::Parser::Collector.stubs(:new).returns(@collector)
- @collector.expects(:resources=).with(["test"])
+ @collector.expects(:resources=).with(["test"])
- @scope.function_realize("test")
- end
+ @scope.function_realize("test")
+ end
- it "should flatten the resources assigned to the collector" do
- Puppet::Parser::Collector.stubs(:new).returns(@collector)
+ it "should flatten the resources assigned to the collector" do
+ Puppet::Parser::Collector.stubs(:new).returns(@collector)
- @collector.expects(:resources=).with(["test"])
+ @collector.expects(:resources=).with(["test"])
- @scope.function_realize([["test"]])
- end
+ @scope.function_realize([["test"]])
+ end
- it "should let the compiler know this collector" do
- Puppet::Parser::Collector.stubs(:new).returns(@collector)
- @collector.stubs(:resources=).with(["test"])
+ it "should let the compiler know this collector" do
+ Puppet::Parser::Collector.stubs(:new).returns(@collector)
+ @collector.stubs(:resources=).with(["test"])
- @compiler.expects(:add_collection).with(@collector)
+ @compiler.expects(:add_collection).with(@collector)
- @scope.function_realize("test")
- end
+ @scope.function_realize("test")
+ end
end
diff --git a/spec/unit/parser/functions/regsubst_spec.rb b/spec/unit/parser/functions/regsubst_spec.rb
index d87b4d9ab..47126dd7a 100755
--- a/spec/unit/parser/functions/regsubst_spec.rb
+++ b/spec/unit/parser/functions/regsubst_spec.rb
@@ -4,189 +4,189 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the regsubst function" do
- before :each do
- @scope = Puppet::Parser::Scope.new
- end
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
- it "should exist" do
- Puppet::Parser::Functions.function("regsubst").should == "function_regsubst"
- end
+ it "should exist" do
+ Puppet::Parser::Functions.function("regsubst").should == "function_regsubst"
+ end
- it "should raise a ParseError if there is less than 3 arguments" do
- lambda { @scope.function_regsubst(["foo", "bar"]) }.should( raise_error(Puppet::ParseError))
- end
+ it "should raise a ParseError if there is less than 3 arguments" do
+ lambda { @scope.function_regsubst(["foo", "bar"]) }.should( raise_error(Puppet::ParseError))
+ end
- it "should raise a ParseError if there is more than 5 arguments" do
- lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "del", "x", "y"]) }.should( raise_error(Puppet::ParseError))
- end
+ it "should raise a ParseError if there is more than 5 arguments" do
+ lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "del", "x", "y"]) }.should( raise_error(Puppet::ParseError))
+ end
- it "should raise a ParseError when given a bad flag" do
- lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "X"]) }.should( raise_error(Puppet::ParseError))
- end
+ it "should raise a ParseError when given a bad flag" do
+ lambda { @scope.function_regsubst(["foo", "bar", "gazonk", "X"]) }.should( raise_error(Puppet::ParseError))
+ end
- it "should raise a ParseError for non-string and non-array target" do
- lambda { @scope.function_regsubst([4711, "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError))
- end
+ it "should raise a ParseError for non-string and non-array target" do
+ lambda { @scope.function_regsubst([4711, "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError))
+ end
- it "should raise a ParseError for array target with non-string element" do
- lambda { @scope.function_regsubst([["x", ["y"], "z"], "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError))
- end
+ it "should raise a ParseError for array target with non-string element" do
+ lambda { @scope.function_regsubst([["x", ["y"], "z"], "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError))
+ end
- it "should raise a ParseError for a bad regular expression" do
- lambda { @scope.function_regsubst(["foo", "(bar", "gazonk"]) }.should(
- raise_error(Puppet::ParseError))
- end
+ it "should raise a ParseError for a bad regular expression" do
+ lambda { @scope.function_regsubst(["foo", "(bar", "gazonk"]) }.should(
+ raise_error(Puppet::ParseError))
+ end
- it "should raise a ParseError for a non-string regular expression" do
- lambda { @scope.function_regsubst(["foo", ["bar"], "gazonk"]) }.should( raise_error(Puppet::ParseError))
- end
+ it "should raise a ParseError for a non-string regular expression" do
+ lambda { @scope.function_regsubst(["foo", ["bar"], "gazonk"]) }.should( raise_error(Puppet::ParseError))
+ end
- it "should handle groups" do
+ it "should handle groups" do
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ '130.236.254.10',
+ [ '130.236.254.10',
- '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$',
- '\4-\3-\2-\1'
- ])
- result.should(eql("10-254-236-130"))
- end
+ '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$',
+ '\4-\3-\2-\1'
+ ])
+ result.should(eql("10-254-236-130"))
+ end
- it "should handle simple regexps" do
+ it "should handle simple regexps" do
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ "the monkey breaks banana trees",
- "b[an]*a",
+ [ "the monkey breaks banana trees",
+ "b[an]*a",
- "coconut"
- ])
- result.should(eql("the monkey breaks coconut trees"))
- end
+ "coconut"
+ ])
+ result.should(eql("the monkey breaks coconut trees"))
+ end
- it "should handle case-sensitive regexps" do
+ it "should handle case-sensitive regexps" do
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ "the monkey breaks baNAna trees",
- "b[an]+a",
+ [ "the monkey breaks baNAna trees",
+ "b[an]+a",
- "coconut"
- ])
- result.should(eql("the monkey breaks baNAna trees"))
- end
+ "coconut"
+ ])
+ result.should(eql("the monkey breaks baNAna trees"))
+ end
- it "should handle case-insensitive regexps" do
+ it "should handle case-insensitive regexps" do
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ "the monkey breaks baNAna trees",
- "b[an]+a",
- "coconut",
+ [ "the monkey breaks baNAna trees",
+ "b[an]+a",
+ "coconut",
- "I"
- ])
- result.should(eql("the monkey breaks coconut trees"))
- end
+ "I"
+ ])
+ result.should(eql("the monkey breaks coconut trees"))
+ end
- it "should handle global substitutions" do
+ it "should handle global substitutions" do
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ "the monkey breaks\tbanana trees",
- "[ \t]",
- "--",
+ [ "the monkey breaks\tbanana trees",
+ "[ \t]",
+ "--",
- "G"
- ])
- result.should(eql("the--monkey--breaks--banana--trees"))
- end
+ "G"
+ ])
+ result.should(eql("the--monkey--breaks--banana--trees"))
+ end
- it "should handle global substitutions with groups" do
+ it "should handle global substitutions with groups" do
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ '130.236.254.10',
+ [ '130.236.254.10',
- '([0-9]+)',
- '<\1>',
- 'G'
- ])
- result.should(eql('<130>.<236>.<254>.<10>'))
- end
+ '([0-9]+)',
+ '<\1>',
+ 'G'
+ ])
+ result.should(eql('<130>.<236>.<254>.<10>'))
+ end
- it "should apply on all elements of an array" do
- data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
- result = @scope.function_regsubst([ data, '[.]', '-'])
- result.should(eql( ['130-236.254.10', 'foo-example.com', 'coconut', '10-20.30.40']))
- end
+ it "should apply on all elements of an array" do
+ data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
+ result = @scope.function_regsubst([ data, '[.]', '-'])
+ result.should(eql( ['130-236.254.10', 'foo-example.com', 'coconut', '10-20.30.40']))
+ end
- it "should apply global substitutions on all elements of an array" do
- data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
- result = @scope.function_regsubst([ data, '[.]', '-', 'G'])
- result.should(eql( ['130-236-254-10', 'foo-example-com', 'coconut', '10-20-30-40']))
- end
+ it "should apply global substitutions on all elements of an array" do
+ data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
+ result = @scope.function_regsubst([ data, '[.]', '-', 'G'])
+ result.should(eql( ['130-236-254-10', 'foo-example-com', 'coconut', '10-20-30-40']))
+ end
- it "should handle groups on all elements of an array" do
- data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
+ it "should handle groups on all elements of an array" do
+ data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ data,
+ [ data,
- '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$',
- '\4-\3-\2-\1'
- ])
- result.should(eql( ['10-254-236-130', 'foo.example.com', 'coconut', '40-30-20-10']))
- end
+ '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$',
+ '\4-\3-\2-\1'
+ ])
+ result.should(eql( ['10-254-236-130', 'foo.example.com', 'coconut', '40-30-20-10']))
+ end
- it "should handle global substitutions with groups on all elements of an array" do
- data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
+ it "should handle global substitutions with groups on all elements of an array" do
+ data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ data,
+ [ data,
- '([^.]+)',
- '<\1>',
- 'G'
- ])
+ '([^.]+)',
+ '<\1>',
+ 'G'
+ ])
- result.should(eql(
+ result.should(eql(
- ['<130>.<236>.<254>.<10>', '<foo>.<example>.<com>',
+ ['<130>.<236>.<254>.<10>', '<foo>.<example>.<com>',
- '<coconut>', '<10>.<20>.<30>.<40>']))
- end
+ '<coconut>', '<10>.<20>.<30>.<40>']))
+ end
- it "should return an array (not a string) for a single element array parameter" do
- data = ['130.236.254.10']
+ it "should return an array (not a string) for a single element array parameter" do
+ data = ['130.236.254.10']
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ data,
+ [ data,
- '([^.]+)',
- '<\1>',
- 'G'
- ])
- result.should(eql(['<130>.<236>.<254>.<10>']))
- end
+ '([^.]+)',
+ '<\1>',
+ 'G'
+ ])
+ result.should(eql(['<130>.<236>.<254>.<10>']))
+ end
- it "should return a string (not a one element array) for a simple string parameter" do
- data = '130.236.254.10'
+ it "should return a string (not a one element array) for a simple string parameter" do
+ data = '130.236.254.10'
- result = @scope.function_regsubst(
+ result = @scope.function_regsubst(
- [ data,
+ [ data,
- '([^.]+)',
- '<\1>',
- 'G'
- ])
- result.should(eql('<130>.<236>.<254>.<10>'))
- end
+ '([^.]+)',
+ '<\1>',
+ 'G'
+ ])
+ result.should(eql('<130>.<236>.<254>.<10>'))
+ end
end
diff --git a/spec/unit/parser/functions/require_spec.rb b/spec/unit/parser/functions/require_spec.rb
index 48769d16c..bd42fa579 100755
--- a/spec/unit/parser/functions/require_spec.rb
+++ b/spec/unit/parser/functions/require_spec.rb
@@ -4,71 +4,71 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the require function" do
- before :each do
- @catalog = stub 'catalog'
- @compiler = stub 'compiler', :catalog => @catalog
+ before :each do
+ @catalog = stub 'catalog'
+ @compiler = stub 'compiler', :catalog => @catalog
- @scope = Puppet::Parser::Scope.new
- @scope.stubs(:findresource)
- @scope.stubs(:compiler).returns(@compiler)
- @klass = stub 'class', :name => "myclass"
- @scope.stubs(:find_hostclass).returns(@klass)
+ @scope = Puppet::Parser::Scope.new
+ @scope.stubs(:findresource)
+ @scope.stubs(:compiler).returns(@compiler)
+ @klass = stub 'class', :name => "myclass"
+ @scope.stubs(:find_hostclass).returns(@klass)
- @resource = Puppet::Parser::Resource.new(:file, "/my/file", :scope => @scope, :source => "source")
- @resource.stubs(:metaparam_compatibility_mode?).returns false
- @scope.stubs(:resource).returns @resource
- end
+ @resource = Puppet::Parser::Resource.new(:file, "/my/file", :scope => @scope, :source => "source")
+ @resource.stubs(:metaparam_compatibility_mode?).returns false
+ @scope.stubs(:resource).returns @resource
+ end
- it "should exist" do
- Puppet::Parser::Functions.function("require").should == "function_require"
- end
+ it "should exist" do
+ Puppet::Parser::Functions.function("require").should == "function_require"
+ end
- it "should delegate to the 'include' puppet function" do
- @scope.expects(:function_include).with("myclass")
+ it "should delegate to the 'include' puppet function" do
+ @scope.expects(:function_include).with("myclass")
- @scope.function_require("myclass")
- end
+ @scope.function_require("myclass")
+ end
- it "should set the 'require' prarameter on the resource to a resource reference" do
- @scope.stubs(:function_include)
- @scope.function_require("myclass")
+ it "should set the 'require' prarameter on the resource to a resource reference" do
+ @scope.stubs(:function_include)
+ @scope.function_require("myclass")
- @resource["require"].should be_instance_of(Array)
- @resource["require"][0].should be_instance_of(Puppet::Resource)
- end
+ @resource["require"].should be_instance_of(Array)
+ @resource["require"][0].should be_instance_of(Puppet::Resource)
+ end
- it "should verify the 'include' function is loaded" do
- Puppet::Parser::Functions.expects(:function).with(:include).returns(:function_include)
- @scope.stubs(:function_include)
- @scope.function_require("myclass")
- end
+ it "should verify the 'include' function is loaded" do
+ Puppet::Parser::Functions.expects(:function).with(:include).returns(:function_include)
+ @scope.stubs(:function_include)
+ @scope.function_require("myclass")
+ end
- it "should include the class but not add a dependency if used on a client not at least version 0.25" do
- @resource.expects(:metaparam_compatibility_mode?).returns true
- @scope.expects(:warning)
- @resource.expects(:set_parameter).never
- @scope.expects(:function_include)
+ it "should include the class but not add a dependency if used on a client not at least version 0.25" do
+ @resource.expects(:metaparam_compatibility_mode?).returns true
+ @scope.expects(:warning)
+ @resource.expects(:set_parameter).never
+ @scope.expects(:function_include)
- @scope.function_require("myclass")
- end
+ @scope.function_require("myclass")
+ end
- it "should lookup the absolute class path" do
- @scope.stubs(:function_include)
+ it "should lookup the absolute class path" do
+ @scope.stubs(:function_include)
- @scope.expects(:find_hostclass).with("myclass").returns(@klass)
- @klass.expects(:name).returns("myclass")
+ @scope.expects(:find_hostclass).with("myclass").returns(@klass)
+ @klass.expects(:name).returns("myclass")
- @scope.function_require("myclass")
- end
+ @scope.function_require("myclass")
+ end
- it "should append the required class to the require parameter" do
- @scope.stubs(:function_include)
+ it "should append the required class to the require parameter" do
+ @scope.stubs(:function_include)
- one = Puppet::Resource.new(:file, "/one")
- @resource[:require] = one
- @scope.function_require("myclass")
+ one = Puppet::Resource.new(:file, "/one")
+ @resource[:require] = one
+ @scope.function_require("myclass")
- @resource[:require].should be_include(one)
- @resource[:require].detect { |r| r.to_s == "Class[Myclass]" }.should be_instance_of(Puppet::Resource)
- end
+ @resource[:require].should be_include(one)
+ @resource[:require].detect { |r| r.to_s == "Class[Myclass]" }.should be_instance_of(Puppet::Resource)
+ end
end
diff --git a/spec/unit/parser/functions/shellquote_spec.rb b/spec/unit/parser/functions/shellquote_spec.rb
index e4eeaeba8..46b9f8d10 100755
--- a/spec/unit/parser/functions/shellquote_spec.rb
+++ b/spec/unit/parser/functions/shellquote_spec.rb
@@ -4,78 +4,78 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the shellquote function" do
- before :each do
- @scope = Puppet::Parser::Scope.new
- end
-
- it "should exist" do
- Puppet::Parser::Functions.function("shellquote").should == "function_shellquote"
- end
-
-
- it "should handle no arguments" do
- result = @scope.function_shellquote([])
- result.should(eql(""))
- end
-
- it "should handle several simple arguments" do
- result = @scope.function_shellquote( ['foo', 'bar@example.com', 'localhost:/dev/null', 'xyzzy+-4711,23'])
- result.should(eql( 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
- end
-
- it "should handle array arguments" do
-
- result = @scope.function_shellquote(
-
- ['foo', ['bar@example.com', 'localhost:/dev/null'],
-
- 'xyzzy+-4711,23'])
- result.should(eql(
- 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
- end
-
- it "should quote unsafe characters" do
- result = @scope.function_shellquote( ['/etc/passwd ', '(ls)', '*', '[?]', "'&'"])
- result.should(eql( '"/etc/passwd " "(ls)" "*" "[?]" "\'&\'"'))
- end
-
- it "should deal with double quotes" do
- result = @scope.function_shellquote(
- ['"foo"bar"'])
- result.should(eql(
- '\'"foo"bar"\''))
- end
-
- it "should cope with dollar signs" do
- result = @scope.function_shellquote( ['$PATH', 'foo$bar', '"x$"'])
- result.should(eql( "'$PATH' 'foo$bar' '\"x$\"'"))
- end
-
- it "should deal with apostrophes (single quotes)" do
- result = @scope.function_shellquote(
- ["'foo'bar'", "`$'EDITOR'`"])
- result.should(eql(
- '"\'foo\'bar\'" "\\`\\$\'EDITOR\'\\`"'))
- end
-
- it "should cope with grave accents (backquotes)" do
- result = @scope.function_shellquote( ['`echo *`', '`ls "$MAILPATH"`'])
- result.should(eql( "'`echo *`' '`ls \"$MAILPATH\"`'"))
- end
-
- it "should deal with both single and double quotes" do
- result = @scope.function_shellquote( ['\'foo"bar"xyzzy\'', '"foo\'bar\'xyzzy"'])
- result.should(eql( '"\'foo\\"bar\\"xyzzy\'" "\\"foo\'bar\'xyzzy\\""'))
- end
-
- it "should handle multiple quotes *and* dollars and backquotes" do
- result = @scope.function_shellquote( ['\'foo"$x`bar`"xyzzy\''])
- result.should(eql( '"\'foo\\"\\$x\\`bar\\`\\"xyzzy\'"'))
- end
-
- it "should handle linefeeds" do
- result = @scope.function_shellquote( ["foo \n bar"])
- result.should(eql( "\"foo \n bar\""))
- end
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("shellquote").should == "function_shellquote"
+ end
+
+
+ it "should handle no arguments" do
+ result = @scope.function_shellquote([])
+ result.should(eql(""))
+ end
+
+ it "should handle several simple arguments" do
+ result = @scope.function_shellquote( ['foo', 'bar@example.com', 'localhost:/dev/null', 'xyzzy+-4711,23'])
+ result.should(eql( 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
+ end
+
+ it "should handle array arguments" do
+
+ result = @scope.function_shellquote(
+
+ ['foo', ['bar@example.com', 'localhost:/dev/null'],
+
+ 'xyzzy+-4711,23'])
+ result.should(eql(
+ 'foo bar@example.com localhost:/dev/null xyzzy+-4711,23'))
+ end
+
+ it "should quote unsafe characters" do
+ result = @scope.function_shellquote( ['/etc/passwd ', '(ls)', '*', '[?]', "'&'"])
+ result.should(eql( '"/etc/passwd " "(ls)" "*" "[?]" "\'&\'"'))
+ end
+
+ it "should deal with double quotes" do
+ result = @scope.function_shellquote(
+ ['"foo"bar"'])
+ result.should(eql(
+ '\'"foo"bar"\''))
+ end
+
+ it "should cope with dollar signs" do
+ result = @scope.function_shellquote( ['$PATH', 'foo$bar', '"x$"'])
+ result.should(eql( "'$PATH' 'foo$bar' '\"x$\"'"))
+ end
+
+ it "should deal with apostrophes (single quotes)" do
+ result = @scope.function_shellquote(
+ ["'foo'bar'", "`$'EDITOR'`"])
+ result.should(eql(
+ '"\'foo\'bar\'" "\\`\\$\'EDITOR\'\\`"'))
+ end
+
+ it "should cope with grave accents (backquotes)" do
+ result = @scope.function_shellquote( ['`echo *`', '`ls "$MAILPATH"`'])
+ result.should(eql( "'`echo *`' '`ls \"$MAILPATH\"`'"))
+ end
+
+ it "should deal with both single and double quotes" do
+ result = @scope.function_shellquote( ['\'foo"bar"xyzzy\'', '"foo\'bar\'xyzzy"'])
+ result.should(eql( '"\'foo\\"bar\\"xyzzy\'" "\\"foo\'bar\'xyzzy\\""'))
+ end
+
+ it "should handle multiple quotes *and* dollars and backquotes" do
+ result = @scope.function_shellquote( ['\'foo"$x`bar`"xyzzy\''])
+ result.should(eql( '"\'foo\\"\\$x\\`bar\\`\\"xyzzy\'"'))
+ end
+
+ it "should handle linefeeds" do
+ result = @scope.function_shellquote( ["foo \n bar"])
+ result.should(eql( "\"foo \n bar\""))
+ end
end
diff --git a/spec/unit/parser/functions/split_spec.rb b/spec/unit/parser/functions/split_spec.rb
index d76c253b0..a1c83bb0f 100755
--- a/spec/unit/parser/functions/split_spec.rb
+++ b/spec/unit/parser/functions/split_spec.rb
@@ -4,46 +4,46 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the split function" do
- before :each do
- @scope = Puppet::Parser::Scope.new
- end
-
- it "should exist" do
- Puppet::Parser::Functions.function("split").should == "function_split"
- end
-
- it "should raise a ParseError if there is less than 2 arguments" do
- lambda { @scope.function_split(["foo"]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should raise a ParseError if there is more than 2 arguments" do
- lambda { @scope.function_split(["foo", "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError))
- end
-
- it "should raise a RegexpError if the regexp is malformed" do
- lambda { @scope.function_split(["foo", "("]) }.should(
- raise_error(RegexpError))
- end
-
-
- it "should handle simple string without metacharacters" do
- result = @scope.function_split([ "130;236;254;10", ";"])
- result.should(eql(["130", "236", "254", "10"]))
- end
-
- it "should handle simple regexps" do
- result = @scope.function_split([ "130.236;254.;10", "[.;]+"])
- result.should(eql(["130", "236", "254", "10"]))
- end
-
- it "should handle groups" do
- result = @scope.function_split([ "130.236;254.;10", "([.;]+)"])
- result.should(eql(["130", ".", "236", ";", "254", ".;", "10"]))
- end
-
- it "should handle simple string without metacharacters" do
- result = @scope.function_split([ "130.236.254.10", ";"])
- result.should(eql(["130.236.254.10"]))
- end
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("split").should == "function_split"
+ end
+
+ it "should raise a ParseError if there is less than 2 arguments" do
+ lambda { @scope.function_split(["foo"]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there is more than 2 arguments" do
+ lambda { @scope.function_split(["foo", "bar", "gazonk"]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a RegexpError if the regexp is malformed" do
+ lambda { @scope.function_split(["foo", "("]) }.should(
+ raise_error(RegexpError))
+ end
+
+
+ it "should handle simple string without metacharacters" do
+ result = @scope.function_split([ "130;236;254;10", ";"])
+ result.should(eql(["130", "236", "254", "10"]))
+ end
+
+ it "should handle simple regexps" do
+ result = @scope.function_split([ "130.236;254.;10", "[.;]+"])
+ result.should(eql(["130", "236", "254", "10"]))
+ end
+
+ it "should handle groups" do
+ result = @scope.function_split([ "130.236;254.;10", "([.;]+)"])
+ result.should(eql(["130", ".", "236", ";", "254", ".;", "10"]))
+ end
+
+ it "should handle simple string without metacharacters" do
+ result = @scope.function_split([ "130.236.254.10", ";"])
+ result.should(eql(["130.236.254.10"]))
+ end
end
diff --git a/spec/unit/parser/functions/sprintf_spec.rb b/spec/unit/parser/functions/sprintf_spec.rb
index 3795479e4..01545a879 100755
--- a/spec/unit/parser/functions/sprintf_spec.rb
+++ b/spec/unit/parser/functions/sprintf_spec.rb
@@ -4,38 +4,38 @@ 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
+ 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
diff --git a/spec/unit/parser/functions/tag_spec.rb b/spec/unit/parser/functions/tag_spec.rb
index 4f08afedf..ff37badbb 100755
--- a/spec/unit/parser/functions/tag_spec.rb
+++ b/spec/unit/parser/functions/tag_spec.rb
@@ -4,21 +4,21 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the 'tag' function" do
- before :each do
- @scope = Puppet::Parser::Scope.new
- end
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
- it "should exist" do
- Puppet::Parser::Functions.function(:tag).should == "function_tag"
- end
+ it "should exist" do
+ Puppet::Parser::Functions.function(:tag).should == "function_tag"
+ end
- it "should tag the resource with any provided tags" do
- resource = Puppet::Parser::Resource.new(:file, "/file", :scope => @scope)
- @scope.expects(:resource).returns resource
+ it "should tag the resource with any provided tags" do
+ resource = Puppet::Parser::Resource.new(:file, "/file", :scope => @scope)
+ @scope.expects(:resource).returns resource
- @scope.function_tag ["one", "two"]
+ @scope.function_tag ["one", "two"]
- resource.should be_tagged("one")
- resource.should be_tagged("two")
- end
+ resource.should be_tagged("one")
+ resource.should be_tagged("two")
+ end
end
diff --git a/spec/unit/parser/functions/template_spec.rb b/spec/unit/parser/functions/template_spec.rb
index 87c7d5d24..096b0598e 100755
--- a/spec/unit/parser/functions/template_spec.rb
+++ b/spec/unit/parser/functions/template_spec.rb
@@ -4,59 +4,59 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the template function" do
- before :each do
- @scope = Puppet::Parser::Scope.new
- end
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
- it "should exist" do
- Puppet::Parser::Functions.function("template").should == "function_template"
- end
+ it "should exist" do
+ Puppet::Parser::Functions.function("template").should == "function_template"
+ end
- it "should create a TemplateWrapper when called" do
- tw = stub_everything 'template_wrapper'
+ it "should create a TemplateWrapper when called" do
+ tw = stub_everything 'template_wrapper'
- Puppet::Parser::TemplateWrapper.expects(:new).returns(tw)
+ Puppet::Parser::TemplateWrapper.expects(:new).returns(tw)
- @scope.function_template("test")
- end
+ @scope.function_template("test")
+ end
- it "should give the template filename to the TemplateWrapper" do
- tw = stub_everything 'template_wrapper'
- Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
+ it "should give the template filename to the TemplateWrapper" do
+ tw = stub_everything 'template_wrapper'
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
- tw.expects(:file=).with("test")
+ tw.expects(:file=).with("test")
- @scope.function_template("test")
- end
+ @scope.function_template("test")
+ end
- it "should return what TemplateWrapper.result returns" do
- tw = stub_everything 'template_wrapper'
- Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
- tw.stubs(:file=).with("test")
+ it "should return what TemplateWrapper.result returns" do
+ tw = stub_everything 'template_wrapper'
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
+ tw.stubs(:file=).with("test")
- tw.expects(:result).returns("template contents evaluated")
+ tw.expects(:result).returns("template contents evaluated")
- @scope.function_template("test").should == "template contents evaluated"
- end
+ @scope.function_template("test").should == "template contents evaluated"
+ end
- it "should concatenate template wrapper outputs for multiple templates" do
- tw1 = stub_everything "template_wrapper1"
- tw2 = stub_everything "template_wrapper2"
- Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw1,tw2)
- tw1.stubs(:file=).with("1")
- tw2.stubs(:file=).with("2")
- tw1.stubs(:result).returns("result1")
- tw2.stubs(:result).returns("result2")
+ it "should concatenate template wrapper outputs for multiple templates" do
+ tw1 = stub_everything "template_wrapper1"
+ tw2 = stub_everything "template_wrapper2"
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw1,tw2)
+ tw1.stubs(:file=).with("1")
+ tw2.stubs(:file=).with("2")
+ tw1.stubs(:result).returns("result1")
+ tw2.stubs(:result).returns("result2")
- @scope.function_template(["1","2"]).should == "result1result2"
- end
+ @scope.function_template(["1","2"]).should == "result1result2"
+ end
- it "should raise an error if the template raises an error" do
- tw = stub_everything 'template_wrapper'
- Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
- tw.stubs(:result).raises
+ it "should raise an error if the template raises an error" do
+ tw = stub_everything 'template_wrapper'
+ Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw)
+ tw.stubs(:result).raises
- lambda { @scope.function_template("1") }.should raise_error(Puppet::ParseError)
- end
+ lambda { @scope.function_template("1") }.should raise_error(Puppet::ParseError)
+ end
end \ No newline at end of file
diff --git a/spec/unit/parser/functions/versioncmp_spec.rb b/spec/unit/parser/functions/versioncmp_spec.rb
index d57ea57ad..380c6307a 100755
--- a/spec/unit/parser/functions/versioncmp_spec.rb
+++ b/spec/unit/parser/functions/versioncmp_spec.rb
@@ -4,26 +4,26 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "the versioncmp function" do
- before :each do
- @scope = Puppet::Parser::Scope.new
- end
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
- it "should exist" do
- Puppet::Parser::Functions.function("versioncmp").should == "function_versioncmp"
- end
+ it "should exist" do
+ Puppet::Parser::Functions.function("versioncmp").should == "function_versioncmp"
+ end
- it "should raise a ParseError if there is less than 2 arguments" do
- lambda { @scope.function_versioncmp(["1.2"]) }.should raise_error(Puppet::ParseError)
- end
+ it "should raise a ParseError if there is less than 2 arguments" do
+ lambda { @scope.function_versioncmp(["1.2"]) }.should raise_error(Puppet::ParseError)
+ end
- it "should raise a ParseError if there is more than 2 arguments" do
- lambda { @scope.function_versioncmp(["1.2", "2.4.5", "3.5.6"]) }.should raise_error(Puppet::ParseError)
- end
+ it "should raise a ParseError if there is more than 2 arguments" do
+ lambda { @scope.function_versioncmp(["1.2", "2.4.5", "3.5.6"]) }.should raise_error(Puppet::ParseError)
+ end
- it "should call Puppet::Util::Package.versioncmp (included in scope)" do
- Puppet::Util::Package.expects(:versioncmp).with("1.2", "1.3").returns(-1)
+ it "should call Puppet::Util::Package.versioncmp (included in scope)" do
+ Puppet::Util::Package.expects(:versioncmp).with("1.2", "1.3").returns(-1)
- @scope.function_versioncmp(["1.2", "1.3"])
- end
+ @scope.function_versioncmp(["1.2", "1.3"])
+ end
end