diff --git a/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt b/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt index 6af63df..40889ca 100644 --- a/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt +++ b/src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt @@ -3,7 +3,6 @@ package info.mking.k2zpl.builder import info.mking.k2zpl.command.EndFormat -import info.mking.k2zpl.command.FieldData import info.mking.k2zpl.command.LabelLength import info.mking.k2zpl.command.PrintQuantity import info.mking.k2zpl.command.StartFormat @@ -11,14 +10,6 @@ import info.mking.k2zpl.command.ZplCommand import info.mking.k2zpl.command.options.ZplFont import info.mking.k2zpl.command.options.ZplYesNo -/** - * Adds field data. - * @param data The data to be added to the field. - */ -fun ZplBuilder.fieldData(data: String) { - command(FieldData(data)) -} - /** * Sets the print quantity and related parameters. * @param quantity The number of labels to print. diff --git a/src/main/kotlin/info/mking/k2zpl/builder/ZplBuilder.kt b/src/main/kotlin/info/mking/k2zpl/builder/ZplBuilder.kt index 9925178..a733790 100644 --- a/src/main/kotlin/info/mking/k2zpl/builder/ZplBuilder.kt +++ b/src/main/kotlin/info/mking/k2zpl/builder/ZplBuilder.kt @@ -5,6 +5,7 @@ package info.mking.k2zpl.builder import info.mking.k2zpl.command.CustomCommand import info.mking.k2zpl.command.Font import info.mking.k2zpl.command.ZplCommand +import info.mking.k2zpl.command.fieldData import info.mking.k2zpl.command.fieldOrigin import info.mking.k2zpl.command.fieldSeparator import info.mking.k2zpl.command.font diff --git a/src/main/kotlin/info/mking/k2zpl/command/BarCode.kt b/src/main/kotlin/info/mking/k2zpl/command/BarCode.kt index baea248..969863b 100644 --- a/src/main/kotlin/info/mking/k2zpl/command/BarCode.kt +++ b/src/main/kotlin/info/mking/k2zpl/command/BarCode.kt @@ -2,7 +2,6 @@ package info.mking.k2zpl.command import info.mking.k2zpl.builder.ZplBuilder import info.mking.k2zpl.builder.command -import info.mking.k2zpl.builder.fieldData import info.mking.k2zpl.builder.toZplYesNo import info.mking.k2zpl.command.options.ZplBarcodeType import info.mking.k2zpl.command.options.ZplFieldOrientation diff --git a/src/main/kotlin/info/mking/k2zpl/command/FieldData.kt b/src/main/kotlin/info/mking/k2zpl/command/FieldData.kt index 0f94ac0..7f8c38e 100644 --- a/src/main/kotlin/info/mking/k2zpl/command/FieldData.kt +++ b/src/main/kotlin/info/mking/k2zpl/command/FieldData.kt @@ -1,6 +1,17 @@ package info.mking.k2zpl.command +import info.mking.k2zpl.builder.ZplBuilder +import info.mking.k2zpl.builder.command + internal data class FieldData(val data: String) : ZplCommand { override val command: CharSequence = "^FD" override val parameters: LinkedHashMap = linkedMapOf("d" to data) +} + +/** + * Adds field data. + * @param data The data to be added to the field. + */ +fun ZplBuilder.fieldData(data: String) { + command(FieldData(data)) } \ No newline at end of file diff --git a/src/test/kotlin/info/mking/k2zpl/command/FieldDataTest.kt b/src/test/kotlin/info/mking/k2zpl/command/FieldDataTest.kt new file mode 100644 index 0000000..1d7304b --- /dev/null +++ b/src/test/kotlin/info/mking/k2zpl/command/FieldDataTest.kt @@ -0,0 +1,27 @@ +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 FieldDataTest : DescribeSpec({ + isolationMode = IsolationMode.InstancePerLeaf + + val fieldData = FieldData("some-data") + + describe("FieldData") { + it("outputs correct command") { + fieldData.testBuildString() shouldBe "^FDsome-data" + } + } + describe("fieldData extension function") { + it("outputs correct command") { + val result = k2zpl { + fieldData("some-other-data") + } + result shouldBe "^FDsome-other-data\n" + } + } +}) \ No newline at end of file