From 70a74e0b71a4d79acca2d54e962cbb1bea4f4d1c Mon Sep 17 00:00:00 2001 From: Matt King Date: Sun, 28 Jul 2024 16:50:55 +0100 Subject: [PATCH] Add LabelHome test and move extension function --- .../info/mking/k2zpl/builder/Extensions.kt | 9 ------ .../info/mking/k2zpl/command/LabelHome.kt | 12 +++++++ .../info/mking/k2zpl/command/LabelHomeTest.kt | 31 +++++++++++++++++++ 3 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 src/test/kotlin/info/mking/k2zpl/command/LabelHomeTest.kt diff --git a/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt b/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt index 1caf563..31ec5f8 100644 --- a/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt +++ b/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt @@ -25,15 +25,6 @@ import info.mking.k2zpl.command.options.ZplPrintSpeed import info.mking.k2zpl.command.options.ZplTextAlignment import info.mking.k2zpl.command.options.ZplYesNo -/** - * Sets the label home position. - * @param x The x-coordinate of the label home. - * @param y The y-coordinate of the label home. - */ -fun ZplBuilder.labelHome(x: Int, y: Int) { - command(LabelHome(x = x, y = y)) -} - /** * Sets the label shift. * @param shift The shift amount. diff --git a/src/main/kotlin/info/mking/k2zpl/command/LabelHome.kt b/src/main/kotlin/info/mking/k2zpl/command/LabelHome.kt index 88373e5..3d5a2ae 100644 --- a/src/main/kotlin/info/mking/k2zpl/command/LabelHome.kt +++ b/src/main/kotlin/info/mking/k2zpl/command/LabelHome.kt @@ -1,6 +1,18 @@ package info.mking.k2zpl.command +import info.mking.k2zpl.builder.ZplBuilder +import info.mking.k2zpl.builder.command + internal data class LabelHome(val x: Int, val y: Int) : ZplCommand { override val command: CharSequence = "^LH" override val parameters: LinkedHashMap = linkedMapOf("x" to x, "y" to y) +} + +/** + * Sets the label home position. + * @param x The x-coordinate of the label home. + * @param y The y-coordinate of the label home. + */ +fun ZplBuilder.labelHome(x: Int, y: Int) { + command(LabelHome(x = x, y = y)) } \ No newline at end of file diff --git a/src/test/kotlin/info/mking/k2zpl/command/LabelHomeTest.kt b/src/test/kotlin/info/mking/k2zpl/command/LabelHomeTest.kt new file mode 100644 index 0000000..3ce9bc5 --- /dev/null +++ b/src/test/kotlin/info/mking/k2zpl/command/LabelHomeTest.kt @@ -0,0 +1,31 @@ +package info.mking.k2zpl.command + +import info.mking.k2zpl.k2zpl +import info.mking.k2zpl.testBuildString +import io.kotest.core.spec.IsolationMode +import io.kotest.core.spec.style.DescribeSpec +import io.kotest.matchers.shouldBe + +class LabelHomeTest : DescribeSpec({ + + isolationMode = IsolationMode.InstancePerLeaf + + val labelHome = LabelHome( + x = 10, + y = 10 + ) + + describe("LabelHome") { + it("outputs the correct command") { + labelHome.testBuildString() shouldBe "^LH10,10" + } + } + describe("labelHome extension function") { + it("outputs the correct command") { + val result = k2zpl { + labelHome(x = 0, y = 100) + } + result shouldBe "^LH0,100\n" + } + } +}) \ No newline at end of file