Skip to content

Commit 3110a8f

Browse files
committed
✅ add unit tests for Utils.merge functionality
1 parent e838fc2 commit 3110a8f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.github.techouse.qskotlin.unit
33
import io.github.techouse.qskotlin.decode
44
import io.github.techouse.qskotlin.encode
55
import io.github.techouse.qskotlin.enums.ListFormat
6+
import io.github.techouse.qskotlin.internal.Utils
67
import io.github.techouse.qskotlin.models.*
78
import io.kotest.assertions.throwables.shouldNotThrow
89
import io.kotest.core.spec.style.DescribeSpec
@@ -985,4 +986,36 @@ class QsParserSpec :
985986
commaResult shouldContain "a="
986987
}
987988
}
989+
990+
describe("Utils.merge") {
991+
it("should merge with null values") {
992+
Utils.merge(null, listOf(42)) shouldBe listOf(null, 42)
993+
Utils.merge(null, true) shouldBe listOf(null, true)
994+
}
995+
996+
it("should merge maps and arrays") {
997+
val dict1 = mapOf("a" to "b")
998+
val dict2 = mapOf("a" to "c")
999+
val dict3 = mapOf("a" to dict2)
1000+
1001+
Utils.merge(dict1, dict2) shouldBe mapOf("a" to listOf("b", "c"))
1002+
Utils.merge(dict1, dict3) shouldBe mapOf("a" to listOf("b", mapOf("a" to "c")))
1003+
1004+
val d1 = mapOf("foo" to listOf("bar", mapOf("first" to "123")))
1005+
val d2 = mapOf("foo" to mapOf("second" to "456"))
1006+
1007+
val expected1 =
1008+
mapOf(
1009+
"foo" to mapOf(0 to "bar", 1 to mapOf("first" to "123"), "second" to "456")
1010+
)
1011+
Utils.merge(d1, d2) shouldBe expected1
1012+
1013+
val a = mapOf("foo" to listOf("baz"))
1014+
val b = mapOf("foo" to listOf("bar", "xyzz"))
1015+
Utils.merge(a, b) shouldBe mapOf("foo" to listOf("baz", "bar", "xyzz"))
1016+
1017+
val x = mapOf("foo" to "baz")
1018+
Utils.merge(x, "bar") shouldBe mapOf("foo" to "baz", "bar" to true)
1019+
}
1020+
}
9881021
})

0 commit comments

Comments
 (0)