diff options
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-x | spec/unit/parser/ast/casestatement_spec.rb | 8 | ||||
-rwxr-xr-x | spec/unit/parser/ast/comparison_operator_spec.rb | 18 | ||||
-rwxr-xr-x | spec/unit/parser/ast/vardef_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/parser/ast_spec.rb | 6 | ||||
-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 | ||||
-rwxr-xr-x | spec/unit/parser/lexer_spec.rb | 8 | ||||
-rwxr-xr-x | spec/unit/parser/parser_spec.rb | 48 | ||||
-rwxr-xr-x | spec/unit/parser/resource_spec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/parser/scope_spec.rb | 15 | ||||
-rwxr-xr-x | spec/unit/parser/templatewrapper_spec.rb | 14 |
14 files changed, 179 insertions, 162 deletions
diff --git a/spec/unit/parser/ast/casestatement_spec.rb b/spec/unit/parser/ast/casestatement_spec.rb index 240d3bfea..187dd5822 100755 --- a/spec/unit/parser/ast/casestatement_spec.rb +++ b/spec/unit/parser/ast/casestatement_spec.rb @@ -136,11 +136,13 @@ describe Puppet::Parser::AST::CaseStatement do } options = tests.collect do |result, values| values = values.collect { |v| AST::Leaf.new :value => v } - AST::CaseOpt.new(:value => AST::ASTArray.new(:children => values), + + AST::CaseOpt.new( + :value => AST::ASTArray.new(:children => values), + :statements => AST::Leaf.new(:value => result)) end - options << AST::CaseOpt.new(:value => AST::Default.new(:value => "default"), - :statements => AST::Leaf.new(:value => "default")) + options << AST::CaseOpt.new(:value => AST::Default.new(:value => "default"), :statements => AST::Leaf.new(:value => "default")) ast = nil param = AST::Variable.new(:value => "testparam") diff --git a/spec/unit/parser/ast/comparison_operator_spec.rb b/spec/unit/parser/ast/comparison_operator_spec.rb index 97402433f..51f4cc516 100755 --- a/spec/unit/parser/ast/comparison_operator_spec.rb +++ b/spec/unit/parser/ast/comparison_operator_spec.rb @@ -54,11 +54,11 @@ describe Puppet::Parser::AST::ComparisonOperator do end %w{< > <= >= ==}.each do |oper| - it "should return the result of using '#{oper}' to compare the left and right sides" do - operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @one, :operator => oper, :rval => @two + it "should return the result of using '#{oper}' to compare the left and right sides" do + operator = Puppet::Parser::AST::ComparisonOperator.new :lval => @one, :operator => oper, :rval => @two - operator.evaluate(@scope).should == 1.send(oper,2) - end + operator.evaluate(@scope).should == 1.send(oper,2) + end end it "should return the result of using '!=' to compare the left and right sides" do @@ -81,12 +81,12 @@ describe Puppet::Parser::AST::ComparisonOperator do # see ticket #1759 %w{< > <= >=}.each do |oper| it "should return the correct result of using '#{oper}' to compare 10 and 9" do - ten = stub 'one', :safeevaluate => "10" - nine = stub 'two', :safeevaluate => "9" - operator = Puppet::Parser::AST::ComparisonOperator.new :lval => ten, :operator => oper, :rval => nine + ten = stub 'one', :safeevaluate => "10" + nine = stub 'two', :safeevaluate => "9" + operator = Puppet::Parser::AST::ComparisonOperator.new :lval => ten, :operator => oper, :rval => nine - operator.evaluate(@scope).should == 10.send(oper,9) - end + operator.evaluate(@scope).should == 10.send(oper,9) + end end end diff --git a/spec/unit/parser/ast/vardef_spec.rb b/spec/unit/parser/ast/vardef_spec.rb index a6863e75f..369a9f847 100755 --- a/spec/unit/parser/ast/vardef_spec.rb +++ b/spec/unit/parser/ast/vardef_spec.rb @@ -17,7 +17,7 @@ describe Puppet::Parser::AST::VarDef do value.expects(:safeevaluate).with(@scope) vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, - :line => nil + :line => nil vardef.evaluate(@scope) end @@ -28,7 +28,7 @@ describe Puppet::Parser::AST::VarDef do @scope.expects(:setvar).with { |name,value,options| options[:append] == nil } vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, - :line => nil + :line => nil vardef.evaluate(@scope) end @@ -39,7 +39,7 @@ describe Puppet::Parser::AST::VarDef do @scope.expects(:setvar).with { |name,value,options| options[:append] == true } vardef = Puppet::Parser::AST::VarDef.new :name => name, :value => value, :file => nil, - :line => nil, :append => true + :line => nil, :append => true vardef.evaluate(@scope) end diff --git a/spec/unit/parser/ast_spec.rb b/spec/unit/parser/ast_spec.rb index ca6f8080a..cd271af98 100644 --- a/spec/unit/parser/ast_spec.rb +++ b/spec/unit/parser/ast_spec.rb @@ -21,9 +21,9 @@ describe Puppet::Parser::AST do end [ Puppet::Parser::AST::Collection, Puppet::Parser::AST::Else, - Puppet::Parser::AST::Function, Puppet::Parser::AST::IfStatement, - Puppet::Parser::AST::Resource, Puppet::Parser::AST::ResourceDefaults, - Puppet::Parser::AST::ResourceOverride, Puppet::Parser::AST::VarDef + Puppet::Parser::AST::Function, Puppet::Parser::AST::IfStatement, + Puppet::Parser::AST::Resource, Puppet::Parser::AST::ResourceDefaults, + Puppet::Parser::AST::ResourceOverride, Puppet::Parser::AST::VarDef ].each do |k| it "#{k}.use_docs should return true" do ast = k.new({}) 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 diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb index c437034a4..47a768469 100755 --- a/spec/unit/parser/lexer_spec.rb +++ b/spec/unit/parser/lexer_spec.rb @@ -357,8 +357,8 @@ describe Puppet::Parser::Lexer::TOKENS[:MLCOMMENT] do it "should match multiple lines enclosed with '/*' and '*/'" do @token.regex.should =~ """/* - this is a comment - */""" + this is a comment + */""" end it "should increase the lexer current line number by the amount of lines spanned by the comment" do @@ -480,8 +480,8 @@ describe Puppet::Parser::Lexer::TOKENS[:REGEX] do :CASE,:VARIABLE,:LBRACE,:STRING,:COLON,:LBRACE,:VARIABLE,:EQUALS,:NAME,:DIV,:NAME,:RBRACE,[:REGEX,/regex/],:COLON,:LBRACE,:NAME,:LPAREN,:STRING,:RPAREN,:RBRACE,:RBRACE ) end - - end + + end it "should return the REGEX token and a Regexp" do diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb index 2cbb80f9b..53a16e62a 100755 --- a/spec/unit/parser/parser_spec.rb +++ b/spec/unit/parser/parser_spec.rb @@ -32,7 +32,7 @@ describe Puppet::Parser do parser = Puppet::Parser::Parser.new "development" parser.known_resource_types.should equal(rtc) end - + it "should delegate importing to the known resource type loader" do parser = Puppet::Parser::Parser.new "development" parser.known_resource_types.loader.expects(:import).with("newfile", "current_file") @@ -100,32 +100,32 @@ describe Puppet::Parser do end it "comparison operation, it should create the correct ast objects" do - ast::ComparisonOperator.expects(:new).with { - |h| h[:lval].is_a?(ast::Name) and h[:rval].is_a?(ast::Name) and h[:operator]=="<" - } - @parser.parse("if 1 < 2 { $var = 1 }") + ast::ComparisonOperator.expects(:new).with { + |h| h[:lval].is_a?(ast::Name) and h[:rval].is_a?(ast::Name) and h[:operator]=="<" + } + @parser.parse("if 1 < 2 { $var = 1 }") end end describe "when parsing if complex expressions" do - it "should create a correct ast tree" do - aststub = stub_everything 'ast' - ast::ComparisonOperator.expects(:new).with { - |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]==">" - }.returns(aststub) - ast::ComparisonOperator.expects(:new).with { - |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]=="==" - }.returns(aststub) - ast::BooleanOperator.expects(:new).with { - |h| h[:rval]==aststub and h[:lval]==aststub and h[:operator]=="and" - } - @parser.parse("if (1 > 2) and (1 == 2) { $var = 1 }") - end - - it "should raise an error on incorrect expression" do - lambda { @parser.parse("if (1 > 2 > ) or (1 == 2) { $var = 1 }") }.should raise_error + it "should create a correct ast tree" do + aststub = stub_everything 'ast' + ast::ComparisonOperator.expects(:new).with { + |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]==">" + }.returns(aststub) + ast::ComparisonOperator.expects(:new).with { + |h| h[:rval].is_a?(ast::Name) and h[:lval].is_a?(ast::Name) and h[:operator]=="==" + }.returns(aststub) + ast::BooleanOperator.expects(:new).with { + |h| h[:rval]==aststub and h[:lval]==aststub and h[:operator]=="and" + } + @parser.parse("if (1 > 2) and (1 == 2) { $var = 1 }") + end + + it "should raise an error on incorrect expression" do + lambda { @parser.parse("if (1 > 2 > ) or (1 == 2) { $var = 1 }") }.should raise_error end end @@ -194,7 +194,7 @@ describe Puppet::Parser do it "should build a chain of 'ifs' if there's an 'elsif'" do ast = @parser.parse(<<-PP) - if true { notice('test') } elsif true {} else { } + if true { notice('test') } elsif true {} else { } PP end @@ -398,12 +398,12 @@ describe Puppet::Parser do @krt.add(Puppet::Resource::Type.new(:hostclass, "foobar", :arguments => {"biz" => nil})) lambda { @parser.parse("class { foobar: biz => stuff }") }.should_not raise_error end - + it "should correctly mark exported resources as exported" do @parser.parse("@@file { '/file': }") @krt.hostclass("").code[0].exported.should be_true end - + it "should correctly mark virtual resources as virtual" do @parser.parse("@file { '/file': }") @krt.hostclass("").code[0].virtual.should be_true diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb index 9d407c0e7..31bde27dd 100755 --- a/spec/unit/parser/resource_spec.rb +++ b/spec/unit/parser/resource_spec.rb @@ -496,7 +496,7 @@ describe Puppet::Parser::Resource do end it "should fail if the same param is declared twice" do - lambda do + lambda do @parser_resource = mkresource :source => @source, :parameters => [ Puppet::Parser::Resource::Param.new( :name => :foo, :value => "bar", :source => @source diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb index 29dca38f4..94192a693 100755 --- a/spec/unit/parser/scope_spec.rb +++ b/spec/unit/parser/scope_spec.rb @@ -11,7 +11,7 @@ describe Puppet::Parser::Scope do @scope.compiler = Puppet::Parser::Compiler.new(Puppet::Node.new("foo")) @scope.parent = @topscope end - + it "should be able to store references to class scopes" do lambda { @scope.class_set "myname", "myscope" }.should_not raise_error end @@ -500,8 +500,7 @@ describe Puppet::Parser::Scope do assert_equal("value", scope.lookupvar("::test"), "did not look up qualified value correctly") tests.each do |input, output| assert_nothing_raised("Failed to scan %s" % input.inspect) do - assert_equal(output, scope.strinterp(input), - 'did not parserret %s correctly' % input.inspect) + assert_equal(output, scope.strinterp(input), 'did not parserret %s correctly' % input.inspect) end end @@ -513,11 +512,17 @@ describe Puppet::Parser::Scope do %w{d f h l w z}.each do |l| string = "\\" + l assert_nothing_raised do - assert_equal(string, scope.strinterp(string), + + assert_equal( + string, scope.strinterp(string), + 'did not parserret %s correctly' % string) end - assert(logs.detect { |m| m.message =~ /Unrecognised escape/ }, + + assert( + logs.detect { |m| m.message =~ /Unrecognised escape/ }, + "Did not get warning about escape sequence with %s" % string) logs.clear end diff --git a/spec/unit/parser/templatewrapper_spec.rb b/spec/unit/parser/templatewrapper_spec.rb index 1b4121643..9a16666fd 100755 --- a/spec/unit/parser/templatewrapper_spec.rb +++ b/spec/unit/parser/templatewrapper_spec.rb @@ -120,18 +120,18 @@ describe Puppet::Parser::TemplateWrapper do @tw.result("template contents") @tw.instance_variable_get("@one").should == "foo" - end + end - it "should not error out if one of the variables is a symbol" do + it "should not error out if one of the variables is a symbol" do template_mock = mock("template", :result => "woot!") ERB.expects(:new).with("template contents", 0, "-").returns(template_mock) @scope.expects(:to_hash).returns(:_timestamp => "1234") @tw.result("template contents") - end + end - %w{! . ; :}.each do |badchar| - it "should translate #{badchar} to _ when setting the instance variables" do + %w{! . ; :}.each do |badchar| + it "should translate #{badchar} to _ when setting the instance variables" do template_mock = mock("template", :result => "woot!") ERB.expects(:new).with("template contents", 0, "-").returns(template_mock) @@ -139,6 +139,6 @@ describe Puppet::Parser::TemplateWrapper do @tw.result("template contents") @tw.instance_variable_get("@one_").should == "foo" - end - end + end + end end |