diff options
author | Luke Kanies <luke@madstop.com> | 2009-09-01 00:12:07 -0700 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2009-09-01 00:12:07 -0700 |
commit | 6750aeb90a4d19a2cd1de3ff007f216d31c4e65d (patch) | |
tree | b2afd8bf2bf30f7ec3c084f995c7b2df6eebc0fa | |
parent | b728b931e5914cfeaf3d072fb77870e9a8ecf6cd (diff) | |
download | puppet-6750aeb90a4d19a2cd1de3ff007f216d31c4e65d.tar.gz puppet-6750aeb90a4d19a2cd1de3ff007f216d31c4e65d.tar.xz puppet-6750aeb90a4d19a2cd1de3ff007f216d31c4e65d.zip |
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 <luke@madstop.com>
-rw-r--r-- | lib/puppet/parser/ast/leaf.rb | 14 | ||||
-rwxr-xr-x | spec/unit/parser/ast/leaf.rb | 38 |
2 files changed, 50 insertions, 2 deletions
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index 1c1eae972..d10ea62f4 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -119,8 +119,18 @@ class Puppet::Parser::AST end def match(value) - value = value.value if value.is_a?(HostName) - return @value.match(value) + return @value.match(value) unless value.is_a?(HostName) + + if value.regex? and self.regex? + # Wow this is some sweet design; maybe a touch of refactoring + # in order here. + return value.value.value == self.value.value + elsif value.regex? # we know if the existing name is not a regex, it won't match a regex + return false + else + # else, we could be either a regex or normal and it doesn't matter + return @value.match(value.value) + end end def regex? 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 |