summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/ast/asthash.rb5
-rw-r--r--spec/unit/parser/ast/asthash.rb12
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/asthash.rb b/lib/puppet/parser/ast/asthash.rb
index aa5127dd9..d04901912 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 c6839ab4d..fc8e1c7ea 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" })