summaryrefslogtreecommitdiff
path: root/spec/unit/parser/ast/leaf_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/parser/ast/leaf_spec.rb')
-rwxr-xr-xspec/unit/parser/ast/leaf_spec.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/spec/unit/parser/ast/leaf_spec.rb b/spec/unit/parser/ast/leaf_spec.rb
index ff3fed5e9..881506ea4 100755
--- a/spec/unit/parser/ast/leaf_spec.rb
+++ b/spec/unit/parser/ast/leaf_spec.rb
@@ -151,6 +151,14 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
lambda { access.evaluate(@scope) }.should raise_error
end
+ it "should be able to return :undef for an unknown array index" do
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns(["val1", "val2", "val3"])
+
+ access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => 6 )
+
+ access.evaluate(@scope).should == :undef
+ end
+
it "should be able to return an hash value" do
@scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key1" => "val1", "key2" => "val2", "key3" => "val3" })
@@ -159,6 +167,14 @@ describe Puppet::Parser::AST::HashOrArrayAccess do
access.evaluate(@scope).should == "val2"
end
+ it "should be able to return :undef for unknown hash keys" do
+ @scope.stubs(:lookupvar).with { |name,options| name == 'a'}.returns({ "key1" => "val1", "key2" => "val2", "key3" => "val3" })
+
+ access = Puppet::Parser::AST::HashOrArrayAccess.new(:variable => "a", :key => "key12" )
+
+ access.evaluate(@scope).should == :undef
+ end
+
it "should be able to return an hash value with a numerical key" do
@scope.stubs(:lookupvar).with { |name,options| name == "a"}.returns({ "key1" => "val1", "key2" => "val2", "45" => "45", "key3" => "val3" })