mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-06 16:28:40 +07:00
Added tests for parameters for complex filters, fixed nested complex filter returning 'possible filtering' when it should have been known
This commit is contained in:
@ -5,7 +5,7 @@ object MultiFilter {
|
|||||||
/** Unique validity doesn't check for actual matching */ forUniqueValidityTests:Boolean=false): Boolean {
|
/** Unique validity doesn't check for actual matching */ forUniqueValidityTests:Boolean=false): Boolean {
|
||||||
if (input.contains("} {"))
|
if (input.contains("} {"))
|
||||||
return input.removePrefix("{").removeSuffix("}").split("} {")
|
return input.removePrefix("{").removeSuffix("}").split("} {")
|
||||||
.all{ multiFilter(it, filterFunction) }
|
.all{ multiFilter(it, filterFunction, forUniqueValidityTests) }
|
||||||
if (input.startsWith("non-[") && input.endsWith("]")) {
|
if (input.startsWith("non-[") && input.endsWith("]")) {
|
||||||
val internalResult = multiFilter(input.removePrefix("non-[").removeSuffix("]"), filterFunction)
|
val internalResult = multiFilter(input.removePrefix("non-[").removeSuffix("]"), filterFunction)
|
||||||
return if (forUniqueValidityTests) internalResult else !internalResult
|
return if (forUniqueValidityTests) internalResult else !internalResult
|
||||||
|
@ -13,17 +13,17 @@ Note that all of these are case-sensitive!
|
|||||||
|
|
||||||
All filters except for `cityFilter` and `populationFilter` accept multiple values in the format: `{A} {B} {C}` etc, meaning "the object must match ALL of these filters"
|
All filters except for `cityFilter` and `populationFilter` accept multiple values in the format: `{A} {B} {C}` etc, meaning "the object must match ALL of these filters"
|
||||||
|
|
||||||
Example: `[{Military} {Water}] units`, `[{Wounded} {Armor}] units`, etc.
|
> Example: `[{Military} {Water}] units`, `[{Wounded} {Armor}] units`, etc.
|
||||||
|
|
||||||
No space or other text is allowed between the `[` and the first `{`.
|
No space or other text is allowed between the `[` and the first `{`.
|
||||||
|
|
||||||
All filters accept `non-[filter]` as a possible value
|
All filters accept `non-[filter]` as a possible value
|
||||||
|
|
||||||
Example: `[non-[Wounded]] units`
|
> Example: `[non-[Wounded]] units`
|
||||||
|
|
||||||
These can be combined by having the values be negative filters
|
These can be combined by having the values be negative filters
|
||||||
|
|
||||||
Example: `[{non-[Wounded]} {Armor}] units`
|
> Example: `[{non-[Wounded]} {Armor}] units`
|
||||||
|
|
||||||
These CANNOT be combined in the other way - e.g. `[non-[{Wounded} {Armor}]] units` is NOT valid and will fail to register any units.
|
These CANNOT be combined in the other way - e.g. `[non-[{Wounded} {Armor}]] units` is NOT valid and will fail to register any units.
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package com.unciv.logic
|
package com.unciv.logic
|
||||||
|
|
||||||
|
import com.unciv.models.ruleset.Ruleset
|
||||||
|
import com.unciv.models.ruleset.unique.UniqueParameterType
|
||||||
|
import com.unciv.models.ruleset.unique.UniqueType
|
||||||
import com.unciv.testing.GdxTestRunner
|
import com.unciv.testing.GdxTestRunner
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@ -25,4 +28,24 @@ class MultiFilterTests {
|
|||||||
Assert.assertTrue(MultiFilter.multiFilter("{non-[A]} {non-[B]}", { it=="C"}))
|
Assert.assertTrue(MultiFilter.multiFilter("{non-[A]} {non-[B]}", { it=="C"}))
|
||||||
Assert.assertFalse(MultiFilter.multiFilter("{non-[A]} {non-[B]}", { it=="A"}))
|
Assert.assertFalse(MultiFilter.multiFilter("{non-[A]} {non-[B]}", { it=="A"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testParameterTypeSplits(){
|
||||||
|
Assert.assertNull(UniqueParameterType.MapUnitFilter.getErrorSeverity("{Wounded} {Barbarian}", Ruleset()))
|
||||||
|
Assert.assertEquals(UniqueParameterType.MapUnitFilter.getErrorSeverity("{Wounded} {NONEXISTANTFILTER}", Ruleset()),
|
||||||
|
UniqueType.UniqueParameterErrorSeverity.PossibleFilteringUnique)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testParameterNonFilters(){
|
||||||
|
Assert.assertNull(UniqueParameterType.MapUnitFilter.getErrorSeverity("non-[Wounded]", Ruleset()))
|
||||||
|
Assert.assertNull(UniqueParameterType.MapUnitFilter.getErrorSeverity("{non-[Wounded]} {Barbarian}", Ruleset()))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testParameterTypeSplitsWorkWithMultipleLevels() {
|
||||||
|
// Wounded is part of MapUnitFilter, Melee - BaseUnitFilter, and Land - UnitTypeFilter
|
||||||
|
Assert.assertNull(UniqueParameterType.MapUnitFilter.getErrorSeverity("{Wounded} {Melee} {Land}", Ruleset()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user