Sha256: 0f51e1175b649562302b2961854d0c4cca9be3140822926bf01e6a3896557d13

Contents?: true

Size: 1.94 KB

Versions: 92

Compression:

Stored size: 1.94 KB

Contents

#! /usr/bin/env ruby
require 'spec_helper'

describe Puppet::Parser::AST::BooleanOperator do

  ast = Puppet::Parser::AST

  before :each do
    node     = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    @scope   = Puppet::Parser::Scope.new(compiler)
    @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

92 entries across 92 versions & 2 rubygems

Version Path
puppet-3.8.7 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.7-x86-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.7-x64-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.6 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.6-x86-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.6-x64-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.5 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.5-x86-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.5-x64-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.4 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.4-x86-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.4-x64-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.3 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.3-x86-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.3-x64-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.2 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.2-x86-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.2-x64-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.1 spec/unit/parser/ast/boolean_operator_spec.rb
puppet-3.8.1-x86-mingw32 spec/unit/parser/ast/boolean_operator_spec.rb