Implementation of conditionals, but better than before (#5187)

* Implementation of conditionals, but better than before

* Updated the unique while I was at it

* Fixed bug where conditionals would never apply

* Capitalization

* Minor code cleaning

* Better documentation & variable names

* Changed translation strategy

* Added missing import?
This commit is contained in:
Xander Lenstra
2021-09-18 22:07:53 +02:00
committed by GitHub
parent 8cff3fda49
commit 01bfd17594
9 changed files with 309 additions and 68 deletions

View File

@ -7,10 +7,7 @@ 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 com.unciv.models.translations.*
import org.junit.Assert
import org.junit.Before
import org.junit.Test
@ -27,7 +24,7 @@ class TranslationTests {
@Before
fun loadTranslations() {
// Since the ruleset and translation loader have their own output,
// We 'disable' the output stream for their outputs, and only enable it for the twst itself.
// We 'disable' the output stream for their outputs, and only enable it for the test itself.
val outputChannel = System.out
System.setOut(PrintStream(object : OutputStream() {
override fun write(b: Int) {}
@ -188,4 +185,48 @@ class TranslationTests {
allWordsTranslatedCorrectly
)
}
@Test
fun wordBoundaryTranslationIsFormattedCorrectly() {
val translationEntry = translations["\" \""]!!
var allTranslationsCheckedOut = true
for ((language, translation) in translationEntry) {
if (!translation.startsWith("\"")
|| !translation.endsWith("\"")
|| translation.count { it == '\"' } != 2
) {
allTranslationsCheckedOut = false
println("Translation of the word boundary in $language was incorrectly formatted")
}
}
Assert.assertTrue(
"This test will only pass when the word boundrary translation succeeds",
allTranslationsCheckedOut
)
}
@Test
fun allConditionalsAreContainedInConditionalOrderTranslation() {
val orderedConditionals = Translations.englishConditionalOrderingString
val orderedConditionalsSet = orderedConditionals.getConditionals().map { it.placeholderText }
val translationEntry = translations[orderedConditionals]!!
var allTranslationsCheckedOut = true
for ((language, translation) in translationEntry) {
val translationConditionals = translation.getConditionals().map { it.placeholderText }
if (translationConditionals.toHashSet() != orderedConditionalsSet.toHashSet()
|| translationConditionals.count() != translationConditionals.distinct().count()
) {
allTranslationsCheckedOut = false
println("Not all or double parameters found in the conditional ordering for $language")
}
}
Assert.assertTrue(
"This test will only pass when each of the conditionals exists exactly once in the translations for the conditional ordering",
allTranslationsCheckedOut
)
}
}