Move all mutable state from FileTreeWalk to its iterator implementation, allowing this sequence to be iterated several times.

Introduce SingleFileState for single file walks.
Do not check isDirectory in DirectoryState constructor unless assertions are enabled.
This commit is contained in:
Ilya Gorbunov
2015-12-04 20:48:06 +03:00
parent 061803d7b1
commit e24dbcefb6
2 changed files with 161 additions and 140 deletions
+17
View File
@@ -49,6 +49,23 @@ class FileTreeWalkTest {
}
}
@Test fun singleFile() {
val testFile = createTempFile()
val nonExistantFile = testFile.resolve("foo")
try {
for (walk in listOf(File::walkTopDown, File::walkBottomUp)) {
assertEquals(testFile, walk(testFile).single(), "${walk.name}")
assertTrue(walk(testFile).treeFilter { false }.none(), "${walk.name}")
assertEquals(testFile, testFile.walk().onEnter { false }.single(), "${walk.name} - enter should not be called for single file")
assertTrue(walk(nonExistantFile).none(), "${walk.name} - enter should not be called for single file")
}
}
finally {
testFile.delete()
}
}
@Test fun withEnterLeave() {
val basedir = createTestFiles()
try {