forked from pinterest/ktlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement PathMatcher instead of Klob for Glob Matching
- Loading branch information
Showing
4 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
ktlint/src/test/kotlin/com/pinterest/ktlint/internal/FileUtilsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.pinterest.ktlint.internal | ||
|
||
import java.io.File | ||
import java.nio.file.Paths | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class FileUtilsTest { | ||
|
||
@Test | ||
fun negation() { | ||
val filter = FileMatcher(File("/tmp"), listOf( | ||
"**.kt", | ||
"!**/*test*/**.kt", | ||
"!**/prefix*/**.kt", | ||
"!**/*suffix/**.kt" | ||
)) | ||
|
||
assertTrue(filter.matches(Paths.get("a.kt"))) | ||
assertFalse(filter.matches(Paths.get("a/test_/a.kt"))) | ||
assertFalse(filter.matches(Paths.get("a/_test_/a.kt"))) | ||
assertFalse(filter.matches(Paths.get("a/_test/a.kt"))) | ||
assertFalse(filter.matches(Paths.get("a/prefix_/a.kt"))) | ||
assertFalse(filter.matches(Paths.get("a/prefix/a.kt"))) | ||
assertTrue(filter.matches(Paths.get("a/_prefix/a.kt"))) | ||
assertFalse(filter.matches(Paths.get("a/_suffix/a.kt"))) | ||
assertFalse(filter.matches(Paths.get("a/suffix/a.kt"))) | ||
assertTrue(filter.matches(Paths.get("a/suffix_/a.kt"))) | ||
} | ||
|
||
@Test | ||
fun overlappingFilePatternTest() { | ||
val result = listOf("src/test/**/*.kt", "!src/test/resources/**").fileSequence() | ||
|
||
result.forEach { | ||
assertTrue("File should have been excluded : ${it.path}", !it.path.contains("/resources/")) | ||
} | ||
} | ||
|
||
} |