Sha256: 2f208870947fefbef48fc2c95f66b7dbb2a0764da2b39568e698829a9490141e

Contents?: true

Size: 1.87 KB

Versions: 19

Compression:

Stored size: 1.87 KB

Contents

#!/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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
puppet-2.6.18 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.17 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.16 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.15 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.14 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.13 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.12 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.11 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.10 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.9 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.8 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.7 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.6 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.5 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.4 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.3 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.2 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.1 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-2.6.0 spec/unit/parser/ast/boolean_operator_spec.rb