Skip to content

Commit

Permalink
Add LabelLength tests
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattking committed Jul 29, 2024
1 parent 7947f66 commit fb05cbc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 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,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.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/info/mking/k2zpl/command/LabelLength.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
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" }
}

override val command: CharSequence = "^LL"
override val parameters: LinkedHashMap<CharSequence, Any?> = 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))
}
43 changes: 43 additions & 0 deletions src/test/kotlin/info/mking/k2zpl/command/LabelLengthTest.kt
Original file line number Diff line number Diff line change
@@ -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<IllegalArgumentException> {
labelLength.copy(length = it)
}
}
}
}
describe("labelLength extension function") {
it("outputs correct command") {
val result = k2zpl {
labelLength(1000)
}
result shouldBe "^LL1000\n"
}
}
})

0 comments on commit fb05cbc

Please sign in to comment.