3
require File.dirname(__FILE__) + '/../../../spec_helper'
5
describe Puppet::Parser::AST::MatchOperator do
7
@scope = Puppet::Parser::Scope.new()
10
@lval.stubs(:safeevaluate).with(@scope).returns("this is a string")
13
@rval.stubs(:evaluate_match)
15
@operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => "=~"
18
it "should evaluate the left operand" do
19
@lval.expects(:safeevaluate).with(@scope)
21
@operator.evaluate(@scope)
24
it "should fail for an unknown operator" do
25
lambda { operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :operator => "unknown", :rval => @rval }.should raise_error
28
it "should evaluate_match the left operand" do
29
@rval.expects(:evaluate_match).with("this is a string", @scope).returns(:match)
31
@operator.evaluate(@scope)
34
{ "=~" => true, "!~" => false }.each do |op, res|
35
it "should return #{res} if the regexp matches with #{op}" do
37
@rval.stubs(:evaluate_match).with("this is a string", @scope).returns(match)
39
operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => op
40
operator.evaluate(@scope).should == res
43
it "should return #{!res} if the regexp doesn't match" do
44
@rval.stubs(:evaluate_match).with("this is a string", @scope).returns(nil)
46
operator = Puppet::Parser::AST::MatchOperator.new :lval => @lval, :rval => @rval, :operator => op
47
operator.evaluate(@scope).should == !res