Skip to content

Commit

Permalink
Add LabelHome test and move extension function
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattking committed Jul 28, 2024
1 parent 796b764 commit 70a74e0
Show file tree
Hide file tree
Showing 3 changed files with 43 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 @@ -25,15 +25,6 @@ import info.mking.k2zpl.command.options.ZplPrintSpeed
import info.mking.k2zpl.command.options.ZplTextAlignment
import info.mking.k2zpl.command.options.ZplYesNo

/**
* Sets the label home position.
* @param x The x-coordinate of the label home.
* @param y The y-coordinate of the label home.
*/
fun ZplBuilder.labelHome(x: Int, y: Int) {
command(LabelHome(x = x, y = y))
}

/**
* Sets the label shift.
* @param shift The shift amount.
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/info/mking/k2zpl/command/LabelHome.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.builder.ZplBuilder
import info.mking.k2zpl.builder.command

internal data class LabelHome(val x: Int, val y: Int) : ZplCommand {
override val command: CharSequence = "^LH"
override val parameters: LinkedHashMap<CharSequence, Any?> = linkedMapOf("x" to x, "y" to y)
}

/**
* Sets the label home position.
* @param x The x-coordinate of the label home.
* @param y The y-coordinate of the label home.
*/
fun ZplBuilder.labelHome(x: Int, y: Int) {
command(LabelHome(x = x, y = y))
}
31 changes: 31 additions & 0 deletions src/test/kotlin/info/mking/k2zpl/command/LabelHomeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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 LabelHomeTest : DescribeSpec({

isolationMode = IsolationMode.InstancePerLeaf

val labelHome = LabelHome(
x = 10,
y = 10
)

describe("LabelHome") {
it("outputs the correct command") {
labelHome.testBuildString() shouldBe "^LH10,10"
}
}
describe("labelHome extension function") {
it("outputs the correct command") {
val result = k2zpl {
labelHome(x = 0, y = 100)
}
result shouldBe "^LH0,100\n"
}
}
})

0 comments on commit 70a74e0

Please sign in to comment.