Add Konsist test to check that files do not have double license header.

It seems that sometimes Android Studio is doing this mistake.
This commit is contained in:
Benoit Marty 2025-08-11 10:36:40 +02:00
parent 275c5b41c5
commit 3be08fdb0c

View file

@ -68,4 +68,30 @@ class KonsistLicenseTest {
enterpriseLicense.containsMatchIn(it.text)
}
}
@Test
fun `assert that files do not have double license header`() {
Konsist
.scopeFromProject()
.files
.filter {
it.nameWithExtension != "locales.kt" &&
it.nameWithExtension != "KonsistLicenseTest.kt" &&
it.name.startsWith("Template ").not()
}
.assertTrue { it ->
it.text.count("New Vector") == 1
}
}
}
private fun String.count(subString: String): Int {
var count = 0
var index = 0
while (true) {
index = indexOf(subString, index)
if (index == -1) return count
count++
index += subString.length
}
}