diff options
author | Luke Kanies <luke@madstop.com> | 2008-12-01 13:43:12 -0600 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-12-02 09:12:39 +1100 |
commit | 1b3a7d8c9ce8d4384b76be47c952d2bab7580481 (patch) | |
tree | d4f3dae024e08c98b8584973f6a8c4d61cff9f75 /spec/unit | |
parent | 091b8bf11c83ed31f85d859e6c97730ea5e4905a (diff) | |
download | puppet-1b3a7d8c9ce8d4384b76be47c952d2bab7580481.tar.gz puppet-1b3a7d8c9ce8d4384b76be47c952d2bab7580481.tar.xz puppet-1b3a7d8c9ce8d4384b76be47c952d2bab7580481.zip |
Fixing the AST constant warnings, using a variable instead of a constant
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit')
-rwxr-xr-x | spec/unit/parser/ast/arithmetic_operator.rb | 20 | ||||
-rwxr-xr-x | spec/unit/parser/ast/boolean_operator.rb | 18 | ||||
-rwxr-xr-x | spec/unit/parser/ast/collexpr.rb | 22 | ||||
-rwxr-xr-x | spec/unit/parser/ast/resource_override.rb | 14 | ||||
-rwxr-xr-x | spec/unit/parser/ast/resource_reference.rb | 10 | ||||
-rwxr-xr-x | spec/unit/parser/parser.rb | 64 |
6 files changed, 74 insertions, 74 deletions
diff --git a/spec/unit/parser/ast/arithmetic_operator.rb b/spec/unit/parser/ast/arithmetic_operator.rb index 24d6ad47d..ce6d42faf 100755 --- a/spec/unit/parser/ast/arithmetic_operator.rb +++ b/spec/unit/parser/ast/arithmetic_operator.rb @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::ArithmeticOperator do - AST = Puppet::Parser::AST + ast = Puppet::Parser::AST before :each do @scope = Puppet::Parser::Scope.new() @@ -18,19 +18,19 @@ describe Puppet::Parser::AST::ArithmeticOperator do rval = stub "rval" rval.expects(:safeevaluate).with(@scope).returns(2) - operator = AST::ArithmeticOperator.new :rval => rval, :operator => "+", :lval => lval + operator = ast::ArithmeticOperator.new :rval => rval, :operator => "+", :lval => lval operator.evaluate(@scope) end it "should fail for an unknown operator" do - lambda { operator = AST::ArithmeticOperator.new :lval => @one, :operator => "%", :rval => @two }.should raise_error + lambda { operator = ast::ArithmeticOperator.new :lval => @one, :operator => "%", :rval => @two }.should raise_error end it "should call Puppet::Parser::Scope.number?" do Puppet::Parser::Scope.expects(:number?).with(1).returns(1) Puppet::Parser::Scope.expects(:number?).with(2).returns(2) - AST::ArithmeticOperator.new(:lval => @one, :operator => "+", :rval => @two).evaluate(@scope) + ast::ArithmeticOperator.new(:lval => @one, :operator => "+", :rval => @two).evaluate(@scope) end @@ -38,7 +38,7 @@ describe Puppet::Parser::AST::ArithmeticOperator do it "should call ruby Numeric '#{op}'" do one = stub 'one' two = stub 'two' - operator = AST::ArithmeticOperator.new :lval => @one, :operator => op, :rval => @two + operator = ast::ArithmeticOperator.new :lval => @one, :operator => op, :rval => @two Puppet::Parser::Scope.stubs(:number?).with(1).returns(one) Puppet::Parser::Scope.stubs(:number?).with(2).returns(two) one.expects(:send).with(op,two) @@ -49,24 +49,24 @@ describe Puppet::Parser::AST::ArithmeticOperator do it "should work even with numbers embedded in strings" do two = stub 'two', :safeevaluate => "2" one = stub 'one', :safeevaluate => "1" - operator = AST::ArithmeticOperator.new :lval => two, :operator => "+", :rval => one + operator = ast::ArithmeticOperator.new :lval => two, :operator => "+", :rval => one operator.evaluate(@scope).should == 3 end it "should work even with floats" do two = stub 'two', :safeevaluate => 2.53 one = stub 'one', :safeevaluate => 1.80 - operator = AST::ArithmeticOperator.new :lval => two, :operator => "+", :rval => one + operator = ast::ArithmeticOperator.new :lval => two, :operator => "+", :rval => one operator.evaluate(@scope).should == 4.33 end it "should work for variables too" do @scope.expects(:lookupvar).with("one").returns(1) @scope.expects(:lookupvar).with("two").returns(2) - one = AST::Variable.new( :value => "one" ) - two = AST::Variable.new( :value => "two" ) + one = ast::Variable.new( :value => "one" ) + two = ast::Variable.new( :value => "two" ) - operator = AST::ArithmeticOperator.new :lval => one, :operator => "+", :rval => two + operator = ast::ArithmeticOperator.new :lval => one, :operator => "+", :rval => two operator.evaluate(@scope).should == 3 end diff --git a/spec/unit/parser/ast/boolean_operator.rb b/spec/unit/parser/ast/boolean_operator.rb index 7304e2a10..98e173bf0 100755 --- a/spec/unit/parser/ast/boolean_operator.rb +++ b/spec/unit/parser/ast/boolean_operator.rb @@ -4,12 +4,12 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::BooleanOperator do - AST = Puppet::Parser::AST + ast = Puppet::Parser::AST before :each do @scope = Puppet::Parser::Scope.new() - @true_ast = AST::Boolean.new( :value => true) - @false_ast = AST::Boolean.new( :value => false) + @true_ast = ast::Boolean.new( :value => true) + @false_ast = ast::Boolean.new( :value => false) end it "should evaluate left operand inconditionally" do @@ -18,7 +18,7 @@ describe Puppet::Parser::AST::BooleanOperator do rval = stub "rval", :safeevaluate => false rval.expects(:safeevaluate).never - operator = AST::BooleanOperator.new :rval => rval, :operator => "or", :lval => lval + operator = ast::BooleanOperator.new :rval => rval, :operator => "or", :lval => lval operator.evaluate(@scope) end @@ -26,7 +26,7 @@ describe Puppet::Parser::AST::BooleanOperator do lval = stub "lval", :safeevaluate => true rval = stub "rval", :safeevaluate => false rval.expects(:safeevaluate).with(@scope).returns(false) - operator = AST::BooleanOperator.new :rval => rval, :operator => "and", :lval => lval + operator = ast::BooleanOperator.new :rval => rval, :operator => "and", :lval => lval operator.evaluate(@scope) end @@ -34,20 +34,20 @@ describe Puppet::Parser::AST::BooleanOperator do lval = stub "lval", :safeevaluate => false rval = stub "rval", :safeevaluate => false rval.expects(:safeevaluate).with(@scope).returns(false) - operator = AST::BooleanOperator.new :rval => rval, :operator => "or", :lval => lval + operator = ast::BooleanOperator.new :rval => rval, :operator => "or", :lval => lval operator.evaluate(@scope) end it "should return true for false OR true" do - AST::BooleanOperator.new(:rval => @true_ast, :operator => "or", :lval => @false_ast).evaluate(@scope).should be_true + ast::BooleanOperator.new(:rval => @true_ast, :operator => "or", :lval => @false_ast).evaluate(@scope).should be_true end it "should return false for true AND false" do - AST::BooleanOperator.new(:rval => @true_ast, :operator => "and", :lval => @false_ast ).evaluate(@scope).should be_false + ast::BooleanOperator.new(:rval => @true_ast, :operator => "and", :lval => @false_ast ).evaluate(@scope).should be_false end it "should return true for true AND true" do - AST::BooleanOperator.new(:rval => @true_ast, :operator => "and", :lval => @true_ast ).evaluate(@scope).should be_true + ast::BooleanOperator.new(:rval => @true_ast, :operator => "and", :lval => @true_ast ).evaluate(@scope).should be_true end end diff --git a/spec/unit/parser/ast/collexpr.rb b/spec/unit/parser/ast/collexpr.rb index e5e6e0d7a..5f0ca941e 100755 --- a/spec/unit/parser/ast/collexpr.rb +++ b/spec/unit/parser/ast/collexpr.rb @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::CollExpr do - AST = Puppet::Parser::AST + ast = Puppet::Parser::AST before :each do @scope = Puppet::Parser::Scope.new() @@ -19,12 +19,12 @@ describe Puppet::Parser::AST::CollExpr do end it "should evaluate both" do - collexpr = AST::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=>"==") + collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=>"==") collexpr.evaluate(@scope) end it "should produce a textual representation and code of the expression" do - collexpr = AST::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=>"==") + collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=>"==") result = collexpr.evaluate(@scope) result[0].should == "param_values.value = 'test2' and param_names.name = 'test1'" result[1].should be_an_instance_of(Proc) @@ -39,7 +39,7 @@ describe Puppet::Parser::AST::CollExpr do t.expects(:form=) end - collexpr = AST::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=>"==", :form => true, :type => true) + collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=>"==", :form => true, :type => true) result = collexpr.evaluate(@scope) end @@ -50,25 +50,25 @@ describe Puppet::Parser::AST::CollExpr do end it "should evaluate like the original expression for ==" do - collexpr = AST::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper => "==") + collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper => "==") collexpr.evaluate(@scope)[1].call(@resource).should === (@resource["test1"] == "test2") end it "should evaluate like the original expression for !=" do - collexpr = AST::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper => "!=") + collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper => "!=") collexpr.evaluate(@scope)[1].call(@resource).should === (@resource["test1"] != "test2") end end it "should warn if this is an exported collection containing parenthesis (unsupported)" do - collexpr = AST::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=>"==", :parens => true, :form => :exported) + collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=>"==", :parens => true, :form => :exported) Puppet.expects(:warning) collexpr.evaluate(@scope) end %w{and or}.each do |op| it "should raise an error if this is an exported collection with #{op} operator (unsupported)" do - collexpr = AST::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=> op, :form => :exported) + collexpr = ast::CollExpr.new(:test1 => @test1, :test2 => @test2, :oper=> op, :form => :exported) lambda { collexpr.evaluate(@scope) }.should raise_error(Puppet::ParseError) end end @@ -81,12 +81,12 @@ describe Puppet::Parser::AST::CollExpr do resource = mock 'resource' resource.expects(:[]).with("array").at_least(1).returns(["test1","test2","test3"]) - collexpr = AST::CollExpr.new(:test1 => array, :test2 => test1, :oper => "==") + collexpr = ast::CollExpr.new(:test1 => array, :test2 => test1, :oper => "==") collexpr.evaluate(@scope)[1].call(resource).should be_true end it "should raise an error for invalid operator" do - lambda { collexpr = AST::CollExpr.new(:oper=>">") }.should raise_error + lambda { collexpr = ast::CollExpr.new(:oper=>">") }.should raise_error end -end
\ No newline at end of file +end diff --git a/spec/unit/parser/ast/resource_override.rb b/spec/unit/parser/ast/resource_override.rb index 3fbeb323c..c1520bf78 100755 --- a/spec/unit/parser/ast/resource_override.rb +++ b/spec/unit/parser/ast/resource_override.rb @@ -4,12 +4,12 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::ResourceOverride do - AST = Puppet::Parser::AST + ast = Puppet::Parser::AST before :each do @compiler = stub 'compiler' @scope = Puppet::Parser::Scope.new(:compiler => @compiler) - @params = AST::ASTArray.new({}) + @params = ast::ASTArray.new({}) @compiler.stubs(:add_override) end @@ -17,7 +17,7 @@ describe Puppet::Parser::AST::ResourceOverride do klass = stub 'klass', :title => "title", :type => "type" object = mock 'object' object.expects(:safeevaluate).with(@scope).returns(klass) - AST::ResourceOverride.new(:object => object, :params => @params ).evaluate(@scope) + ast::ResourceOverride.new(:object => object, :params => @params ).evaluate(@scope) end it "should tell the compiler to override the resource with our own" do @@ -25,13 +25,13 @@ describe Puppet::Parser::AST::ResourceOverride do klass = stub 'klass', :title => "title", :type => "one" object = mock 'object', :safeevaluate => klass - AST::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope) + ast::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope) end it "should return the overriden resource directly when called with one item" do klass = stub 'klass', :title => "title", :type => "one" object = mock 'object', :safeevaluate => klass - override = AST::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope) + override = ast::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope) override.should be_an_instance_of(Puppet::Parser::Resource) override.title.should == "title" override.type.should == "One" @@ -43,9 +43,9 @@ describe Puppet::Parser::AST::ResourceOverride do object = mock 'object', :safeevaluate => [klass1,klass2] - override = AST::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope) + override = ast::ResourceOverride.new(:object => object , :params => @params).evaluate(@scope) override.should have(2).elements override.each {|o| o.should be_an_instance_of(Puppet::Parser::Resource) } end -end
\ No newline at end of file +end diff --git a/spec/unit/parser/ast/resource_reference.rb b/spec/unit/parser/ast/resource_reference.rb index e4b7c763b..ce2915a97 100755 --- a/spec/unit/parser/ast/resource_reference.rb +++ b/spec/unit/parser/ast/resource_reference.rb @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper' describe Puppet::Parser::AST::ResourceReference do - AST = Puppet::Parser::AST + ast = Puppet::Parser::AST before :each do @scope = Puppet::Parser::Scope.new() @@ -12,7 +12,7 @@ describe Puppet::Parser::AST::ResourceReference do def newref(title, type) title = stub 'title', :safeevaluate => title - ref = AST::ResourceReference.new(:type => type, :title => title) + ref = Puppet::Parser::AST::ResourceReference.new(:type => type, :title => title) end it "should evaluate correctly reference to builtin types" do @@ -45,7 +45,7 @@ describe Puppet::Parser::AST::ResourceReference do it "should return an array of reference if given an array of titles" do titles = mock 'titles', :safeevaluate => ["title1","title2"] - ref = AST::ResourceReference.new( :title => titles, :type => "Resource" ) + ref = ast::ResourceReference.new( :title => titles, :type => "Resource" ) ref.stubs(:qualified_type).with(@scope).returns("Resource") ref.evaluate(@scope).should have(2).elements @@ -53,11 +53,11 @@ describe Puppet::Parser::AST::ResourceReference do it "should qualify class of all titles for Class resource references" do titles = mock 'titles', :safeevaluate => ["title1","title2"] - ref = AST::ResourceReference.new( :title => titles, :type => "Class" ) + ref = ast::ResourceReference.new( :title => titles, :type => "Class" ) ref.expects(:qualified_class).with(@scope,"title1").returns("class") ref.expects(:qualified_class).with(@scope,"title2").returns("class") ref.evaluate(@scope) end -end
\ No newline at end of file +end diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb index 2a086ad86..b764dee97 100755 --- a/spec/unit/parser/parser.rb +++ b/spec/unit/parser/parser.rb @@ -4,11 +4,11 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Parser do - AST = Puppet::Parser::AST + ast = Puppet::Parser::AST before :each do @parser = Puppet::Parser::Parser.new :environment => "development" - @true_ast = AST::Boolean.new :value => true + @true_ast = Puppet::Parser::AST::Boolean.new :value => true end describe "when parsing append operator" do @@ -21,13 +21,13 @@ describe Puppet::Parser do lambda { @parser.parse("$var += ") }.should raise_error end - it "should call AST::VarDef with append=true" do - AST::VarDef.expects(:new).with { |h| h[:append] == true } + it "should call ast::VarDef with append=true" do + ast::VarDef.expects(:new).with { |h| h[:append] == true } @parser.parse("$var += 2") end it "should work with arrays too" do - AST::VarDef.expects(:new).with { |h| h[:append] == true } + ast::VarDef.expects(:new).with { |h| h[:append] == true } @parser.parse("$var += ['test']") end @@ -35,21 +35,21 @@ describe Puppet::Parser do describe Puppet::Parser, "when parsing 'if'" do it "not, it should create the correct ast objects" do - AST::Not.expects(:new).with { |h| h[:value].is_a?(AST::Boolean) } + ast::Not.expects(:new).with { |h| h[:value].is_a?(ast::Boolean) } @parser.parse("if ! true { $var = 1 }") end it "boolean operation, it should create the correct ast objects" do - AST::BooleanOperator.expects(:new).with { - |h| h[:rval].is_a?(AST::Boolean) and h[:lval].is_a?(AST::Boolean) and h[:operator]=="or" + ast::BooleanOperator.expects(:new).with { + |h| h[:rval].is_a?(ast::Boolean) and h[:lval].is_a?(ast::Boolean) and h[:operator]=="or" } @parser.parse("if true or true { $var = 1 }") 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]=="<" + 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 }") @@ -59,15 +59,15 @@ describe Puppet::Parser do describe Puppet::Parser, "when parsing if complex expressions" do it "should create a correct ast tree" do - ast = 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(ast) - AST::ComparisonOperator.expects(:new).with { - |h| h[:rval].is_a?(AST::Name) and h[:lval].is_a?(AST::Name) and h[:operator]=="==" - }.returns(ast) - AST::BooleanOperator.expects(:new).with { - |h| h[:rval]==ast and h[:lval]==ast and h[:operator]=="and" + 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 @@ -88,10 +88,10 @@ describe Puppet::Parser do lambda { @parser.parse('exec { test: param => File["a","b"] }') }.should_not raise_error end - it "should create an AST::ResourceReference" do - AST::Resource.stubs(:new) - AST::ResourceReference.expects(:new).with { |arg| - arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(AST::ASTArray) + it "should create an ast::ResourceReference" do + ast::Resource.stubs(:new) + ast::ResourceReference.expects(:new).with { |arg| + arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(ast::ASTArray) } @parser.parse('exec { test: command => File["a","b"] }') end @@ -107,9 +107,9 @@ describe Puppet::Parser do lambda { @parser.parse('Resource["title1","title2"] { param => value }') }.should_not raise_error end - it "should create an AST::ResourceOverride" do - AST::ResourceOverride.expects(:new).with { |arg| - arg[:line]==1 and arg[:object].is_a?(AST::ResourceReference) and arg[:params].is_a?(AST::ResourceParam) + it "should create an ast::ResourceOverride" do + ast::ResourceOverride.expects(:new).with { |arg| + arg[:line]==1 and arg[:object].is_a?(ast::ResourceReference) and arg[:params].is_a?(ast::ResourceParam) } @parser.parse('Resource["title1","title2"] { param => value }') end @@ -131,12 +131,12 @@ describe Puppet::Parser do end it "should create a nop node for empty branch" do - AST::Nop.expects(:new) + ast::Nop.expects(:new) @parser.parse("if true { }") end it "should create a nop node for empty else branch" do - AST::Nop.expects(:new) + ast::Nop.expects(:new) @parser.parse("if true { notice('test') } else { }") end @@ -177,12 +177,12 @@ describe Puppet::Parser do before :each do @one = stub 'one', :is_a? => true - @one.stubs(:is_a?).with(AST::ASTArray).returns(false) - @one.stubs(:is_a?).with(AST).returns(true) + @one.stubs(:is_a?).with(ast::ASTArray).returns(false) + @one.stubs(:is_a?).with(ast).returns(true) @two = stub 'two' - @two.stubs(:is_a?).with(AST::ASTArray).returns(false) - @two.stubs(:is_a?).with(AST).returns(true) + @two.stubs(:is_a?).with(ast::ASTArray).returns(false) + @two.stubs(:is_a?).with(ast).returns(true) end it "should return the first class" do |