From fb05cbc6f8a6c160d9c51b7294bf33242f397ff3 Mon Sep 17 00:00:00 2001 From: Matt King Date: Mon, 29 Jul 2024 07:31:49 +0100 Subject: [PATCH] Add LabelLength tests --- .../info/mking/k2zpl/builder/Extensions.kt | 9 ---- .../info/mking/k2zpl/command/LabelLength.kt | 11 +++++ .../mking/k2zpl/command/LabelLengthTest.kt | 43 +++++++++++++++++++ 3 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 src/test/kotlin/info/mking/k2zpl/command/LabelLengthTest.kt diff --git a/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt b/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt index 1022a5d..9de138d 100644 --- a/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt +++ b/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt @@ -3,20 +3,11 @@ package info.mking.k2zpl.builder import info.mking.k2zpl.command.EndFormat -import info.mking.k2zpl.command.LabelLength import info.mking.k2zpl.command.StartFormat import info.mking.k2zpl.command.ZplCommand import info.mking.k2zpl.command.options.ZplFont import info.mking.k2zpl.command.options.ZplYesNo -/** - * Sets the length of the label. - * @param length The length of the label. - */ -fun ZplBuilder.labelLength(length: Int) { - command(LabelLength(length)) -} - /** * Starts the label format. */ diff --git a/src/main/kotlin/info/mking/k2zpl/command/LabelLength.kt b/src/main/kotlin/info/mking/k2zpl/command/LabelLength.kt index 5faa925..46f1808 100644 --- a/src/main/kotlin/info/mking/k2zpl/command/LabelLength.kt +++ b/src/main/kotlin/info/mking/k2zpl/command/LabelLength.kt @@ -1,5 +1,8 @@ package info.mking.k2zpl.command +import info.mking.k2zpl.builder.ZplBuilder +import info.mking.k2zpl.builder.command + internal data class LabelLength(val length: Int) : ZplCommand { init { require(length in 1..32000) { "Length must be between 1 and 32000" } @@ -7,4 +10,12 @@ internal data class LabelLength(val length: Int) : ZplCommand { override val command: CharSequence = "^LL" override val parameters: LinkedHashMap = linkedMapOf("l" to length) +} + +/** + * Sets the length of the label. + * @param length The length of the label. + */ +fun ZplBuilder.labelLength(length: Int) { + command(LabelLength(length)) } \ No newline at end of file diff --git a/src/test/kotlin/info/mking/k2zpl/command/LabelLengthTest.kt b/src/test/kotlin/info/mking/k2zpl/command/LabelLengthTest.kt new file mode 100644 index 0000000..8705383 --- /dev/null +++ b/src/test/kotlin/info/mking/k2zpl/command/LabelLengthTest.kt @@ -0,0 +1,43 @@ +package info.mking.k2zpl.command + +import info.mking.k2zpl.k2zpl +import info.mking.k2zpl.testBuildString +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.IsolationMode +import io.kotest.core.spec.style.DescribeSpec +import io.kotest.data.forAll +import io.kotest.data.headers +import io.kotest.data.row +import io.kotest.data.table +import io.kotest.matchers.shouldBe + +class LabelLengthTest : DescribeSpec({ + isolationMode = IsolationMode.InstancePerLeaf + + val labelLength = LabelLength(100) + + describe("LabelLength") { + it("outputs correct command") { + labelLength.testBuildString() shouldBe "^LL100" + } + it("requires valid parameters") { + table( + headers("length"), + row(0), + row(32001) + ).forAll { + shouldThrow { + labelLength.copy(length = it) + } + } + } + } + describe("labelLength extension function") { + it("outputs correct command") { + val result = k2zpl { + labelLength(1000) + } + result shouldBe "^LL1000\n" + } + } +}) \ No newline at end of file