From 1b563a0378998f2fed28bf81b8e254cb47742503 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 3 May 2024 00:02:29 +0200 Subject: Improve paragraph detection --- src/test/kotlin/moe/nea/blog/gen/HtmlTest.kt | 2 +- .../kotlin/moe/nea/blog/md/test/BlockQuoteTest.kt | 6 +++ src/test/kotlin/moe/nea/blog/md/test/ListTest.kt | 22 +++++++++ .../kotlin/moe/nea/blog/md/test/MarkdownTest.kt | 5 ++ .../kotlin/moe/nea/blog/md/test/ParagraphTest.kt | 55 +++++++++++++++++++++- 5 files changed, 87 insertions(+), 3 deletions(-) (limited to 'src/test/kotlin') diff --git a/src/test/kotlin/moe/nea/blog/gen/HtmlTest.kt b/src/test/kotlin/moe/nea/blog/gen/HtmlTest.kt index 439fbeb..cfc8bf8 100644 --- a/src/test/kotlin/moe/nea/blog/gen/HtmlTest.kt +++ b/src/test/kotlin/moe/nea/blog/gen/HtmlTest.kt @@ -13,7 +13,7 @@ class HtmlTest : HtmlGenerationTest() { fun testBiggerFile() { assertGeneratorMD( """ - |

Hello World

lol hehe

public class ObjectControllerFactoryManagerProvider<T extends ObjectControllerFactoryManager<T>> {
+			|

Hello World

lol hehe

public class ObjectControllerFactoryManagerProvider<T extends ObjectControllerFactoryManager<T>> {
 			|   public ObjectControllerFactoryManagerProvider() {}
 			|}
""".trimMargin(), diff --git a/src/test/kotlin/moe/nea/blog/md/test/BlockQuoteTest.kt b/src/test/kotlin/moe/nea/blog/md/test/BlockQuoteTest.kt index 635dd88..c4f7f99 100644 --- a/src/test/kotlin/moe/nea/blog/md/test/BlockQuoteTest.kt +++ b/src/test/kotlin/moe/nea/blog/md/test/BlockQuoteTest.kt @@ -8,9 +8,13 @@ class BlockQuoteTest : MarkdownTest() { assertDocumentFormat( """ +

hi +

+

hello +

""".trimIndent(), @@ -26,7 +30,9 @@ class BlockQuoteTest : MarkdownTest() { assertDocumentFormat( """ +

hi +

fun helloWorld(): Unit = "Hello, World!".let(::println) diff --git a/src/test/kotlin/moe/nea/blog/md/test/ListTest.kt b/src/test/kotlin/moe/nea/blog/md/test/ListTest.kt index 0ac8f1e..241929f 100644 --- a/src/test/kotlin/moe/nea/blog/md/test/ListTest.kt +++ b/src/test/kotlin/moe/nea/blog/md/test/ListTest.kt @@ -7,13 +7,19 @@ class ListTest : MarkdownTest() { fun testBasicList() { assertDocumentFormat( """ +

Some Text: +

+

First +

+

Second +

""".trimIndent(), @@ -28,14 +34,22 @@ class ListTest : MarkdownTest() { fun testBlockContinuation() { assertDocumentFormat( """ +

Some Text: +

+

First More First +

+

Second +

+

More Second +

""".trimIndent(), @@ -53,18 +67,26 @@ class ListTest : MarkdownTest() { fun testNestedLists() { assertDocumentFormat( """ +

Some Text: +

+

First +

+

Another List +

+

Second +

""".trimIndent(), diff --git a/src/test/kotlin/moe/nea/blog/md/test/MarkdownTest.kt b/src/test/kotlin/moe/nea/blog/md/test/MarkdownTest.kt index 3e01acc..f2aef71 100644 --- a/src/test/kotlin/moe/nea/blog/md/test/MarkdownTest.kt +++ b/src/test/kotlin/moe/nea/blog/md/test/MarkdownTest.kt @@ -9,14 +9,19 @@ import kotlin.test.assertEquals abstract class MarkdownTest { + open fun registerExtraParser(parser: MarkdownParser) { + } + fun parseInline(string: String): MarkdownFormat { val parser = MarkdownParser(string) parser.addDefaultParsers() + registerExtraParser(parser) return parser.parseInlineText(string) } fun parseDoc(string: String): Document { val parser = MarkdownParser(string) parser.addDefaultParsers() + registerExtraParser(parser) return parser.readDocument() } diff --git a/src/test/kotlin/moe/nea/blog/md/test/ParagraphTest.kt b/src/test/kotlin/moe/nea/blog/md/test/ParagraphTest.kt index 9e12cfe..19f4552 100644 --- a/src/test/kotlin/moe/nea/blog/md/test/ParagraphTest.kt +++ b/src/test/kotlin/moe/nea/blog/md/test/ParagraphTest.kt @@ -1,15 +1,63 @@ package moe.nea.blog.md.test +import moe.nea.blog.md.MarkdownParser +import moe.nea.blog.md.ext.NoteBlockParser import kotlin.test.Test class ParagraphTest : MarkdownTest() { + override fun registerExtraParser(parser: MarkdownParser) { + parser.addParser(NoteBlockParser) + } + + @Test + fun testNonImmediateParagraph() { + assertDocumentFormat( + """ + | + | + | xor eax, eax + | ret + | + | + | + | + |

+ | Test + |

+ | + | inc eax + | ret + | + |
+ |
+ """.trimMargin(), + """ + |!!! note + | + | ```assembly + | xor eax, eax + | ret + | ``` + | + | - Test + | + | ```assembly + | inc eax + | ret + | ``` + """.trimMargin(), + ) + } @Test fun testParagraph() { assertDocumentFormat(""" + |

|a b - | + |

+ |

|c d + |

""".trimMargin(), """ |a |b @@ -23,9 +71,12 @@ class ParagraphTest : MarkdownTest() { @Test fun testCodeBlock() { assertDocumentFormat(""" + |

|a b - | + |

+ |

|c d + |

| |public static final String TEST = "TEST"; | -- cgit