Sha256: 1879987547618416c1adf8c3d9ea5356775fa087abca402d0e58c9b47ad51936

Contents?: true

Size: 1.68 KB

Versions: 92

Compression:

Stored size: 1.68 KB

Contents

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

describe Puppet::Parser::AST::MatchOperator do
  before :each do
    node     = Puppet::Node.new('localhost')
    compiler = Puppet::Parser::Compiler.new(node)
    @scope   = Puppet::Parser::Scope.new(compiler)

    @lval = stub 'lval'
    @lval.stubs(:safeevaluate).with(@scope).returns("this is a string")

    @rval = stub 'rval'
    @rval.stubs(:evaluate_match)

    @operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => "=~"
  end

  it "should evaluate the left operand" do
    @lval.expects(:safeevaluate).with(@scope)

    @operator.evaluate(@scope)
  end

  it "should fail for an unknown operator" do
    lambda { operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :operator => "unknown", :rval => @rval }.should raise_error
  end

  it "should evaluate_match the left operand" do
    @rval.expects(:evaluate_match).with("this is a string", @scope).returns(:match)

    @operator.evaluate(@scope)
  end

  { "=~" => true, "!~" => false }.each do |op, res|
    it "should return #{res} if the regexp matches with #{op}" do
      match = stub 'match'
      @rval.stubs(:evaluate_match).with("this is a string", @scope).returns(match)

      operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => op
      operator.evaluate(@scope).should == res
    end

    it "should return #{!res} if the regexp doesn't match" do
      @rval.stubs(:evaluate_match).with("this is a string", @scope).returns(nil)

      operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => op
      operator.evaluate(@scope).should == !res
    end
  end
end

Version data entries

92 entries across 92 versions & 2 rubygems

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