test: 異種リストのテストを追加2

This commit is contained in:
usbharu 2024-11-17 20:16:46 +09:00
parent ac6c4f132b
commit e53a7cc42e
Signed by: usbharu
GPG Key ID: 95CBCF7046307B77
2 changed files with 42 additions and 1 deletions

View File

@ -78,12 +78,14 @@ class Parser {
} }
val peekOrNull = iterator.peekOrNull() val peekOrNull = iterator.peekOrNull()
if (peekOrNull is Token.List) { if (peekOrNull is Token.List) {
iterator.skip()
if (peekOrNull.type != list.type) { if (peekOrNull.type != list.type) {
if (item.isNotEmpty()) { if (item.isNotEmpty()) {
listItems.add(ListItemNode(item)) listItems.add(ListItemNode(item))
} }
break break
} else {
iterator.skip()
} }
} }

View File

@ -670,4 +670,43 @@ class ParserTest {
), actual ), actual
) )
} }
@Test
fun 異種list() {
val parser = Parser()
val actual = parser.parse(
listOf(
DiscList,
Text("aiueo"),
LineBreak(1),
DiscList,
Text("abcd"),
LineBreak(1),
DecimalList('1'),
Text("efgh"),
LineBreak(1),
DecimalList('1'),
Text("hoge")
)
)
println(actual)
println(actual.print())
assertEquals(
RootNode(
BodyNode(
DiscListNode(
ListItemNode(PlainText("aiueo")),
ListItemNode(PlainText("abcd"))
),
DecimalListNode(
ListItemNode(PlainText("efgh")),
ListItemNode(PlainText("hoge"))
)
)
), actual
)
}
} }