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() {
val node = createNode {
assertEquals(it["msg"], "msg")
assertEquals(it["targets"], NameEntityTarget("Bixilon"))
assertEquals(it["message"], "hi there!")
}
var stack: CommandStack? = null
val node = createNode { stack = it.copy() }
node.execute("msg Bixilon hi there!")
assertEquals(stack!!["msg"], "msg")
assertEquals(stack!!["targets"], NameEntityTarget("Bixilon"))
assertEquals(stack!!["message"], "hi there!")
}
fun redirectExecution() {
@ -69,12 +69,14 @@ class MsgCommandIT {
}
fun redirectStack() {
val node = createNode {
assertEquals(it["msg"], "redirect")
assertEquals(it["targets"], NameEntityTarget("Bixilon"))
assertEquals(it["message"], "hi there!")
}
var stack: CommandStack? = null
val node = createNode { stack = it.copy() }
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() {
val node = createNode {
assertEquals(it["tp"], "tp")
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)))
}
var stack: CommandStack? = null
val node = createNode { stack = it.copy() }
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
}
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
}
}