diff options
| author | James Turnbull <james@lovedthanlost.net> | 2009-06-12 22:39:33 +1000 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-06-12 22:39:33 +1000 |
| commit | 5fbf63ce789b015da9abb95d7e9fbbf4a44ba7d1 (patch) | |
| tree | 3dbf7e79fe773530a2ad007246b3e30d5fd925f0 /spec/unit/parser/functions | |
| parent | a585bddadf49b1c1d41052f6fdd62db832bca49c (diff) | |
| download | puppet-5fbf63ce789b015da9abb95d7e9fbbf4a44ba7d1.tar.gz puppet-5fbf63ce789b015da9abb95d7e9fbbf4a44ba7d1.tar.xz puppet-5fbf63ce789b015da9abb95d7e9fbbf4a44ba7d1.zip | |
Updated split function and add split function unit tests (courtesy of Thomas Bellman)
Diffstat (limited to 'spec/unit/parser/functions')
| -rwxr-xr-x[-rw-r--r--] | spec/unit/parser/functions/inline_template.rb | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | spec/unit/parser/functions/regsubst.rb | 0 | ||||
| -rwxr-xr-x | spec/unit/parser/functions/split.rb | 51 | ||||
| -rwxr-xr-x[-rw-r--r--] | spec/unit/parser/functions/sprintf.rb | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | spec/unit/parser/functions/template.rb | 0 |
5 files changed, 51 insertions, 0 deletions
diff --git a/spec/unit/parser/functions/inline_template.rb b/spec/unit/parser/functions/inline_template.rb index 19e1a3b2a..19e1a3b2a 100644..100755 --- a/spec/unit/parser/functions/inline_template.rb +++ b/spec/unit/parser/functions/inline_template.rb diff --git a/spec/unit/parser/functions/regsubst.rb b/spec/unit/parser/functions/regsubst.rb index 0e80ec798..0e80ec798 100644..100755 --- a/spec/unit/parser/functions/regsubst.rb +++ b/spec/unit/parser/functions/regsubst.rb diff --git a/spec/unit/parser/functions/split.rb b/spec/unit/parser/functions/split.rb new file mode 100755 index 000000000..8aa031d19 --- /dev/null +++ b/spec/unit/parser/functions/split.rb @@ -0,0 +1,51 @@ +#! /usr/bin/env ruby + +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 + +end diff --git a/spec/unit/parser/functions/sprintf.rb b/spec/unit/parser/functions/sprintf.rb index 949dc3fcc..949dc3fcc 100644..100755 --- a/spec/unit/parser/functions/sprintf.rb +++ b/spec/unit/parser/functions/sprintf.rb diff --git a/spec/unit/parser/functions/template.rb b/spec/unit/parser/functions/template.rb index 8fc64d0c3..8fc64d0c3 100644..100755 --- a/spec/unit/parser/functions/template.rb +++ b/spec/unit/parser/functions/template.rb |
