From 6750aeb90a4d19a2cd1de3ff007f216d31c4e65d Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 1 Sep 2009 00:12:07 -0700 Subject: Fixing #2563 - multiple regex nodes now work together The problem was that we were needing to convert one of the regexes to a string, which wasn't working well. This adds specific rules for how regexes vs. strings get compared. Signed-off-by: Luke Kanies --- spec/unit/parser/ast/leaf.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/ast/leaf.rb b/spec/unit/parser/ast/leaf.rb index c9593b967..6215f6345 100755 --- a/spec/unit/parser/ast/leaf.rb +++ b/spec/unit/parser/ast/leaf.rb @@ -200,6 +200,11 @@ describe Puppet::Parser::AST::HostName do host.to_classname.should == "this-isnotaclassname" end + it "should delegate 'match' to the underlying value if it is an HostName" do + @value.expects(:match).with("value") + @host.match("value") + end + it "should delegate eql? to the underlying value if it is an HostName" do @value.expects(:eql?).with("value") @host.eql?("value") @@ -220,4 +225,37 @@ describe Puppet::Parser::AST::HostName do @value.expects(:is_a?).with(Puppet::Parser::AST::Regex).returns(true) @host.regex?.should be_true end + + it "should return the results of comparing the regexes if asked whether a regex matches another regex" do + hosts = [1,2].collect do |num| + vreg = /vreg#{num}/ + value = Puppet::Parser::AST::Regex.new(:value => vreg) + Puppet::Parser::AST::HostName.new(:value => value) + end + + hosts[0].match(hosts[1]).should be_false + hosts[0].match(hosts[0]).should be_true + end + + it "should return false when comparing a non-regex to a regex" do + vreg = /vreg/ + value = Puppet::Parser::AST::Regex.new(:value => vreg) + regex = Puppet::Parser::AST::HostName.new(:value => value) + + value = Puppet::Parser::AST::Regex.new(:value => "foo") + normal = Puppet::Parser::AST::HostName.new(:value => value) + + normal.match(regex).should be_false + end + + it "should true when a provided string matches a regex" do + vreg = /r/ + value = Puppet::Parser::AST::Regex.new(:value => vreg) + regex = Puppet::Parser::AST::HostName.new(:value => value) + + value = Puppet::Parser::AST::Leaf.new(:value => "bar") + normal = Puppet::Parser::AST::HostName.new(:value => value) + + regex.match(normal).should be_true + end end -- cgit