@@ -5,6 +5,7 @@ import io.github.techouse.qskotlin.encode
55import io.github.techouse.qskotlin.enums.DecodeKind
66import io.github.techouse.qskotlin.enums.Duplicates
77import io.github.techouse.qskotlin.fixtures.data.EmptyTestCases
8+ import io.github.techouse.qskotlin.internal.Decoder as InternalDecoder
89import io.github.techouse.qskotlin.internal.Utils
910import io.github.techouse.qskotlin.models.DecodeOptions
1011import io.github.techouse.qskotlin.models.Decoder
@@ -1385,4 +1386,79 @@ class DecodeSpec :
13851386 }
13861387 }
13871388 }
1389+
1390+ describe(" splitKeyIntoSegments — remainder wrapping & strictDepth behavior" ) {
1391+ it(" allowDots=true, depth=1: wrap the remainder from the next unprocessed bracket" ) {
1392+ // "a.b.c" -> dot-to-bracket first => "a[b][c]"
1393+ // With maxDepth=1, we collect "[b]" and then wrap the remainder "[c]" as "[[c]]"
1394+ val segs =
1395+ InternalDecoder .splitKeyIntoSegments(
1396+ originalKey = " a.b.c" ,
1397+ allowDots = true ,
1398+ maxDepth = 1 ,
1399+ strictDepth = false ,
1400+ )
1401+ segs shouldBe listOf (" a" , " [b]" , " [[c]]" )
1402+ }
1403+
1404+ it(
1405+ " bracketed input, depth=2: collect two groups, wrap remainder as a single synthetic segment"
1406+ ) {
1407+ // "a[b][c][d]" with maxDepth=2 -> ["a", "[b]", "[c]", "[[d]]"]
1408+ val segs =
1409+ InternalDecoder .splitKeyIntoSegments(
1410+ originalKey = " a[b][c][d]" ,
1411+ allowDots = false ,
1412+ maxDepth = 2 ,
1413+ strictDepth = false ,
1414+ )
1415+ segs shouldBe listOf (" a" , " [b]" , " [c]" , " [[d]]" )
1416+ }
1417+
1418+ it(
1419+ " unterminated bracket group: do not throw even with strictDepth=true; wrap raw remainder"
1420+ ) {
1421+ // Unterminated after first '[': "a[b[c" -> ["a", "[[b[c]"]
1422+ val segs =
1423+ InternalDecoder .splitKeyIntoSegments(
1424+ originalKey = " a[b[c" ,
1425+ allowDots = false ,
1426+ maxDepth = 5 ,
1427+ strictDepth = true ,
1428+ )
1429+ segs shouldBe listOf (" a" , " [[b[c]" )
1430+ }
1431+
1432+ it(" strictDepth=true: well-formed depth overflow raises IndexOutOfBoundsException" ) {
1433+ // Well-formed: "a[b][c][d]" with maxDepth=2 should overflow and throw
1434+ shouldThrow<IndexOutOfBoundsException > {
1435+ InternalDecoder .splitKeyIntoSegments(
1436+ originalKey = " a[b][c][d]" ,
1437+ allowDots = false ,
1438+ maxDepth = 2 ,
1439+ strictDepth = true ,
1440+ )
1441+ }
1442+ }
1443+
1444+ it(" depth=0: never split; return the original key as a single segment" ) {
1445+ val segs1 =
1446+ InternalDecoder .splitKeyIntoSegments(
1447+ originalKey = " a.b.c" ,
1448+ allowDots = true ,
1449+ maxDepth = 0 ,
1450+ strictDepth = false ,
1451+ )
1452+ segs1 shouldBe listOf (" a.b.c" )
1453+
1454+ val segs2 =
1455+ InternalDecoder .splitKeyIntoSegments(
1456+ originalKey = " a[b][c]" ,
1457+ allowDots = false ,
1458+ maxDepth = 0 ,
1459+ strictDepth = false ,
1460+ )
1461+ segs2 shouldBe listOf (" a[b][c]" )
1462+ }
1463+ }
13881464 })
0 commit comments