mirror of
https://github.com/yairm210/Unciv.git
synced 2025-10-02 16:31:15 -04:00
Added a test to ensure that translations don't crash
This commit is contained in:
parent
ca58cf1694
commit
20db11e73f
@ -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()
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user