Skip to content

Commit 6cbc168

Browse files
Add ParserStructureConcatenationTest to verify concat behavior and operation distribution
1 parent 5875c72 commit 6cbc168

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2019-2025 JetBrains s.r.o. and contributors.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
6+
package kotlinx.datetime.test.format
7+
8+
import kotlinx.datetime.internal.format.parser.ConstantNumberConsumer
9+
import kotlinx.datetime.internal.format.parser.NumberSpanParserOperation
10+
import kotlinx.datetime.internal.format.parser.ParserStructure
11+
import kotlinx.datetime.internal.format.parser.concat
12+
import kotlin.test.Test
13+
import kotlin.test.assertEquals
14+
import kotlin.test.assertTrue
15+
16+
class ParserStructureConcatenationTest {
17+
18+
@Test
19+
fun concatDistributesTopLevelNumberSpanParserOperationIntoBranches() {
20+
val parser = ParserStructure<Int>(
21+
operations = listOf(
22+
NumberSpanParserOperation(listOf(ConstantNumberConsumer("12")))
23+
),
24+
followedBy = listOf(
25+
ParserStructure(
26+
operations = listOf(
27+
NumberSpanParserOperation(listOf(ConstantNumberConsumer("34")))
28+
),
29+
followedBy = listOf()
30+
),
31+
ParserStructure(
32+
operations = listOf(),
33+
followedBy = listOf()
34+
)
35+
)
36+
)
37+
38+
val actual = listOf(parser).concat()
39+
40+
with(actual) {
41+
assertEquals(0, operations.size)
42+
assertEquals(2, followedBy.size)
43+
with(followedBy[0]) {
44+
assertEquals(0, followedBy.size)
45+
with(operations) {
46+
assertEquals(1, size)
47+
assertTrue(operations[0] is NumberSpanParserOperation)
48+
assertEquals(2, (operations[0] as NumberSpanParserOperation).consumers.size)
49+
}
50+
}
51+
with(followedBy[1]) {
52+
assertEquals(0, followedBy.size)
53+
with(operations) {
54+
assertEquals(1, size)
55+
with(operations) {
56+
assertEquals(1, size)
57+
assertTrue(operations[0] is NumberSpanParserOperation)
58+
assertEquals(1, (operations[0] as NumberSpanParserOperation).consumers.size)
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)