-
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.
Browse files
Browse the repository at this point in the history
* [#13] Add MediaType `^MT` command - Adds `MediaType` with extension function `mediaType` * Suppress unused `ZplMediaType` * Fix `MediaTypeTest` nesting
- Loading branch information
1 parent
39af7d8
commit 05e8503
Showing
3 changed files
with
86 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.sainsburys.k2zpl.command | ||
|
||
import com.sainsburys.k2zpl.builder.ZplBuilder | ||
import com.sainsburys.k2zpl.command.options.ZplMediaType | ||
|
||
internal data class MediaType( | ||
val type: ZplMediaType, | ||
) : ZplCommand { | ||
override val command = "^MT" | ||
override val parameters: ZplParameters = zplParameters( | ||
"t" to type | ||
) | ||
} | ||
|
||
/** | ||
* Sets the media type for the label. | ||
* Allows to set thermal vs. ribbon. | ||
* | ||
* The ^MT command selects the type of media being used in the printer. | ||
* | ||
* @param type The media type of the printer. | ||
* | ||
* [ZplMediaType.THERMAL_TRANSFER] – this media uses a high-carbon black or colored ribbon. The ink on the ribbon is bonded to the media. | ||
* | ||
* [ZplMediaType.DIRECT_TRANSFER] – this media is heat sensitive and requires no ribbon. | ||
* | ||
*/ | ||
fun ZplBuilder.mediaType(type: ZplMediaType) { | ||
command(MediaType(type)) | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/sainsburys/k2zpl/command/options/ZplMediaType.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,12 @@ | ||
@file:Suppress("UNUSED") | ||
|
||
package com.sainsburys.k2zpl.command.options | ||
|
||
enum class ZplMediaType(val value: String) { | ||
THERMAL_TRANSFER("T"), | ||
DIRECT_TRANSFER("D"); | ||
|
||
override fun toString(): String { | ||
return value | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/kotlin/com/sainsburys/k2zpl/command/MediaTypeTest.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 com.sainsburys.k2zpl.command | ||
|
||
import com.sainsburys.k2zpl.command.options.ZplMediaType | ||
import com.sainsburys.k2zpl.k2zpl | ||
import com.sainsburys.k2zpl.testBuildString | ||
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 MediaTypeTest : DescribeSpec({ | ||
|
||
isolationMode = IsolationMode.InstancePerLeaf | ||
|
||
describe("MediaType") { | ||
|
||
val subject = MediaType(type = ZplMediaType.DIRECT_TRANSFER) | ||
|
||
it("outputs correct command") { | ||
table( | ||
headers("media type"), | ||
ZplMediaType.entries.map { row(it) } | ||
).forAll { type -> | ||
subject.copy(type = type).testBuildString() shouldBe "^MT${type}" | ||
} | ||
} | ||
} | ||
describe("mediaType extension function") { | ||
it("outputs correct command") { | ||
table( | ||
headers("media type"), | ||
ZplMediaType.entries.map { row(it) } | ||
).forAll { type -> | ||
val result = k2zpl { | ||
mediaType(type) | ||
} | ||
result shouldBe "^MT${type}\n" | ||
} | ||
} | ||
} | ||
}) |