Skip to content

Commit

Permalink
Move graphicField extension function, add empty GraphicFieldTest file…
Browse files Browse the repository at this point in the history
…, will add more tests later upon further investigation.

Also add suppression of UNUSED on all option class files
  • Loading branch information
itsmattking committed Jul 29, 2024
1 parent 7acc7eb commit bb78aeb
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 21 deletions.
19 changes: 0 additions & 19 deletions src/main/kotlin/info/mking/k2zpl/builder/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,13 @@ package info.mking.k2zpl.builder
import info.mking.k2zpl.command.EndFormat
import info.mking.k2zpl.command.FieldData
import info.mking.k2zpl.command.FieldSeparator
import info.mking.k2zpl.command.GraphicField
import info.mking.k2zpl.command.LabelLength
import info.mking.k2zpl.command.PrintQuantity
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

/**
* Draws a graphic field.
* @param format The format of the graphic field.
* @param dataBytes The number of data bytes.
* @param totalBytes The total number of bytes.
* @param rowBytes The number of bytes per row.
* @param data The data for the graphic field.
*/
fun ZplBuilder.graphicField(format: Char, dataBytes: Int, totalBytes: Int, rowBytes: Int, data: String) {
command(GraphicField(
format = format,
dataBytes = dataBytes,
totalBytes = totalBytes,
rowBytes = rowBytes,
data = data
))
}

/**
* Adds a field separator.
*/
Expand Down
32 changes: 30 additions & 2 deletions src/main/kotlin/info/mking/k2zpl/command/GraphicField.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package info.mking.k2zpl.command

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

internal data class GraphicField(
val format: Char,
val format: ZplCompressionType,
val dataBytes: Int,
val totalBytes: Int,
val rowBytes: Int,
Expand All @@ -15,6 +19,30 @@ internal data class GraphicField(

override val command: CharSequence = "^GF"
override val parameters: LinkedHashMap<CharSequence, Any?> = linkedMapOf(
"f" to format, "db" to dataBytes, "tb" to totalBytes, "rb" to rowBytes, "d" to data
"f" to format,
"db" to dataBytes,
"tb" to totalBytes,
"rb" to rowBytes,
"d" to data
)
}

/**
* Draws a graphic field.
* @param format The format of the graphic field.
* @param dataBytes The number of data bytes.
* @param totalBytes The total number of bytes.
* @param rowBytes The number of bytes per row.
* @param data The data for the graphic field.
*/
fun ZplBuilder.graphicField(format: ZplCompressionType = ZplCompressionType.ASCII, dataBytes: Int, totalBytes: Int, rowBytes: Int, data: String) {
command(
GraphicField(
format = format,
dataBytes = dataBytes,
totalBytes = totalBytes,
rowBytes = rowBytes,
data = data
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@file:Suppress("UNUSED")

package info.mking.k2zpl.command.options

enum class ZplCompressionType(private val value: Char) {
ASCII('A'),
BINARY('B'),
COMPRESSED_BINARY('C');

override fun toString(): String {
return value.toString()
}
}
29 changes: 29 additions & 0 deletions src/test/kotlin/info/mking/k2zpl/command/GraphicFieldTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package info.mking.k2zpl.command

import info.mking.k2zpl.command.options.ZplCompressionType
import info.mking.k2zpl.k2zpl
import io.kotest.core.spec.IsolationMode
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.shouldBe

class GraphicFieldTest : DescribeSpec({
isolationMode = IsolationMode.InstancePerLeaf

describe("GraphicField") {

}
describe("graphicField extension function") {
it("outputs correct command") {
val result = k2zpl {
graphicField(
format = ZplCompressionType.BINARY,
dataBytes = 1024,
totalBytes = 2048,
rowBytes = 10000,
data = "data"
)
}
result shouldBe "^GFB,1024,2048,10000,data\n"
}
}
})

0 comments on commit bb78aeb

Please sign in to comment.