-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobOrderingSpec.scala
More file actions
79 lines (74 loc) · 3.04 KB
/
GlobOrderingSpec.scala
File metadata and controls
79 lines (74 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* sbt IO
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/
package sbt.nio
import java.io.File
import org.scalatest.flatspec.AnyFlatSpec
import sbt.io.{ IO, SimpleFilter }
import sbt.nio.file.RelativeGlob.Matcher
import sbt.nio.file._
import sbt.nio.file.syntax._
import scala.jdk.CollectionConverters._
class GlobOrderingSpec extends AnyFlatSpec {
"Globs" should "be ordered" in IO.withTemporaryDirectory { dir =>
val subdir = new File(dir, "subdir")
assert(Seq(Glob(subdir), Glob(dir)).sorted == Seq(Glob(dir), Glob(subdir)))
}
they should "fall back on depth" in IO.withTemporaryDirectory { dir =>
val recursive = Glob(dir, **)
val nonRecursive = Glob(dir)
assert(Seq(nonRecursive, recursive).sorted == Seq(recursive, nonRecursive))
}
they should "not stack overflow" in IO.withTemporaryDirectory { dir =>
val exact = Glob(dir.toPath.resolve("foo"))
val fullFile =
sbt.internal.nio.Globs(dir.toPath / "foo", recursive = true, sbt.io.HiddenFileFilter)
assert(Seq(exact, fullFile).sorted == Seq(exact, fullFile))
}
they should "not violate sorting contract" in IO.withTemporaryDirectory { dir =>
val globs = Seq(
**,
** / "foo",
** / * / "bar",
** / "foo" / "bar",
** / Matcher.or(Matcher("foo"), Matcher("bar")),
** / Matcher.and(Matcher("foo"), Matcher("bar")),
** / Matcher.not(Matcher("foo")),
** / Matcher.not(Matcher.and(Matcher("foo"), Matcher("bar"))),
** / Matcher(_.contains("foo")),
** / "foo" / Matcher(_.contains("bar")),
** / "foo" / Matcher.not(Matcher(_.contains("bar"))),
** / "foo" / "*.scala",
** / **,
** / *,
(** / "foo") / * / "*.scala",
(** / "foo") / * / "*.scala*",
(** / "foo") / ** / "*.scala*",
Glob(dir.toPath.resolve("foo")),
Glob(dir.toPath.resolve("bar")),
Glob(dir.toPath.resolve("bar").resolve("baz")),
sbt.internal.nio.Globs(dir.toPath, recursive = false, sbt.io.AllPassFilter),
sbt.internal.nio.Globs(dir.toPath, recursive = false, new SimpleFilter(_.contains("bar"))),
sbt.internal.nio.Globs(dir.toPath, recursive = true, new SimpleFilter(_.contains("baz"))),
sbt.internal.nio.Globs(dir.toPath, recursive = true, sbt.io.HiddenFileFilter),
sbt.internal.nio.Globs(dir.toPath / "foo", recursive = true, sbt.io.HiddenFileFilter),
sbt.internal.nio.Globs(dir.toPath, recursive = true, sbt.io.NothingFilter),
sbt.internal.nio.Globs(dir.toPath, recursive = true, new SimpleFilter(_.contains("foo"))),
Glob(dir.toPath / "scala", ** / "*.scala"),
Glob(dir.toPath / "java", ** / "*.java"),
Glob(dir.toPath / "scala", ** / "*.java"),
)
val javaGlobs = new java.util.ArrayList((globs ++ globs ++ globs).asJava)
1 to 1000 foreach { _ =>
java.util.Collections.shuffle(javaGlobs)
javaGlobs.asScala.sorted
}
}
}