Add unit test for unique translation template keys (#7557)

This commit is contained in:
OptimizedForDensity
2022-07-30 03:32:40 -04:00
committed by GitHub
parent 64e79ffa0d
commit 53d18095ee

View File

@ -126,6 +126,28 @@ class TranslationTests {
)
}
@Test
fun allTranslationsHaveUniquePlaceholders() {
// check that the templates have unique placeholders (the translation entries are checked below)
val templateLines = Gdx.files.internal(TranslationFileWriter.templateFileLocation).reader().readLines()
var noTwoPlaceholdersAreTheSame = true
for (template in templateLines) {
if (template.startsWith("#")) continue
val placeholders = squareBraceRegex.findAll(template)
.map { it.value }.toList()
for (placeholder in placeholders)
if (placeholders.count { it == placeholder } > 1) {
noTwoPlaceholdersAreTheSame = false
println("Template key $template has the parameter $placeholder more than once")
break
}
}
Assert.assertTrue(
"This test will only pass when no translation template keys have the same parameter twice",
noTwoPlaceholdersAreTheSame)
}
@Test
fun noTwoPlaceholdersAreTheSame() {
var noTwoPlaceholdersAreTheSame = true