-
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.
[CHORE] Add ZplParameters Wrapper (#21)
* [CHORE] Migrate use of `Map` and `LinkedHashMap` to wrapper `ZplParameters` To enforce use of `LinkedHashMap` on `ZplCommand`, add a simple wrapper class that uses `LinkedHashMap` underneath. * Add tests * Make `ZplParameters` implement `Iterable` and adjust interface * minor constructor adjustment * PR Feedback - collapse iterator on `ZplCommand` to sequenced functions * Add .idea/misc.xml to .gitignore * PR feedback - simplify parameter stream
- Loading branch information
1 parent
46e28f4
commit 2dbb616
Showing
17 changed files
with
110 additions
and
43 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ build/ | |
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
.idea/misc.xml | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/sainsburys/k2zpl/command/ZplParameters.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 @@ | ||
package com.sainsburys.k2zpl.command | ||
|
||
class ZplParameters(map: Map<CharSequence, Any?>) : Iterable<Map.Entry<CharSequence, Any?>> { | ||
constructor(vararg pairs: Pair<CharSequence, Any?>) : this(mapOf(*pairs)) | ||
private val _parameters: LinkedHashMap<CharSequence, Any?> = LinkedHashMap(map) | ||
operator fun get(key: CharSequence) = _parameters[key] | ||
override fun iterator(): Iterator<Map.Entry<CharSequence, Any?>> = | ||
_parameters.iterator() | ||
} | ||
|
||
fun zplParameters(vararg pairs: Pair<CharSequence, Any?>) = ZplParameters(*pairs) | ||
fun zplParameters(builderBlock: MutableMap<CharSequence, Any?>.() -> Unit) = ZplParameters(buildMap(builderBlock)) |
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
73 changes: 73 additions & 0 deletions
73
src/test/kotlin/com/sainsburys/k2zpl/command/ZplParametersTest.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,73 @@ | ||
package com.sainsburys.k2zpl.command | ||
|
||
import io.kotest.core.spec.IsolationMode | ||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class ZplParametersTest : DescribeSpec({ | ||
isolationMode = IsolationMode.InstancePerLeaf | ||
|
||
describe("ZplParameters pairs constructor") { | ||
val result = ZplParameters("a" to "b", "c" to "d") | ||
it("returns values passed to ZplParameters") { | ||
result.forEachIndexed { index, param -> | ||
when (index) { | ||
0 -> param.value shouldBe "b" | ||
1 -> param.value shouldBe "d" | ||
} | ||
} | ||
} | ||
it("makes values accessible by get operator") { | ||
result["a"] shouldBe "b" | ||
result["c"] shouldBe "d" | ||
} | ||
} | ||
describe("ZplParameters map constructor") { | ||
val result = ZplParameters(mapOf("a" to "b", "c" to "d")) | ||
it("returns values passed to ZplParameters") { | ||
result.forEachIndexed { index, param -> | ||
when (index) { | ||
0 -> param.value shouldBe "b" | ||
1 -> param.value shouldBe "d" | ||
} | ||
} | ||
} | ||
it("makes values accessible by get operator") { | ||
result["a"] shouldBe "b" | ||
result["c"] shouldBe "d" | ||
} | ||
} | ||
describe("zplParameters pairs function") { | ||
val result = zplParameters("e" to "f", "g" to "h") | ||
it("returns values passed to ZplParameters") { | ||
result.forEachIndexed { index, param -> | ||
when (index) { | ||
0 -> param.value shouldBe "f" | ||
1 -> param.value shouldBe "h" | ||
} | ||
} } | ||
it("makes values accessible by get operator") { | ||
result["e"] shouldBe "f" | ||
result["g"] shouldBe "h" | ||
} | ||
} | ||
|
||
describe("ZplParameters builder function") { | ||
val result = zplParameters { | ||
put("a", "b") | ||
put("c", "d") | ||
} | ||
it("returns values passed to ZplParameters") { | ||
result.forEachIndexed { index, param -> | ||
when (index) { | ||
0 -> param.value shouldBe "b" | ||
1 -> param.value shouldBe "d" | ||
} | ||
} | ||
} | ||
it("makes values accessible by get operator") { | ||
result["a"] shouldBe "b" | ||
result["c"] shouldBe "d" | ||
} | ||
} | ||
}) |