-
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.
- Add ZplYesNo to handle translating booleans to Y/N - Add BarCodeTest
- Loading branch information
1 parent
0ff69a6
commit cf57069
Showing
6 changed files
with
137 additions
and
34 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
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/info/mking/k2zpl/command/options/ZplBarcodeType.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,5 @@ | ||
package info.mking.k2zpl.command.options | ||
|
||
enum class ZplBarcodeType { | ||
CODE_39 | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/info/mking/k2zpl/command/options/ZplYesNo.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,10 @@ | ||
package info.mking.k2zpl.command.options | ||
|
||
enum class ZplYesNo(val value: String) { | ||
YES("Y"), | ||
NO("N"); | ||
|
||
override fun toString(): String { | ||
return value | ||
} | ||
} |
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,76 @@ | ||
package info.mking.k2zpl.command | ||
|
||
import info.mking.k2zpl.command.options.ZplBarcodeType | ||
import info.mking.k2zpl.command.options.ZplFieldOrientation | ||
import info.mking.k2zpl.command.options.ZplYesNo | ||
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 BarCodeTest : DescribeSpec({ | ||
|
||
isolationMode = IsolationMode.InstancePerLeaf | ||
|
||
val barCode = BarCode( | ||
type = ZplBarcodeType.CODE_39, | ||
orientation = ZplFieldOrientation.NORMAL, | ||
checkDigit = ZplYesNo.NO, | ||
height = 10, | ||
line = 7, | ||
lineAbove = ZplYesNo.YES | ||
) | ||
|
||
describe("Barcode") { | ||
it("outputs correct command") { | ||
val result = barCode.testBuildString() | ||
result shouldBe "^B1N,N,10,7,Y" | ||
} | ||
it("uses orientation parameter properly") { | ||
ZplFieldOrientation.entries.forEach { | ||
barCode.copy(orientation = it).testBuildString() shouldBe "^B1${it.code},N,10,7,Y" | ||
} | ||
} | ||
it("uses checkDigit parameter properly") { | ||
ZplYesNo.entries.forEach { | ||
barCode.copy(checkDigit = it).testBuildString() shouldBe "^B1N,${it},10,7,Y" | ||
} | ||
} | ||
it("uses lineAbove parameter properly") { | ||
ZplYesNo.entries.forEach { | ||
barCode.copy(lineAbove = it).testBuildString() shouldBe "^B1N,N,10,7,${it}" | ||
} | ||
} | ||
it("requires valid parameters") { | ||
table( | ||
headers("height", "line"), | ||
row(32001, 1), | ||
row(0, 1), | ||
row(1, 0), | ||
row(1, 8) | ||
).forAll { height, line -> | ||
shouldThrow<IllegalArgumentException> { | ||
barCode.copy( | ||
height = height, | ||
line = line, | ||
) | ||
} | ||
} | ||
} | ||
|
||
} | ||
describe("barcode extension") { | ||
it("outputs the correct command") { | ||
val result = k2zpl { | ||
barcode(checkDigit = false, height = 10, line = 7, lineAbove = true) | ||
} | ||
result shouldBe "^B1N,N,10,7,Y\n" | ||
} | ||
} | ||
}) |
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