diff options
author | Linnea Gräf <nea@nea.moe> | 2024-03-24 15:54:19 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-03-24 15:54:19 +0100 |
commit | 4c0ac30dc82677b2b2db36d114b452fdea537a37 (patch) | |
tree | d29b45e396fab55ac119298143f4b7abb2cc9c8d /src/test/kotlin/moe | |
parent | be66c61d729fe642e3dd3ed2214990f9f2273c5e (diff) | |
download | blog-infra-4c0ac30dc82677b2b2db36d114b452fdea537a37.tar.gz blog-infra-4c0ac30dc82677b2b2db36d114b452fdea537a37.tar.bz2 blog-infra-4c0ac30dc82677b2b2db36d114b452fdea537a37.zip |
Add italics parsing unit tests
Diffstat (limited to 'src/test/kotlin/moe')
-rw-r--r-- | src/test/kotlin/moe/nea/blog/md/test/TestItalics.kt | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/test/kotlin/moe/nea/blog/md/test/TestItalics.kt b/src/test/kotlin/moe/nea/blog/md/test/TestItalics.kt new file mode 100644 index 0000000..b4b102a --- /dev/null +++ b/src/test/kotlin/moe/nea/blog/md/test/TestItalics.kt @@ -0,0 +1,64 @@ +package moe.nea.blog.md.test + +import moe.nea.blog.md.MarkdownFormat +import moe.nea.blog.md.MarkdownParser +import java.io.ByteArrayOutputStream +import java.io.PrintStream +import kotlin.test.Test +import kotlin.test.assertEquals + +class TestItalics { + + fun parseInline(string: String): MarkdownFormat { + val parser = MarkdownParser(string) + parser.addDefaultParsers() + return parser.parseInlineText(string) + } + + fun assertInlineFormat(expected: String, source: String) { + val format = parseInline(source) + val baos = ByteArrayOutputStream() + format.debugFormat(PrintStream(baos)) + assertEquals(expected, baos.toByteArray().decodeToString()) + } + + @Test + fun testDoubleStartItalicsInBold() { + assertInlineFormat("<b><i>both</i> just bold</b>", "***both* just bold**") + } + + @Test + fun testDoubleStartBoldInItalics() { + assertInlineFormat("<i><b>both</b> just italics</i>", "***both** just italics*") + } + + @Test + fun testDoubleStartRestartingItalics() { + assertInlineFormat( + "<i><b>both</b> just italics <b>both again</b></i>", + "***both** just italics **both again***" + ) + } + + @Test + fun testStandaloneBold() { + assertInlineFormat("<b>bold</b>", "**bold**") + } + + @Test + fun testStandaloneItalics() { + assertInlineFormat("<i>italic</i>", "*italic*") + } + + @Test + fun testInline() { + assertInlineFormat("left <i>italics</i> middle <b>bold</b> right", "left *italics* middle **bold** right") + } + + @Test + fun testNested() { + assertInlineFormat("<i>a <b>bold</b> b</i>", "*a **bold** b*") + assertInlineFormat("<i>a <i>double italics</i></i>", "*a *double italics**") + } + +}
\ No newline at end of file |