From e53a7cc42ec8d2676a5733f653f082e7b81e66ef Mon Sep 17 00:00:00 2001 From: usbharu Date: Sun, 17 Nov 2024 20:16:46 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E7=95=B0=E7=A8=AE=E3=83=AA=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/dev/usbharu/markdown/Parser.kt | 4 +- .../kotlin/dev/usbharu/markdown/ParserTest.kt | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/library/src/commonMain/kotlin/dev/usbharu/markdown/Parser.kt b/library/src/commonMain/kotlin/dev/usbharu/markdown/Parser.kt index aec00b8..24f6162 100644 --- a/library/src/commonMain/kotlin/dev/usbharu/markdown/Parser.kt +++ b/library/src/commonMain/kotlin/dev/usbharu/markdown/Parser.kt @@ -78,12 +78,14 @@ class Parser { } val peekOrNull = iterator.peekOrNull() if (peekOrNull is Token.List) { - iterator.skip() + if (peekOrNull.type != list.type) { if (item.isNotEmpty()) { listItems.add(ListItemNode(item)) } break + } else { + iterator.skip() } } diff --git a/library/src/commonTest/kotlin/dev/usbharu/markdown/ParserTest.kt b/library/src/commonTest/kotlin/dev/usbharu/markdown/ParserTest.kt index 3cb69b1..0f5c347 100644 --- a/library/src/commonTest/kotlin/dev/usbharu/markdown/ParserTest.kt +++ b/library/src/commonTest/kotlin/dev/usbharu/markdown/ParserTest.kt @@ -670,4 +670,43 @@ class ParserTest { ), 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 + ) + } } \ No newline at end of file