Skip to content

Commit 3be08fd

Browse files
committed
Add Konsist test to check that files do not have double license header.
It seems that sometimes Android Studio is doing this mistake.
1 parent 275c5b4 commit 3be08fd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,30 @@ class KonsistLicenseTest {
6868
enterpriseLicense.containsMatchIn(it.text)
6969
}
7070
}
71+
72+
@Test
73+
fun `assert that files do not have double license header`() {
74+
Konsist
75+
.scopeFromProject()
76+
.files
77+
.filter {
78+
it.nameWithExtension != "locales.kt" &&
79+
it.nameWithExtension != "KonsistLicenseTest.kt" &&
80+
it.name.startsWith("Template ").not()
81+
}
82+
.assertTrue { it ->
83+
it.text.count("New Vector") == 1
84+
}
85+
}
86+
}
87+
88+
private fun String.count(subString: String): Int {
89+
var count = 0
90+
var index = 0
91+
while (true) {
92+
index = indexOf(subString, index)
93+
if (index == -1) return count
94+
count++
95+
index += subString.length
96+
}
7197
}

0 commit comments

Comments
 (0)