Skip to content

Commit

Permalink
Merge pull request #248 from eatkins/or-filter-fix
Browse files Browse the repository at this point in the history
Fix bug in converting OrFilter
  • Loading branch information
eed3si9n authored Jul 17, 2019
2 parents 4e19053 + 4035e01 commit ee1403f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion io/src/main/scala/sbt/internal/nio/Globs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private[sbt] object Globs {
case (left, Some(NoPath)) => left
case (any @ Some(AnyPath), _) => any
case (_, any @ Some(AnyPath)) => any
case (Some(left: Matcher), Some(right: Matcher)) => Some(Matcher.and(left, right))
case (Some(left: Matcher), Some(right: Matcher)) => Some(Matcher.or(left, right))
case _ => None
}
}
Expand Down
2 changes: 1 addition & 1 deletion io/src/main/scala/sbt/nio/file/Glob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ object RelativeGlob {
* @return true it the path matches.
*/
override def matches(path: Path): Boolean = left.matches(path) || right.matches(path)
override def toString: String = s"($left && $right)"
override def toString: String = s"($left || $right)"
}
private[file] final case class AndMatcher(left: Matcher, right: Matcher) extends Matcher {
override private[sbt] def matchers: List[Matcher] = this :: Nil
Expand Down
8 changes: 8 additions & 0 deletions io/src/test/scala/sbt/internal/nio/GlobsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,12 @@ class GlobsSpec extends FlatSpec {
assert(!glob.matches(basePath.resolve("foo").resolve("bar.scala")))
assert(glob.matches(basePath.resolve("foo").resolve("baz.java")))
}
it should "apply or with name filters" in {
val excludeFilter: FileFilter = ("Baz.scala": NameFilter) || "Bar.scala"
val includeFilter: NameFilter = "*.scala"
val filter = includeFilter -- excludeFilter
val glob = Globs(basePath, recursive = true, filter)
assert(glob.matches(basePath.resolve("foo").resolve("Foo.scala")))
assert(!glob.matches(basePath.resolve("foo").resolve("Bar.scala")))
}
}

0 comments on commit ee1403f

Please sign in to comment.