Skip to content

Commit

Permalink
Add FieldData test
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattking committed Jul 29, 2024
1 parent e48c1a1 commit ddc0f0b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
9 changes: 0 additions & 9 deletions src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@
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
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.
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/info/mking/k2zpl/builder/ZplBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/info/mking/k2zpl/command/BarCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/info/mking/k2zpl/command/FieldData.kt
Original file line number Diff line number Diff line change
@@ -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<CharSequence, Any?> = 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))
}
27 changes: 27 additions & 0 deletions src/test/kotlin/info/mking/k2zpl/command/FieldDataTest.kt
Original file line number Diff line number Diff line change
@@ -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"
}
}
})

0 comments on commit ddc0f0b

Please sign in to comment.