@@ -3,6 +3,7 @@ package io.github.techouse.qskotlin.unit
33import io.github.techouse.qskotlin.decode
44import io.github.techouse.qskotlin.encode
55import io.github.techouse.qskotlin.enums.ListFormat
6+ import io.github.techouse.qskotlin.internal.Utils
67import io.github.techouse.qskotlin.models.*
78import io.kotest.assertions.throwables.shouldNotThrow
89import 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