summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/functions/regsubst_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/parser/functions/regsubst_spec.rb')
-rwxr-xr-xspec/unit/parser/functions/regsubst_spec.rb260
1 files changed, 130 insertions, 130 deletions
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