diff --git a/spec/unit/parser/ast/astarray_spec.rb b/spec/unit/parser/ast/astarray_spec.rb index 901c71081..a1b6bb1d7 100755 --- a/spec/unit/parser/ast/astarray_spec.rb +++ b/spec/unit/parser/ast/astarray_spec.rb @@ -1,56 +1,56 @@ #! /usr/bin/env ruby require 'spec_helper' describe 'Puppet::Parser::AST::ASTArray' do -# before :each do -# node = Puppet::Node.new('localhost') -# compiler = Puppet::Parser::Compiler.new(node) -# @scope = Puppet::Parser::Scope.new(compiler) -# 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 not flatten children coming from children ASTArray" do -# item = Puppet::Parser::AST::String.new :value => 'foo' -# inner_array = Puppet::Parser::AST::ASTArray.new :children => [item, item] -# operator = Puppet::Parser::AST::ASTArray.new :children => [inner_array, inner_array] -# operator.evaluate(@scope).should == [['foo', 'foo'], ['foo', 'foo']] -# end -# -# it "should not flatten the results of children evaluation" do -# item = Puppet::Parser::AST::String.new :value => 'foo' -# item.stubs(:evaluate).returns(['foo']) -# operator = Puppet::Parser::AST::ASTArray.new :children => [item, item] -# operator.evaluate(@scope).should == [['foo'], ['foo']] -# end -# -# it "should discard nil results from children evaluation" do -# item1 = Puppet::Parser::AST::String.new :value => 'foo' -# item2 = Puppet::Parser::AST::String.new :value => 'foo' -# item2.stubs(:evaluate).returns(nil) -# operator = Puppet::Parser::AST::ASTArray.new :children => [item1, item2] -# operator.evaluate(@scope).should == ['foo'] -# end -# -# it "should return a valid string with to_s" do -# a = stub 'a', :is_a? => true, :to_s => "a" -# b = stub 'b', :is_a? => true, :to_s => "b" -# array = Puppet::Parser::AST::ASTArray.new :children => [a,b] -# -# array.to_s.should == "[a, b]" -# end + before :each do + node = Puppet::Node.new('localhost') + compiler = Puppet::Parser::Compiler.new(node) + @scope = Puppet::Parser::Scope.new(compiler) + 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 not flatten children coming from children ASTArray" do + item = Puppet::Parser::AST::String.new :value => 'foo' + inner_array = Puppet::Parser::AST::ASTArray.new :children => [item, item] + operator = Puppet::Parser::AST::ASTArray.new :children => [inner_array, inner_array] + operator.evaluate(@scope).should == [['foo', 'foo'], ['foo', 'foo']] + end + + it "should not flatten the results of children evaluation" do + item = Puppet::Parser::AST::String.new :value => 'foo' + item.stubs(:evaluate).returns(['foo']) + operator = Puppet::Parser::AST::ASTArray.new :children => [item, item] + operator.evaluate(@scope).should == [['foo'], ['foo']] + end + + it "should discard nil results from children evaluation" do + item1 = Puppet::Parser::AST::String.new :value => 'foo' + item2 = Puppet::Parser::AST::String.new :value => 'foo' + item2.stubs(:evaluate).returns(nil) + operator = Puppet::Parser::AST::ASTArray.new :children => [item1, item2] + operator.evaluate(@scope).should == ['foo'] + end + + it "should return a valid string with to_s" do + a = stub 'a', :is_a? => true, :to_s => "a" + b = stub 'b', :is_a? => true, :to_s => "b" + array = Puppet::Parser::AST::ASTArray.new :children => [a,b] + + array.to_s.should == "[a, b]" + end end diff --git a/spec/unit/parser/ast/asthash_spec.rb b/spec/unit/parser/ast/asthash_spec.rb deleted file mode 100755 index 14fc823a8..000000000 --- a/spec/unit/parser/ast/asthash_spec.rb +++ /dev/null @@ -1,98 +0,0 @@ -#! /usr/bin/env ruby -require 'spec_helper' - -describe 'Puppet::Parser::AST::ASTHash' do -# before :each do -# node = Puppet::Node.new('localhost') -# compiler = Puppet::Parser::Compiler.new(node) -# @scope = Puppet::Parser::Scope.new(compiler) -# end -# -# it "should have a merge functionality" do -# hash = Puppet::Parser::AST::ASTHash.new(:value => {}) -# hash.should respond_to(:merge) -# end -# -# it "should be able to merge 2 AST hashes" do -# hash = Puppet::Parser::AST::ASTHash.new(:value => { "a" => "b" }) -# -# hash.merge(Puppet::Parser::AST::ASTHash.new(:value => {"c" => "d"})) -# -# hash.value.should == { "a" => "b", "c" => "d" } -# end -# -# it "should be able to merge with a ruby Hash" do -# hash = Puppet::Parser::AST::ASTHash.new(:value => { "a" => "b" }) -# -# hash.merge({"c" => "d"}) -# -# hash.value.should == { "a" => "b", "c" => "d" } -# end -# -# it "should evaluate each hash value" do -# key1 = stub "key1" -# value1 = stub "value1" -# key2 = stub "key2" -# value2 = stub "value2" -# -# value1.expects(:safeevaluate).with(@scope).returns("b") -# value2.expects(:safeevaluate).with(@scope).returns("d") -# -# operator = Puppet::Parser::AST::ASTHash.new(:value => { key1 => value1, key2 => value2}) -# operator.evaluate(@scope) -# end -# -# it "should evaluate the hash keys if they are AST instances" do -# key1 = stub "key1" -# value1 = stub "value1", :safeevaluate => "one" -# key2 = stub "key2" -# value2 = stub "value2", :safeevaluate => "two" -# -# key1.expects(:safeevaluate).with(@scope).returns("1") -# key2.expects(:safeevaluate).with(@scope).returns("2") -# -# operator = Puppet::Parser::AST::ASTHash.new(:value => { key1 => value1, key2 => value2}) -# hash = operator.evaluate(@scope) -# hash["1"].should == "one" -# hash["2"].should == "two" -# end -# -# it "should evaluate the hash keys if they are not AST instances" do -# key1 = "1" -# value1 = stub "value1", :safeevaluate => "one" -# key2 = "2" -# value2 = stub "value2", :safeevaluate => "two" -# -# operator = Puppet::Parser::AST::ASTHash.new(:value => { key1 => value1, key2 => value2}) -# hash = operator.evaluate(@scope) -# hash["1"].should == "one" -# hash["2"].should == "two" -# end -# -# it "should return an evaluated hash" do -# key1 = stub "key1" -# value1 = stub "value1", :safeevaluate => "b" -# key2 = stub "key2" -# value2 = stub "value2", :safeevaluate => "d" -# -# operator = Puppet::Parser::AST::ASTHash.new(:value => { key1 => value1, key2 => value2}) -# operator.evaluate(@scope).should == { key1 => "b", key2 => "d" } -# end -# -# describe "when being initialized without arguments" do -# it "should evaluate to an empty hash" do -# hash = Puppet::Parser::AST::ASTHash.new({}) -# hash.evaluate(@scope).should == {} -# end -# -# it "should support merging" do -# hash = Puppet::Parser::AST::ASTHash.new({}) -# hash.merge({"a" => "b"}).should == {"a" => "b"} -# end -# end -# -# it "should return a valid string with to_s" do -# hash = Puppet::Parser::AST::ASTHash.new(:value => { "a" => "b", "c" => "d" }) -# ["{a => b, c => d}", "{c => d, a => b}"].should be_include hash.to_s -# end -end