[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

Luke Kanies luke at puppetlabs.com
Wed Jul 14 10:32:26 UTC 2010


The following commit has been merged in the upstream branch:
commit 0f254bec2937f0b27171dce0352a25fcaddca719
Author: Luke Kanies <luke at puppetlabs.com>
Date:   Mon Apr 12 11:45:46 2010 -0700

    Fixing Hash functionality with non-constant keys
    
    It was only apparently working with constant keys,
    not, say, AST strings.
    
    Signed-off-by: Luke Kanies <luke at puppetlabs.com>

diff --git a/lib/puppet/parser/ast/asthash.rb b/lib/puppet/parser/ast/asthash.rb
index 3e09457..aa5127d 100644
--- a/lib/puppet/parser/ast/asthash.rb
+++ b/lib/puppet/parser/ast/asthash.rb
@@ -9,7 +9,8 @@ class Puppet::Parser::AST
             items = {}
 
             @value.each_pair do |k,v|
-                items.merge!({ k => v.safeevaluate(scope) })
+                key = k.respond_to?(:safeevaluate) ? k.safeevaluate(scope) : k
+                items.merge!({ key => v.safeevaluate(scope) })
             end
 
             return items
diff --git a/spec/unit/parser/ast/asthash.rb b/spec/unit/parser/ast/asthash.rb
index 4c700fe..c6839ab 100644
--- a/spec/unit/parser/ast/asthash.rb
+++ b/spec/unit/parser/ast/asthash.rb
@@ -7,11 +7,6 @@ describe Puppet::Parser::AST::ASTHash do
         @scope = Puppet::Parser::Scope.new()
     end
 
-    it "should have a [] accessor" do
-        hash = Puppet::Parser::AST::ASTHash.new(:value => {})
-        hash.should respond_to(:[])
-    end
-
     it "should have a merge functionality" do
         hash = Puppet::Parser::AST::ASTHash.new(:value => {})
         hash.should respond_to(:merge)
@@ -46,6 +41,33 @@ describe Puppet::Parser::AST::ASTHash do
         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"

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list