+1

On Oct 28, 2008, at 8:13 AM, Brice Figureau wrote:

>
> This fixes bug #1682 and its duplicate #1691.
> The thing is that evaluating an AST node can produce array, if you are
> evaluating for instance array resource references (ie ala File[a,b]).
> This all comes from the fact that ASTArray containing ASTArray  
> evaluates to
> arrays of arrays.
>
> I also added rspec coverage of ASTArray, in the same changeset.
>
> And I also mistakenly moved #1682 status to "Ready for Checkin"  
> instead
> of "Ready for Testing". Unfortunately, it doesn't seem possible to  
> move back
> to "Ready for Testing". If somebody with supernatural powers could  
> reset the
> bug status for me, that'd be great.
>
> Original commit msg:
> If the ASTArray contains children that evaluate to arrays themselves,
> they aren't flattened.
>
> Signed-off-by: Brice Figureau <[EMAIL PROTECTED]>
> ---
> lib/puppet/parser/ast/astarray.rb |    3 +-
> spec/unit/parser/ast/astarray.rb  |   66 ++++++++++++++++++++++++++++ 
> +++++++++
> 2 files changed, 67 insertions(+), 2 deletions(-)
> create mode 100755 spec/unit/parser/ast/astarray.rb
>
> diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ 
> ast/astarray.rb
> index 8f09aa9..0fccbca 100644
> --- a/lib/puppet/parser/ast/astarray.rb
> +++ b/lib/puppet/parser/ast/astarray.rb
> @@ -30,10 +30,9 @@ class Puppet::Parser::AST
>                     items << child
>                 end
>             }
> -
>             rets = items.flatten.collect { |child|
>                 child.safeevaluate(scope)
> -            }
> +            }.flatten
>             return rets.reject { |o| o.nil? }
>         end
>
> diff --git a/spec/unit/parser/ast/astarray.rb b/spec/unit/parser/ast/ 
> astarray.rb
> new file mode 100755
> index 0000000..f1c28ce
> --- /dev/null
> +++ b/spec/unit/parser/ast/astarray.rb
> @@ -0,0 +1,66 @@
> +#!/usr/bin/env ruby
> +
> +require File.dirname(__FILE__) + '/../../../spec_helper'
> +
> +describe Puppet::Parser::AST::ASTArray do
> +    before :each do
> +        @scope = Puppet::Parser::Scope.new()
> +    end
> +
> +    it "should have a [] accessor" do
> +        array = Puppet::Parser::AST::ASTArray.new :children => []
> +        array.should respond_to(:[])
> +    end
> +
> +    it "should evaluate all its children" do
> +        item1 = stub "item1", :is_a? => true
> +        item2 = stub "item2", :is_a? => true
> +
> +        item1.expects(:safeevaluate).with(@scope).returns(123)
> +        item2.expects(:safeevaluate).with(@scope).returns(246)
> +
> +        operator = Puppet::Parser::AST::ASTArray.new :children =>  
> [item1,item2]
> +        operator.evaluate(@scope)
> +    end
> +
> +    it "should evaluate childrens of type ASTArray" do
> +        item1 = stub "item1", :is_a? => true
> +        item2 = stub "item2"
> +        item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
> +         
> item2 
> .stubs 
> (:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true)
> +        item2.stubs(:each).yields(item1)
> +
> +        item1.expects(:safeevaluate).with(@scope).returns(123)
> +
> +        operator = Puppet::Parser::AST::ASTArray.new :children =>  
> [item2]
> +        operator.evaluate(@scope).should == [123]
> +    end
> +
> +    it "should flatten children coming from children ASTArray" do
> +        item1 = stub "item1", :is_a? => true
> +        item2 = stub "item2"
> +        item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
> +         
> item2 
> .stubs 
> (:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true)
> +        item2.stubs(:each).yields([item1])
> +
> +        item1.expects(:safeevaluate).with(@scope).returns(123)
> +
> +        operator = Puppet::Parser::AST::ASTArray.new :children =>  
> [item2]
> +        operator.evaluate(@scope).should == [123]
> +    end
> +
> +    it "should flatten the results of children evaluation" do
> +        item1 = stub "item1", :is_a? => true
> +        item2 = stub "item2"
> +        item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
> +         
> item2 
> .stubs 
> (:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true)
> +        item2.stubs(:each).yields([item1])
> +
> +        item1.expects(:safeevaluate).with(@scope).returns([123])
> +
> +        operator = Puppet::Parser::AST::ASTArray.new :children =>  
> [item2]
> +        operator.evaluate(@scope).should == [123]
> +    end
> +
> +
> +end
> -- 
> 1.5.6.5
>
>
> >


-- 
What happens to the hole when the cheese is gone? -- Bertolt Brecht
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to