Skip to content

Commit 93c2730

Browse files
Add test case for concat to verify operation flattening and nesting behavior.
1 parent 77e4aff commit 93c2730

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

core/common/test/format/ParserStructureConcatenationTest.kt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,53 @@ import kotlin.test.assertTrue
1515

1616
class ParserStructureConcatenationTest {
1717

18+
@Test
19+
fun concatFlattensOperations() {
20+
val parser = ParserStructure<Int>(
21+
operations = listOf(),
22+
followedBy = listOf(
23+
ParserStructure(
24+
operations = listOf(),
25+
followedBy = listOf(
26+
ParserStructure(
27+
operations = listOf(),
28+
followedBy = listOf(
29+
ParserStructure(
30+
operations = listOf(),
31+
followedBy = listOf(
32+
ParserStructure(
33+
operations = listOf(),
34+
followedBy = listOf(
35+
ParserStructure(
36+
operations = listOf(
37+
NumberSpanParserOperation(listOf(ConstantNumberConsumer("34")))
38+
),
39+
followedBy = listOf()
40+
)
41+
)
42+
)
43+
)
44+
)
45+
)
46+
)
47+
)
48+
)
49+
)
50+
)
51+
52+
val actual = listOf(parser).concat()
53+
54+
with(actual) {
55+
assertTrue(operations.isEmpty())
56+
assertEquals(1, followedBy.size)
57+
with(followedBy[0]) {
58+
assertEquals(1, operations.size)
59+
assertTrue(operations[0] is NumberSpanParserOperation)
60+
assertTrue(followedBy.isEmpty())
61+
}
62+
}
63+
}
64+
1865
@Test
1966
fun concatDistributesTopLevelNumberSpanParserOperationIntoBranches() {
2067
val parser = ParserStructure<Int>(

0 commit comments

Comments
 (0)