summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-09-26 22:56:17 +0200
committerBrice Figureau <brice@daysofwonder.com>2008-09-30 17:08:52 +0200
commit8372dc4ca80d95e62c407708a48e51ac09ad2f55 (patch)
tree843731a1bd6282bf007c4adc7a154560780dafbe /spec/unit/parser
parente6698c2b8624fe2c2bbeef594318e3e8d932d345 (diff)
Add boolean operators to AST
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/ast/boolean_operator.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/unit/parser/ast/boolean_operator.rb b/spec/unit/parser/ast/boolean_operator.rb
new file mode 100755
index 000000000..7304e2a10
--- /dev/null
+++ b/spec/unit/parser/ast/boolean_operator.rb
@@ -0,0 +1,53 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::BooleanOperator do
+
+ AST = Puppet::Parser::AST
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ @true_ast = AST::Boolean.new( :value => true)
+ @false_ast = AST::Boolean.new( :value => false)
+ end
+
+ it "should evaluate left operand inconditionally" do
+ lval = stub "lval"
+ lval.expects(:safeevaluate).with(@scope).returns("true")
+ rval = stub "rval", :safeevaluate => false
+ rval.expects(:safeevaluate).never
+
+ operator = AST::BooleanOperator.new :rval => rval, :operator => "or", :lval => lval
+ operator.evaluate(@scope)
+ end
+
+ it "should evaluate right 'and' operand only if left operand is true" do
+ lval = stub "lval", :safeevaluate => true
+ rval = stub "rval", :safeevaluate => false
+ rval.expects(:safeevaluate).with(@scope).returns(false)
+ operator = AST::BooleanOperator.new :rval => rval, :operator => "and", :lval => lval
+ operator.evaluate(@scope)
+ end
+
+ it "should evaluate right 'or' operand only if left operand is false" do
+ lval = stub "lval", :safeevaluate => false
+ rval = stub "rval", :safeevaluate => false
+ rval.expects(:safeevaluate).with(@scope).returns(false)
+ operator = AST::BooleanOperator.new :rval => rval, :operator => "or", :lval => lval
+ operator.evaluate(@scope)
+ end
+
+ it "should return true for false OR true" do
+ AST::BooleanOperator.new(:rval => @true_ast, :operator => "or", :lval => @false_ast).evaluate(@scope).should be_true
+ end
+
+ it "should return false for true AND false" do
+ AST::BooleanOperator.new(:rval => @true_ast, :operator => "and", :lval => @false_ast ).evaluate(@scope).should be_false
+ end
+
+ it "should return true for true AND true" do
+ AST::BooleanOperator.new(:rval => @true_ast, :operator => "and", :lval => @true_ast ).evaluate(@scope).should be_true
+ end
+
+end