diff options
author | Luke Kanies <luke@madstop.com> | 2009-02-13 18:24:34 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2009-02-13 18:24:34 -0600 |
commit | 3fbec120768d84d208b14f574dfe916e25cfdbef (patch) | |
tree | 865d59f4ea9cf3782db46ce1ae7fd54b95945035 /spec/unit/parser/functions/regsubst.rb | |
parent | a2270b4a4f093c6c4f171dcf0c0e05fe101dd979 (diff) | |
parent | 2561c8e252dcf66890513458750bb1329a03beec (diff) | |
download | puppet-3fbec120768d84d208b14f574dfe916e25cfdbef.tar.gz puppet-3fbec120768d84d208b14f574dfe916e25cfdbef.tar.xz puppet-3fbec120768d84d208b14f574dfe916e25cfdbef.zip |
Merge branch '0.24.x'
Conflicts:
lib/puppet/indirector/facts/facter.rb
lib/puppet/provider/augeas/augeas.rb
lib/puppet/util/filetype.rb
spec/unit/indirector/facts/facter.rb
spec/unit/provider/augeas/augeas.rb
test/util/filetype.rb
Diffstat (limited to 'spec/unit/parser/functions/regsubst.rb')
-rw-r--r-- | spec/unit/parser/functions/regsubst.rb | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/spec/unit/parser/functions/regsubst.rb b/spec/unit/parser/functions/regsubst.rb new file mode 100644 index 000000000..18f49f7d4 --- /dev/null +++ b/spec/unit/parser/functions/regsubst.rb @@ -0,0 +1,88 @@ +#! /usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe "the regsubst function" do + + before :each do + @scope = Puppet::Parser::Scope.new() + 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 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 handle groups" do + result = @scope.function_regsubst( + [ '130.236.254.10', + '^([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 + result = @scope.function_regsubst( + [ "the monkey breaks banana trees", + "b[an]*a", + "coconut" + ]) + result.should(eql("the monkey breaks coconut trees")) + end + + it "should handle case-sensitive regexps" do + result = @scope.function_regsubst( + [ "the monkey breaks baNAna trees", + "b[an]+a", + "coconut" + ]) + result.should(eql("the monkey breaks baNAna trees")) + end + + it "should handle case-insensitive regexps" do + result = @scope.function_regsubst( + [ "the monkey breaks baNAna trees", + "b[an]+a", + "coconut", + "I" + ]) + result.should(eql("the monkey breaks coconut trees")) + end + + it "should handle global substitutions" do + result = @scope.function_regsubst( + [ "the monkey breaks\tbanana trees", + "[ \t]", + "--", + "G" + ]) + result.should(eql("the--monkey--breaks--banana--trees")) + end + + it "should handle global substitutions with groups" do + result = @scope.function_regsubst( + [ '130.236.254.10', + '([0-9]+)', + '<\1>', + 'G' + ]) + result.should(eql('<130>.<236>.<254>.<10>')) + end + +end |