Skip to content

Commit e685543

Browse files
committed
✅ add tests for Utils.merge handling iterable maps
1 parent 6481652 commit e685543

File tree

1 file changed

+22
-0
lines changed
  • qs-kotlin/src/test/kotlin/io/github/techouse/qskotlin/unit

1 file changed

+22
-0
lines changed

qs-kotlin/src/test/kotlin/io/github/techouse/qskotlin/unit/UtilsSpec.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,23 @@ class UtilsSpec :
668668
val result = Utils.merge(listOf("a", Undefined()), mapOf("b" to "c"))
669669
result shouldBe mapOf<String, Any?>("0" to "a", "b" to "c")
670670
}
671+
672+
test("merge handles map sources that are also iterable") {
673+
val hybrid = IterableMap(mutableMapOf("x" to "1", "y" to Undefined()))
674+
675+
val folded = Utils.merge("anchor", hybrid)
676+
677+
folded.shouldBeInstanceOf<MutableList<*>>()
678+
folded shouldBe mutableListOf("anchor", "1")
679+
}
680+
681+
test("merge flattens iterable maps into iterable targets") {
682+
val target = IterableMap(mutableMapOf("0" to "keep", "1" to Undefined()))
683+
val merged = Utils.merge(target, mapOf("extra" to "value"))
684+
685+
merged.shouldBeInstanceOf<MutableMap<*, *>>()
686+
merged shouldBe mutableMapOf("0" to "keep", "extra" to "value")
687+
}
671688
}
672689

673690
context("Utils.combine") {
@@ -797,3 +814,8 @@ class UtilsSpec :
797814
private class BoxIterable<T>(private val items: List<T>) : Iterable<T> {
798815
override fun iterator(): Iterator<T> = items.iterator()
799816
}
817+
818+
private class IterableMap(private val delegate: MutableMap<String, Any?>) :
819+
MutableMap<String, Any?> by delegate, Iterable<Any?> {
820+
override fun iterator(): MutableIterator<Any?> = delegate.values.iterator()
821+
}

0 commit comments

Comments
 (0)