summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/parser.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-10-09 15:51:05 +0200
committerLuke Kanies <luke@madstop.com>2008-10-09 15:51:05 +0200
commit9ef6209b3ed1269f7cd1e6a8d0f189f6b5712800 (patch)
tree3c786b42679f3bea18979aceb8e3bf2a5184f366 /spec/unit/parser/parser.rb
parentb96bdc6a63f7be6b724c2aa7ad0ea007cba81718 (diff)
parent0fff7d76e89a650f5d2e78b2c69b30635880c36b (diff)
downloadpuppet-9ef6209b3ed1269f7cd1e6a8d0f189f6b5712800.tar.gz
puppet-9ef6209b3ed1269f7cd1e6a8d0f189f6b5712800.tar.xz
puppet-9ef6209b3ed1269f7cd1e6a8d0f189f6b5712800.zip
Merge branch '0.24.x' of git://github.com/jamtur01/puppet into 0.24.x
Diffstat (limited to 'spec/unit/parser/parser.rb')
-rwxr-xr-xspec/unit/parser/parser.rb113
1 files changed, 112 insertions, 1 deletions
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 94b19be40..c0d22a2cc 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -8,6 +8,7 @@ describe Puppet::Parser do
before :each do
@parser = Puppet::Parser::Parser.new :environment => "development"
+ @true_ast = AST::Boolean.new :value => true
end
describe "when parsing append operator" do
@@ -31,4 +32,114 @@ describe Puppet::Parser do
end
end
-end
+
+ describe Puppet::Parser, "when parsing 'if'" do
+ it "not, it should create the correct ast objects" do
+ AST::Not.expects(:new).with { |h| h[:value].is_a?(AST::Boolean) }
+ @parser.parse("if ! true { $var = 1 }")
+
+ end
+
+ it "boolean operation, it should create the correct ast objects" do
+ AST::BooleanOperator.expects(:new).with {
+ |h| h[:rval].is_a?(AST::Boolean) and h[:lval].is_a?(AST::Boolean) and h[:operator]=="or"
+ }
+ @parser.parse("if true or true { $var = 1 }")
+
+ end
+
+ it "comparison operation, it should create the correct ast objects" do
+ AST::ComparisonOperator.expects(:new).with {
+ |h| h[:lval].is_a?(AST::Name) and h[:rval].is_a?(AST::Name) and h[:operator]=="<"
+ }
+ @parser.parse("if 1 < 2 { $var = 1 }")
+
+ end
+
+ end
+
+ describe Puppet::Parser, "when parsing if complex expressions" do
+ it "should create a correct ast tree" do
+ AST::ComparisonOperator.expects(:new).with {
+ |h| h[:rval].is_a?(AST::Name) and h[:lval].is_a?(AST::Name) and h[:operator]==">"
+ }.returns("whatever")
+ AST::ComparisonOperator.expects(:new).with {
+ |h| h[:rval].is_a?(AST::Name) and h[:lval].is_a?(AST::Name) and h[:operator]=="=="
+ }.returns("whatever")
+ AST::BooleanOperator.expects(:new).with {
+ |h| h[:rval]=="whatever" and h[:lval]=="whatever" and h[:operator]=="and"
+ }
+ @parser.parse("if (1 > 2) and (1 == 2) { $var = 1 }")
+ end
+
+ it "should raise an error on incorrect expression" do
+ lambda { @parser.parse("if (1 > 2 > ) or (1 == 2) { $var = 1 }") }.should raise_error
+ end
+
+ end
+
+ describe Puppet::Parser, "when parsing resource references" do
+
+ it "should not raise syntax errors" do
+ lambda { @parser.parse('exec { test: param => File["a"] }') }.should_not raise_error
+ end
+
+ it "should not raise syntax errors with multiple references" do
+ lambda { @parser.parse('exec { test: param => File["a","b"] }') }.should_not raise_error
+ end
+
+ it "should create an AST::ResourceReference" do
+ AST::Resource.stubs(:new)
+ AST::ResourceReference.expects(:new).with { |arg|
+ arg[:line]==1 and arg[:type]=="File" and arg[:title].is_a?(AST::ASTArray)
+ }
+ @parser.parse('exec { test: command => File["a","b"] }')
+ end
+ end
+
+ describe Puppet::Parser, "when parsing resource overrides" do
+
+ it "should not raise syntax errors" do
+ lambda { @parser.parse('Resource["title"] { param => value }') }.should_not raise_error
+ end
+
+ it "should not raise syntax errors with multiple overrides" do
+ lambda { @parser.parse('Resource["title1","title2"] { param => value }') }.should_not raise_error
+ end
+
+ it "should create an AST::ResourceOverride" do
+ AST::ResourceOverride.expects(:new).with { |arg|
+ arg[:line]==1 and arg[:object].is_a?(AST::ResourceReference) and arg[:params].is_a?(AST::ResourceParam)
+ }
+ @parser.parse('Resource["title1","title2"] { param => value }')
+ end
+
+ 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