package eu.friedcutlet.yokan.ui import java.io.File import kotlin.test.Test import kotlin.test.assertTrue /** * Ratchet for hardcoded user-visible text: per-file counts under `ui/` may only go down. * New text belongs in `composeResources` (`stringResource(Res.string.…)`); after moving text, * lower the file's count in `src/desktopTest/resources/hardcoded-ui-strings.txt`. */ class HardcodedUiStringsTest { private val uiRoot = File("src/commonMain/kotlin/eu/friedcutlet/yokan/ui") private val baselineFile = File("src/desktopTest/resources/hardcoded-ui-strings.txt") private val literal = Regex("""\bText\(\s*"[A-Za-z]|\b(?:title|label|text|subtitle|message|contentDescription|placeholder)\s*=\s*"[A-Za-z]""") @Test fun hardcodedUiStringsOnlyDecrease() { val baseline = baselineFile.readLines() .filter { it.isNotBlank() && !it.startsWith("#") } .associate { line -> line.substringBeforeLast(' ') to line.substringAfterLast(' ').toInt() } val actual = uiRoot.walkTopDown() .filter { it.extension == "kt" } .associate { file -> file.relativeTo(uiRoot).invariantSeparatorsPath to file.readLines().sumOf { literal.findAll(it).count() } } .filterValues { it > 0 } val grown = actual.filter { (path, count) -> count > (baseline[path] ?: 0) } assertTrue(grown.isEmpty(), "New hardcoded UI strings (move them to composeResources): $grown") val shrunk = baseline.filter { (path, count) -> (actual[path] ?: 0) < count } assertTrue(shrunk.isEmpty(), "Hardcoded UI strings went down; lower these counts in ${baselineFile.path}: $shrunk") } }