+1

I thought it might be that, but for some reason I didn't think to init it with arguments - I just sat there thinking, "Can you not initialize hashes?".

On Jun 6, 2010, at 6:42 AM, Brice Figureau wrote:

The following manifest was failing:
$data = {}

This patch makes sure we initalize our ast hash with an empty ruby
hash when it is created without any values.

Signed-off-by: Brice Figureau <[email protected]>
---
lib/puppet/parser/ast/asthash.rb |    5 +++++
spec/unit/parser/ast/asthash.rb  |   12 ++++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/lib/puppet/parser/ast/asthash.rb b/lib/puppet/parser/ ast/asthash.rb
index aa5127d..d049019 100644
--- a/lib/puppet/parser/ast/asthash.rb
+++ b/lib/puppet/parser/ast/asthash.rb
@@ -28,5 +28,10 @@ class Puppet::Parser::AST
        def to_s
"{" + @value.collect { |v| v.collect { |a| a.to_s }.join(' => ') }.join(', ') + "}"
        end
+
+        def initialize(args)
+            super(args)
+            @value ||= {}
+        end
    end
end
diff --git a/spec/unit/parser/ast/asthash.rb b/spec/unit/parser/ast/ asthash.rb
index c6839ab..fc8e1c7 100644
--- a/spec/unit/parser/ast/asthash.rb
+++ b/spec/unit/parser/ast/asthash.rb
@@ -78,6 +78,18 @@ describe Puppet::Parser::AST::ASTHash do
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" })

--
1.6.6.1

--
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 .



--
I happen to feel that the degree of a person's intelligence is directly
reflected by the number of conflicting attitudes she can bring to bear
on the same topic. -- Lisa Alther
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199

--
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