Finishing off #6133 - autoreplace cycles through deprecation replacements until it reaches a non-deprecated text

This is guaranteed to not cycle endlessly thanks to the added test
Checked by having 2 uniques' deprecation text reference each other and it failed as expected
This commit is contained in:
Yair Morgenstern 2022-02-12 20:03:24 +02:00
parent c498426715
commit 3bbfb0100c
2 changed files with 18 additions and 0 deletions

View File

@ -372,7 +372,12 @@ class OptionsPopup(val previousScreen: BaseScreen) : Popup(previousScreen) {
allDeprecatedUniques.add(deprecatedUnique.text)
// note that this replacement does not contain conditionals attached to the original!
var uniqueReplacementText = deprecatedUnique.getReplacementText()
while (Unique(uniqueReplacementText).getDeprecationAnnotation() != null)
uniqueReplacementText = Unique(uniqueReplacementText).getReplacementText()
for (conditional in deprecatedUnique.conditionals)
uniqueReplacementText += " <${conditional.text}>"
val replacementUnique = Unique(uniqueReplacementText)

View File

@ -144,6 +144,19 @@ class BasicTests {
allOK = false
}
}
var iteration = 1
var replacementUnique = Unique(uniqueType.placeholderText)
while (replacementUnique.getDeprecationAnnotation() != null) {
if (iteration == 10) {
allOK = false
println("${uniqueType.name}'s deprecation text never references an undeprecated unique!")
break
}
iteration++
replacementUnique = Unique(replacementUnique.getReplacementText())
}
}
Assert.assertTrue("This test succeeds only if all deprecated uniques have a replaceWith text that matches an existing type", allOK)
}