summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-03-24 16:34:16 +0100
committerLinnea Gräf <nea@nea.moe>2024-03-24 16:34:16 +0100
commit1cc009627643c6a3636472491825ae0d4a751616 (patch)
tree7efa4ad8bb93555f1f883ed337ca4b0071779b58 /src/test
parent306515545281007d1df8733e3aa2bee974e29123 (diff)
downloadblog-infra-1cc009627643c6a3636472491825ae0d4a751616.tar.gz
blog-infra-1cc009627643c6a3636472491825ae0d4a751616.tar.bz2
blog-infra-1cc009627643c6a3636472491825ae0d4a751616.zip
Add code block test
Diffstat (limited to 'src/test')
-rw-r--r--src/test/kotlin/moe/nea/blog/md/test/CodeBlockTest.kt66
-rw-r--r--src/test/kotlin/moe/nea/blog/md/test/MarkdownTest.kt36
-rw-r--r--src/test/kotlin/moe/nea/blog/md/test/TestItalics.kt20
3 files changed, 103 insertions, 19 deletions
diff --git a/src/test/kotlin/moe/nea/blog/md/test/CodeBlockTest.kt b/src/test/kotlin/moe/nea/blog/md/test/CodeBlockTest.kt
new file mode 100644
index 0000000..3e9bbd8
--- /dev/null
+++ b/src/test/kotlin/moe/nea/blog/md/test/CodeBlockTest.kt
@@ -0,0 +1,66 @@
+package moe.nea.blog.md.test
+
+import kotlin.test.Test
+
+class CodeBlockTest : MarkdownTest() {
+ @Test
+ fun testJavaCodeBlock() {
+ assertDocumentFormat(
+ """
+ <code language=java>
+ public class ObjectControllerFactoryManagerProvider<T extends ObjectControllerFactoryManager<T>> {
+ public void doTheThing() {}
+
+ }
+ </code>
+ """.trimIndent(),
+ """
+ ```java
+ public class ObjectControllerFactoryManagerProvider<T extends ObjectControllerFactoryManager<T>> {
+ public void doTheThing() {}
+
+ }
+ ```
+ """.trimIndent()
+ )
+ }
+ @Test
+ fun testAutoStripCommonIndent() {
+ assertDocumentFormat(
+ """
+ <code language=java>
+ public class ObjectControllerFactoryManagerProvider<T extends ObjectControllerFactoryManager<T>> {
+ public void doTheThing() {}
+ }
+ </code>
+ """.trimIndent(),
+ """
+ ```java
+ public class ObjectControllerFactoryManagerProvider<T extends ObjectControllerFactoryManager<T>> {
+ public void doTheThing() {}
+ }
+ ```
+ """.trimIndent()
+ )
+ }
+
+ @Test
+ fun testNonStrippedBlock() {
+ assertDocumentFormat(
+ """
+ <code language=java>
+ public class ObjectControllerFactoryManagerProvider<T extends ObjectControllerFactoryManager<T>> {
+ public void doTheThing() {}
+ }
+ </code>
+ """.trimIndent(),
+ """
+ ```java notrim
+ public class ObjectControllerFactoryManagerProvider<T extends ObjectControllerFactoryManager<T>> {
+ public void doTheThing() {}
+ }
+ ```
+ """.trimIndent()
+ )
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/moe/nea/blog/md/test/MarkdownTest.kt b/src/test/kotlin/moe/nea/blog/md/test/MarkdownTest.kt
new file mode 100644
index 0000000..3e01acc
--- /dev/null
+++ b/src/test/kotlin/moe/nea/blog/md/test/MarkdownTest.kt
@@ -0,0 +1,36 @@
+package moe.nea.blog.md.test
+
+import moe.nea.blog.md.Document
+import moe.nea.blog.md.MarkdownFormat
+import moe.nea.blog.md.MarkdownParser
+import java.io.ByteArrayOutputStream
+import java.io.PrintStream
+import kotlin.test.assertEquals
+
+abstract class MarkdownTest {
+
+ fun parseInline(string: String): MarkdownFormat {
+ val parser = MarkdownParser(string)
+ parser.addDefaultParsers()
+ return parser.parseInlineText(string)
+ }
+ fun parseDoc(string: String): Document {
+ val parser = MarkdownParser(string)
+ parser.addDefaultParsers()
+ return parser.readDocument()
+ }
+
+ fun assertDocumentFormat(expected: String, source: String) {
+ val format = parseDoc(source)
+ val baos = ByteArrayOutputStream()
+ format.debugFormat(PrintStream(baos))
+ assertEquals(expected.trim(), baos.toByteArray().decodeToString().trim())
+ }
+
+ fun assertInlineFormat(expected: String, source: String) {
+ val format = parseInline(source)
+ val baos = ByteArrayOutputStream()
+ format.debugFormat(PrintStream(baos))
+ assertEquals(expected, baos.toByteArray().decodeToString())
+ }
+} \ No newline at end of file
diff --git a/src/test/kotlin/moe/nea/blog/md/test/TestItalics.kt b/src/test/kotlin/moe/nea/blog/md/test/TestItalics.kt
index 5cd8cb4..673dafb 100644
--- a/src/test/kotlin/moe/nea/blog/md/test/TestItalics.kt
+++ b/src/test/kotlin/moe/nea/blog/md/test/TestItalics.kt
@@ -1,26 +1,8 @@
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())
- }
+class TestItalics : MarkdownTest() {
@Test
fun testDoubleStartItalicsInBold() {