-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update PrintWidth to use correct parameters, add tests.
- Loading branch information
1 parent
7f60a6e
commit 796b764
Showing
3 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
package info.mking.k2zpl.command | ||
|
||
import info.mking.k2zpl.builder.ZplBuilder | ||
import info.mking.k2zpl.builder.command | ||
|
||
internal data class PrintWidth(val width: Int) : ZplCommand { | ||
init { | ||
require(width in 1..32000) { "Width must be between 1 and 32000" } | ||
require(width in 2 .. 32000) { "Width must be greater than 2. Value is also capped at width of the actual label." } | ||
} | ||
|
||
override val command: CharSequence = "^PW" | ||
override val parameters: LinkedHashMap<CharSequence, Any?> = linkedMapOf("w" to width) | ||
} | ||
|
||
|
||
/** | ||
* Sets the print width of the label. | ||
* @param width The width of the label. | ||
*/ | ||
fun ZplBuilder.printWidth(width: Int) { | ||
command(PrintWidth(width = width)) | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/kotlin/info/mking/k2zpl/command/PrintWidthTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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 PrintWidthTest : DescribeSpec({ | ||
isolationMode = IsolationMode.InstancePerLeaf | ||
|
||
val printWidth = PrintWidth( | ||
width = 640 | ||
) | ||
|
||
describe("PrintWidth") { | ||
it("outputs correct command") { | ||
printWidth.testBuildString() shouldBe "^PW640" | ||
} | ||
it("requires valid parameters") { | ||
table(headers("width"), | ||
row(0), | ||
row(32001) | ||
).forAll { | ||
shouldThrow<IllegalArgumentException> { | ||
printWidth.copy(width = it) | ||
} | ||
} | ||
} | ||
} | ||
describe("printWidth extension function") { | ||
it("outputs the correct command") { | ||
val result = k2zpl { | ||
printWidth(640) | ||
} | ||
result shouldBe "^PW640\n" | ||
} | ||
} | ||
}) |