From 53d18095ee38249f161e894b3efcd0a531eec6eb Mon Sep 17 00:00:00 2001 From: OptimizedForDensity <105244635+OptimizedForDensity@users.noreply.github.com> Date: Sat, 30 Jul 2022 03:32:40 -0400 Subject: [PATCH] Add unit test for unique translation template keys (#7557) --- .../src/com/unciv/testing/TranslationTests.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/src/com/unciv/testing/TranslationTests.kt b/tests/src/com/unciv/testing/TranslationTests.kt index 86fb167c8c..37e38f6276 100644 --- a/tests/src/com/unciv/testing/TranslationTests.kt +++ b/tests/src/com/unciv/testing/TranslationTests.kt @@ -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