summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/ast/astarray.rb
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-10-28 14:12:36 +0100
committerJames Turnbull <james@lovedthanlost.net>2008-10-29 09:53:14 +1100
commitc7ccc4ba7c42d56595564491ae578a1604c628d1 (patch)
treeb624d8acd2ff2e7699b83963832fd27ddac23631 /spec/unit/parser/ast/astarray.rb
parentc906afd9e36017bba339ca50998e1651e54dbd0c (diff)
downloadpuppet-c7ccc4ba7c42d56595564491ae578a1604c628d1.tar.gz
puppet-c7ccc4ba7c42d56595564491ae578a1604c628d1.tar.xz
puppet-c7ccc4ba7c42d56595564491ae578a1604c628d1.zip
Fix #1682 - ASTArray should flatten product of evaluation of its children
If the ASTArray contains children that evaluate to arrays themselves, they aren't flattened.
Diffstat (limited to 'spec/unit/parser/ast/astarray.rb')
-rwxr-xr-xspec/unit/parser/ast/astarray.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/unit/parser/ast/astarray.rb b/spec/unit/parser/ast/astarray.rb
new file mode 100755
index 000000000..f1c28ce47
--- /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