Skip to content

Commit

Permalink
feat: add filter rule for chapi config
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 21, 2020
1 parent 5d2679c commit 853fe59
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package chapi.app.analyser.config

data class ChapiConfig(
var language: String = "",
var withoutTest: Boolean = false
var withoutTest: Boolean = false,
var filterRule: String = ""
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import chapi.app.analyser.config.ChapiConfig
open class FileFilter {
companion object {
fun filterByLanguage(path: String, config: ChapiConfig): Boolean {
if (config.filterRule.isNotEmpty()) {
return config.filterRule.toRegex().matches(path)
}

return when (config.language) {
"java" -> {
path.endsWith(".java")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package chapi.app.analyser.filter

import chapi.app.analyser.config.ChapiConfig
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

internal class FileFilterTest {
@Test
internal fun shouldReturnTrueWhenInputLangJava() {
val config = ChapiConfig(
language = "java"
)
val isJavaFile = FileFilter.filterByLanguage("hello.java", config)
assertEquals(isJavaFile, true)
}

@Test
internal fun shouldEnableRegexToMatchFile() {
val config = ChapiConfig(
language = "java",
filterRule = ".*\\.java"
)
val isJavaFile = FileFilter.filterByLanguage("hello.java", config)
assertEquals(isJavaFile, true)
}
}

0 comments on commit 853fe59

Please # to comment.