summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-10-04 16:11:03 +0200
committerJames Turnbull <james@lovedthanlost.net>2008-10-07 07:51:44 +1100
commit0c297be5dad784e305ef194cee29b11a92d31b6b (patch)
tree947b3bdb076461f53278be3a1fad39ee4fc5bed6 /spec/unit/parser
parent5268487ac862eec6381d315800d6f56c51dc57b5 (diff)
Fix #1109 - allow empty if or else branches
This changesets allow empty if or else branches: if true { } else { } It works by emitting on the parser stack an AST node that doesn't do anything (a no-op). This allows the less intrusive code as no part of the if evaluation code has been touched.
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/ast/nop.rb20
-rwxr-xr-xspec/unit/parser/parser.rb26
2 files changed, 46 insertions, 0 deletions
diff --git a/spec/unit/parser/ast/nop.rb b/spec/unit/parser/ast/nop.rb
new file mode 100755
index 000000000..5a7132586
--- /dev/null
+++ b/spec/unit/parser/ast/nop.rb
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::Nop do
+
+ before do
+ @scope = mock 'scope'
+ end
+
+ it "should do nothing on evaluation" do
+ Puppet::Parser::AST.expects(:safeevaluate).never
+ Puppet::Parser::AST::Nop.new({}).evaluate(@scope)
+ end
+
+ it "should not return anything" do
+ Puppet::Parser::AST::Nop.new({}).evaluate(@scope).should be_nil
+ end
+
+end
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 0092a9970..c0d22a2cc 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -116,4 +116,30 @@ describe Puppet::Parser do
end
+ describe Puppet::Parser, "when parsing if statements" do
+
+ it "should not raise errors with empty if" do
+ lambda { @parser.parse("if true { }") }.should_not raise_error
+ end
+
+ it "should not raise errors with empty else" do
+ lambda { @parser.parse("if false { notice('if') } else { }") }.should_not raise_error
+ end
+
+ it "should not raise errors with empty if and else" do
+ lambda { @parser.parse("if false { } else { }") }.should_not raise_error
+ end
+
+ it "should create a nop node for empty branch" do
+ AST::Nop.expects(:new)
+ @parser.parse("if true { }")
+ end
+
+ it "should create a nop node for empty else branch" do
+ AST::Nop.expects(:new)
+ @parser.parse("if true { notice('test') } else { }")
+ end
+
+ end
+
end