From bb78aebab88202121d4c811767ceb33979ddb329 Mon Sep 17 00:00:00 2001 From: Matt King Date: Mon, 29 Jul 2024 07:22:16 +0100 Subject: [PATCH] Move graphicField extension function, add empty GraphicFieldTest file, will add more tests later upon further investigation. Also add suppression of UNUSED on all option class files --- .../info/mking/k2zpl/builder/Extensions.kt | 19 ----------- .../info/mking/k2zpl/command/GraphicField.kt | 32 +++++++++++++++++-- .../command/options/ZplCompressionType.kt | 13 ++++++++ .../mking/k2zpl/command/GraphicFieldTest.kt | 29 +++++++++++++++++ 4 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 src/main/kotlin/info/mking/k2zpl/command/options/ZplCompressionType.kt create mode 100644 src/test/kotlin/info/mking/k2zpl/command/GraphicFieldTest.kt diff --git a/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt b/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt index 8c873ee..7d32006 100644 --- a/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt +++ b/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt @@ -5,7 +5,6 @@ package info.mking.k2zpl.builder import info.mking.k2zpl.command.EndFormat import info.mking.k2zpl.command.FieldData import info.mking.k2zpl.command.FieldSeparator -import info.mking.k2zpl.command.GraphicField import info.mking.k2zpl.command.LabelLength import info.mking.k2zpl.command.PrintQuantity import info.mking.k2zpl.command.StartFormat @@ -13,24 +12,6 @@ import info.mking.k2zpl.command.ZplCommand import info.mking.k2zpl.command.options.ZplFont import info.mking.k2zpl.command.options.ZplYesNo -/** - * Draws a graphic field. - * @param format The format of the graphic field. - * @param dataBytes The number of data bytes. - * @param totalBytes The total number of bytes. - * @param rowBytes The number of bytes per row. - * @param data The data for the graphic field. - */ -fun ZplBuilder.graphicField(format: Char, dataBytes: Int, totalBytes: Int, rowBytes: Int, data: String) { - command(GraphicField( - format = format, - dataBytes = dataBytes, - totalBytes = totalBytes, - rowBytes = rowBytes, - data = data - )) -} - /** * Adds a field separator. */ diff --git a/src/main/kotlin/info/mking/k2zpl/command/GraphicField.kt b/src/main/kotlin/info/mking/k2zpl/command/GraphicField.kt index 0546cc1..f46779e 100644 --- a/src/main/kotlin/info/mking/k2zpl/command/GraphicField.kt +++ b/src/main/kotlin/info/mking/k2zpl/command/GraphicField.kt @@ -1,7 +1,11 @@ package info.mking.k2zpl.command +import info.mking.k2zpl.builder.ZplBuilder +import info.mking.k2zpl.builder.command +import info.mking.k2zpl.command.options.ZplCompressionType + internal data class GraphicField( - val format: Char, + val format: ZplCompressionType, val dataBytes: Int, val totalBytes: Int, val rowBytes: Int, @@ -15,6 +19,30 @@ internal data class GraphicField( override val command: CharSequence = "^GF" override val parameters: LinkedHashMap = linkedMapOf( - "f" to format, "db" to dataBytes, "tb" to totalBytes, "rb" to rowBytes, "d" to data + "f" to format, + "db" to dataBytes, + "tb" to totalBytes, + "rb" to rowBytes, + "d" to data + ) +} + +/** + * Draws a graphic field. + * @param format The format of the graphic field. + * @param dataBytes The number of data bytes. + * @param totalBytes The total number of bytes. + * @param rowBytes The number of bytes per row. + * @param data The data for the graphic field. + */ +fun ZplBuilder.graphicField(format: ZplCompressionType = ZplCompressionType.ASCII, dataBytes: Int, totalBytes: Int, rowBytes: Int, data: String) { + command( + GraphicField( + format = format, + dataBytes = dataBytes, + totalBytes = totalBytes, + rowBytes = rowBytes, + data = data + ) ) } \ No newline at end of file diff --git a/src/main/kotlin/info/mking/k2zpl/command/options/ZplCompressionType.kt b/src/main/kotlin/info/mking/k2zpl/command/options/ZplCompressionType.kt new file mode 100644 index 0000000..30b65b0 --- /dev/null +++ b/src/main/kotlin/info/mking/k2zpl/command/options/ZplCompressionType.kt @@ -0,0 +1,13 @@ +@file:Suppress("UNUSED") + +package info.mking.k2zpl.command.options + +enum class ZplCompressionType(private val value: Char) { + ASCII('A'), + BINARY('B'), + COMPRESSED_BINARY('C'); + + override fun toString(): String { + return value.toString() + } +} \ No newline at end of file diff --git a/src/test/kotlin/info/mking/k2zpl/command/GraphicFieldTest.kt b/src/test/kotlin/info/mking/k2zpl/command/GraphicFieldTest.kt new file mode 100644 index 0000000..ad1602e --- /dev/null +++ b/src/test/kotlin/info/mking/k2zpl/command/GraphicFieldTest.kt @@ -0,0 +1,29 @@ +package info.mking.k2zpl.command + +import info.mking.k2zpl.command.options.ZplCompressionType +import info.mking.k2zpl.k2zpl +import io.kotest.core.spec.IsolationMode +import io.kotest.core.spec.style.DescribeSpec +import io.kotest.matchers.shouldBe + +class GraphicFieldTest : DescribeSpec({ + isolationMode = IsolationMode.InstancePerLeaf + + describe("GraphicField") { + + } + describe("graphicField extension function") { + it("outputs correct command") { + val result = k2zpl { + graphicField( + format = ZplCompressionType.BINARY, + dataBytes = 1024, + totalBytes = 2048, + rowBytes = 10000, + data = "data" + ) + } + result shouldBe "^GFB,1024,2048,10000,data\n" + } + } +}) \ No newline at end of file