Added a test to ensure that translations don't crash

This commit is contained in:
Yair Morgenstern 2021-06-27 22:16:15 +03:00
parent ca58cf1694
commit 20db11e73f
2 changed files with 32 additions and 4 deletions

View File

@ -284,7 +284,7 @@ fun String.getPlaceholderText() = this.replace(squareBraceRegex, "[]")
fun String.equalsPlaceholderText(str:String): Boolean {
if (first() != str.first()) return false // for quick negative return 95% of the time
return this.getPlaceholderText() == str
return this.getPlaceholderText() == str
}
fun String.getPlaceholderParameters() = squareBraceRegex.findAll(this).map { it.groups[1]!!.value }.toList()

View File

@ -2,12 +2,15 @@
package com.unciv.testing
import com.badlogic.gdx.Gdx
import com.unciv.UncivGame
import com.unciv.models.UnitActionType
import com.unciv.models.metadata.GameSettings
import com.unciv.models.ruleset.Ruleset
import com.unciv.models.ruleset.RulesetCache
import com.unciv.models.translations.TranslationFileWriter
import com.unciv.models.translations.Translations
import com.unciv.models.translations.squareBraceRegex
import com.unciv.models.translations.tr
import org.junit.Assert
import org.junit.Before
import org.junit.Test
@ -29,13 +32,10 @@ class TranslationTests {
System.setOut(PrintStream(object : OutputStream() {
override fun write(b: Int) {}
}))
// System.setOut(TextWriter.Null)
// Console(). //(TextWriter.Null);
translations.readAllLanguagesTranslation()
RulesetCache.loadRulesets()
ruleset = RulesetCache.getBaseRuleset()
System.setOut(outputChannel)
// Console.SetOut()
}
@Test
@ -156,4 +156,32 @@ class TranslationTests {
}
Assert.assertFalse(failed)
}
@Test
fun allStringsTranslate() {
// Needed for .tr() to work
UncivGame.Current = UncivGame("")
UncivGame.Current.settings = GameSettings()
for ((key, value) in translations)
UncivGame.Current.translations[key] = value
var allWordsTranslatedCorrectly = true
for (translationEntry in translations.values) {
for ((language, translation) in translationEntry) {
UncivGame.Current.settings.language = language
try {
translationEntry.entry.tr()
} catch (ex: Exception) {
allWordsTranslatedCorrectly = false
println("Crashed when translating ${translationEntry.entry} to $language")
}
}
}
Assert.assertTrue(
"This test will only pass when all phrases properly translate to their language",
allWordsTranslatedCorrectly
)
}
}