diff options
Diffstat (limited to 'spec/unit/parser/functions')
-rwxr-xr-x | spec/unit/parser/functions/defined_spec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/parser/functions/regsubst_spec.rb | 134 | ||||
-rwxr-xr-x | spec/unit/parser/functions/shellquote_spec.rb | 51 | ||||
-rwxr-xr-x | spec/unit/parser/functions/split_spec.rb | 24 | ||||
-rwxr-xr-x | spec/unit/parser/functions/sprintf_spec.rb | 5 |
5 files changed, 113 insertions, 103 deletions
diff --git a/spec/unit/parser/functions/defined_spec.rb b/spec/unit/parser/functions/defined_spec.rb index 03b0ef9dd..90f2f5239 100755 --- a/spec/unit/parser/functions/defined_spec.rb +++ b/spec/unit/parser/functions/defined_spec.rb @@ -18,7 +18,7 @@ describe "the 'defined' function" 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 diff --git a/spec/unit/parser/functions/regsubst_spec.rb b/spec/unit/parser/functions/regsubst_spec.rb index 5a533efb1..6ff619f8d 100755 --- a/spec/unit/parser/functions/regsubst_spec.rb +++ b/spec/unit/parser/functions/regsubst_spec.rb @@ -13,29 +13,24 @@ describe "the regsubst function" do 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)) + 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)) + 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)) + 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)) + 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)) + 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 @@ -44,63 +39,80 @@ describe "the regsubst function" do 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)) + lambda { @scope.function_regsubst(["foo", ["bar"], "gazonk"]) }.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' + + '^([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" + "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" + "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" + "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" + "[ \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' + + '([0-9]+)', + '<\1>', + 'G' ]) result.should(eql('<130>.<236>.<254>.<10>')) end @@ -108,59 +120,71 @@ describe "the regsubst function" do 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'])) + 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'])) + 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'] - result = @scope.function_regsubst( - [ data, - '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$', - '\4-\3-\2-\1' + + result = @scope.function_regsubst( + + [ 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'])) + 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'] - result = @scope.function_regsubst( - [ data, - '([^.]+)', - '<\1>', - 'G' + + result = @scope.function_regsubst( + + [ data, + + '([^.]+)', + '<\1>', + 'G' ]) - result.should(eql( - ['<130>.<236>.<254>.<10>', '<foo>.<example>.<com>', - '<coconut>', '<10>.<20>.<30>.<40>'])) + + result.should(eql( + + ['<130>.<236>.<254>.<10>', '<foo>.<example>.<com>', + + '<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'] - result = @scope.function_regsubst( - [ data, - '([^.]+)', - '<\1>', - 'G' + + result = @scope.function_regsubst( + + [ data, + + '([^.]+)', + '<\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' - result = @scope.function_regsubst( - [ data, - '([^.]+)', - '<\1>', - 'G' + + result = @scope.function_regsubst( + + [ data, + + '([^.]+)', + '<\1>', + 'G' ]) result.should(eql('<130>.<236>.<254>.<10>')) end diff --git a/spec/unit/parser/functions/shellquote_spec.rb b/spec/unit/parser/functions/shellquote_spec.rb index 283a4de1e..8286be32e 100755 --- a/spec/unit/parser/functions/shellquote_spec.rb +++ b/spec/unit/parser/functions/shellquote_spec.rb @@ -19,74 +19,63 @@ describe "the shellquote function" do 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')) + 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']) + + '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)" "*" "[?]" "\'&\'"')) + 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"']) + ['"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$\"'")) + 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'`"]) + ["'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\"`'")) + 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\\""')) + 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\'"')) + 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\"")) + 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 8aa031d19..3d0240af4 100755 --- a/spec/unit/parser/functions/split_spec.rb +++ b/spec/unit/parser/functions/split_spec.rb @@ -13,39 +13,37 @@ describe "the split function" do end it "should raise a ParseError if there is less than 2 arguments" do - lambda { @scope.function_split(["foo"]) }.should( - raise_error(Puppet::ParseError)) + 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)) + 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)) + 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"])) + 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"])) + 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"])) + 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"])) + 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 949dc3fcc..71921e0e0 100755 --- a/spec/unit/parser/functions/sprintf_spec.rb +++ b/spec/unit/parser/functions/sprintf_spec.rb @@ -13,8 +13,7 @@ describe "the sprintf function" do end it "should raise a ParseError if there is less than 1 argument" do - lambda { @scope.function_sprintf([]) }.should( - raise_error(Puppet::ParseError)) + lambda { @scope.function_sprintf([]) }.should( raise_error(Puppet::ParseError)) end it "should format integers" do @@ -35,7 +34,7 @@ describe "the sprintf function" do it "should perform more complex formatting" do result = @scope.function_sprintf( [ "<%.8s:%#5o %#8X (%-8s)>", - "overlongstring", "23", "48879", "foo" ]) + "overlongstring", "23", "48879", "foo" ]) result.should(eql("<overlong: 027 0XBEEF (foo )>")) end |