command tests: properly validate stack

This commit is contained in:
Bixilon 2023-05-23 16:57:34 +02:00
parent 60906788cd
commit 517cf93681
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 30 additions and 15 deletions

View File

@ -50,13 +50,13 @@ class MsgCommandIT {
} }
fun validateStack() { fun validateStack() {
val node = createNode { var stack: CommandStack? = null
assertEquals(it["msg"], "msg") val node = createNode { stack = it.copy() }
assertEquals(it["targets"], NameEntityTarget("Bixilon"))
assertEquals(it["message"], "hi there!")
}
node.execute("msg Bixilon hi there!") node.execute("msg Bixilon hi there!")
assertEquals(stack!!["msg"], "msg")
assertEquals(stack!!["targets"], NameEntityTarget("Bixilon"))
assertEquals(stack!!["message"], "hi there!")
} }
fun redirectExecution() { fun redirectExecution() {
@ -69,12 +69,14 @@ class MsgCommandIT {
} }
fun redirectStack() { fun redirectStack() {
val node = createNode { var stack: CommandStack? = null
assertEquals(it["msg"], "redirect") val node = createNode { stack = it.copy() }
assertEquals(it["targets"], NameEntityTarget("Bixilon"))
assertEquals(it["message"], "hi there!")
}
node.execute("redirect Bixilon hi there!") node.execute("redirect Bixilon hi there!")
assertEquals(stack!!["msg"], "redirect")
assertEquals(stack!!["targets"], NameEntityTarget("Bixilon"))
assertEquals(stack!!["message"], "hi there!")
} }
} }

View File

@ -50,12 +50,13 @@ class TPCommandIT {
} }
fun relativeStack() { fun relativeStack() {
val node = createNode { var stack: CommandStack? = null
assertEquals(it["tp"], "tp") val node = createNode { stack = it.copy() }
assertEquals(it["target"], SelectorEntityTarget(TargetSelectors.SELF, emptyMap()))
assertEquals(it["destination"], Vec3Coordinate(Coordinate(CoordinateRelatives.TILDE, 0.0f), Coordinate(CoordinateRelatives.TILDE, +10.0f), Coordinate(CoordinateRelatives.TILDE, 0.0f)))
}
node.execute("tp @s ~ ~10 ~") node.execute("tp @s ~ ~10 ~")
assertEquals(stack!!["tp"], "tp")
assertEquals(stack!!["target"], SelectorEntityTarget(TargetSelectors.SELF, emptyMap()))
assertEquals(stack!!["destination"], Vec3Coordinate(Coordinate(CoordinateRelatives.TILDE, 0.0f), Coordinate(CoordinateRelatives.TILDE, +10.0f), Coordinate(CoordinateRelatives.TILDE, 0.0f)))
} }
} }

View File

@ -68,4 +68,16 @@ class CommandStack(
} }
return output return output
} }
fun copy(): CommandStack {
val stack = CommandStack(null, print)
stack.stack += this.stack
stack.executor = this.executor
if (this::connection.isInitialized) {
stack.connection = this.connection
}
return stack
}
} }