From 3be08fdb0c2745f091fd483e8800af6688392b76 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 11 Aug 2025 10:36:40 +0200 Subject: [PATCH] Add Konsist test to check that files do not have double license header. It seems that sometimes Android Studio is doing this mistake. --- .../tests/konsist/KonsistLicenseTest.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt index 9f20f0fcac..9c0355f01e 100644 --- a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt +++ b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt @@ -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 + } }