From ab853a866c40771e84a3235f40575efe04c435c5 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Mon, 1 Mar 2021 12:01:41 +0100 Subject: Add explicit exceptions in markdown and allow for empty link destinations (#1757) --- .../base/src/test/kotlin/markdown/ParserTest.kt | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'plugins/base/src/test/kotlin/markdown') diff --git a/plugins/base/src/test/kotlin/markdown/ParserTest.kt b/plugins/base/src/test/kotlin/markdown/ParserTest.kt index 0fdb10c1..4ac4a43f 100644 --- a/plugins/base/src/test/kotlin/markdown/ParserTest.kt +++ b/plugins/base/src/test/kotlin/markdown/ParserTest.kt @@ -5,6 +5,9 @@ import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.model.doc.* import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import kotlin.test.assertEquals +import kotlin.test.assertTrue class ParserTest : KDocTest() { @@ -1437,5 +1440,46 @@ class ParserTest : KDocTest() { ) executeTest(kdoc, expectedDocumentationNode) } + + @Test + fun `short link without destination`() { + val kdoc = """ + | This is [link]() + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + CustomDocTag( + listOf( + P( + listOf( + Text("This is "), + A( + listOf(Text("link")), + mapOf("href" to "") + ) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test + fun `exception thrown by empty header should point to location of a file`() { + val kdoc = """ + | ### + """.trimMargin() + val expectedDocumentationNode = DocumentationNode(emptyList()) + val exception = runCatching { executeTest(kdoc, expectedDocumentationNode) }.exceptionOrNull() + + assertEquals( + "Wrong AST Tree. Header does not contain expected content in Test.kt/example.Test, element starts from offset 0 and ends 3: ###", + exception?.message + ) + } } -- cgit