-
Notifications
You must be signed in to change notification settings - Fork 31
/
ScannerSpec.scala
39 lines (29 loc) · 989 Bytes
/
ScannerSpec.scala
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
package scan
import java.io.PrintWriter
import java.nio.file._
import org.specs2._
import scala.collection.immutable.SortedSet
class ScannerSpec extends mutable.Specification {
"Report Format" ! {
val base = deletedOnExit(Files.createTempDirectory("exerciseClassic"))
val base1 = deletedOnExit(fillFile(base, 1))
val base2 = deletedOnExit(fillFile(base, 2))
val subdir = deletedOnExit(Files.createTempDirectory(base, "subdir"))
val sub1 = deletedOnExit(fillFile(subdir, 1))
val sub3 = deletedOnExit(fillFile(subdir, 3))
val actual = Scanner.pathScan(FilePath(base), 2)
val expected = new PathScan(SortedSet(FileSize(sub3, 3), FileSize(base2, 2)), 7, 4)
actual.mustEqual(expected)
}
def fillFile(dir: Path, size: Int) = {
val path = dir.resolve(s"$size.txt")
val w = new PrintWriter(path.toFile)
try w.write("a" * size)
finally w.close
path
}
def deletedOnExit(p: Path) = {
p.toFile.deleteOnExit()
p
}
}