Preparation for query matching: introduce Regexp + PatternMatch.

This commit is contained in:
Andrey Smirnov
2014-07-10 21:16:30 +04:00
parent f0e69144ed
commit d262a131cc
3 changed files with 22 additions and 0 deletions
+5
View File
@@ -224,6 +224,11 @@ func (p *Package) MatchesDependency(dep Dependency) bool {
return r <= 0
case VersionGreaterOrEqual:
return r >= 0
case VersionPatternMatch:
matched, err := filepath.Match(dep.Version, p.Version)
return err == nil && matched
case VersionRegexp:
panic("regexp matching not implemented yet")
}
panic("unknown relation")
+11
View File
@@ -207,6 +207,17 @@ func (s *PackageSuite) TestMatchesDependency(c *C) {
// <=
c.Check(p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionLessOrEqual, Version: "7.40-2"}), Equals, true)
c.Check(p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionLessOrEqual, Version: "7.40-1"}), Equals, false)
// %
c.Check(p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionPatternMatch, Version: "7.40-*"}), Equals, true)
c.Check(p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionPatternMatch, Version: "7.40-[2]"}), Equals, true)
c.Check(p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionPatternMatch, Version: "7.40-[2"}), Equals, false)
c.Check(p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionPatternMatch, Version: "7.40-[34]"}), Equals, false)
// %
c.Check(func() {
p.MatchesDependency(Dependency{Pkg: "alien-arena-common", Architecture: "i386", Relation: VersionRegexp, Version: "7\\.40-.*"})
}, Panics, "regexp matching not implemented yet")
}
func (s *PackageSuite) TestGetDependencies(c *C) {
+6
View File
@@ -178,6 +178,8 @@ const (
VersionEqual
VersionGreaterOrEqual
VersionGreater
VersionPatternMatch
VersionRegexp
)
// Dependency is a parsed version of Debian dependency to package
@@ -207,6 +209,10 @@ func (d *Dependency) String() string {
rel = ">="
case VersionLessOrEqual:
rel = "<="
case VersionPatternMatch:
rel = "%"
case VersionRegexp:
rel = "~"
case VersionDontCare:
return fmt.Sprintf("%s [%s]", d.Pkg, d.Architecture)
}