From dd017a44ed7baae83f4f09a92d9691231f424eaa Mon Sep 17 00:00:00 2001 From: BarkingBad <32793002+BarkingBad@users.noreply.github.com> Date: Fri, 13 Dec 2019 14:01:25 +0100 Subject: Add abstract structure for MD/HTML comments and MD parser --- core/src/test/kotlin/markdown/ParserTest.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core/src/test/kotlin/markdown/ParserTest.kt') diff --git a/core/src/test/kotlin/markdown/ParserTest.kt b/core/src/test/kotlin/markdown/ParserTest.kt index b0ec68ff..e5944e17 100644 --- a/core/src/test/kotlin/markdown/ParserTest.kt +++ b/core/src/test/kotlin/markdown/ParserTest.kt @@ -1,17 +1,17 @@ package org.jetbrains.dokka.tests import org.junit.Test -import org.jetbrains.dokka.toTestString -import org.jetbrains.dokka.parseMarkdown +//import org.jetbrains.dokkatoTestString +//import org.jetbrains.dokka.parseMarkdown import org.junit.Ignore @Ignore public class ParserTest { fun runTestFor(text : String) { println("MD: ---") println(text) - val markdownTree = parseMarkdown(text) +// val markdownTree = parseMarkdown(text) println("AST: ---") - println(markdownTree.toTestString()) +// println(markdownTree.toTestString()) println() } -- cgit From 18e28d080792d3f805d8e3c787675712d6b9b7ce Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Wed, 5 Feb 2020 13:54:04 +0100 Subject: Implements tests for MarkdownParser and fixes some bugs related to its --- core/build.gradle.kts | 2 +- core/src/main/kotlin/model/doc/DocTag.kt | 2 +- core/src/main/kotlin/parsers/MarkdownParser.kt | 166 +++- .../factories/DocNodesFromIElementFactory.kt | 5 +- .../parsers/factories/DocNodesFromStringFactory.kt | 2 +- core/src/test/kotlin/markdown/ParserTest.kt | 939 ++++++++++++++++++--- .../main/kotlin/testApi/testRunner/TestRunner.kt | 45 + 7 files changed, 1027 insertions(+), 134 deletions(-) (limited to 'core/src/test/kotlin/markdown/ParserTest.kt') diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 06610a38..e70791f3 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -16,7 +16,7 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version") implementation("org.jsoup:jsoup:1.12.1") implementation("com.google.code.gson:gson:2.8.5") - implementation("org.jetbrains:markdown:0.1.40") + implementation("org.jetbrains:markdown:0.1.41") implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.6.10") testImplementation(project(":testApi")) diff --git a/core/src/main/kotlin/model/doc/DocTag.kt b/core/src/main/kotlin/model/doc/DocTag.kt index 0d8b361a..0224634b 100644 --- a/core/src/main/kotlin/model/doc/DocTag.kt +++ b/core/src/main/kotlin/model/doc/DocTag.kt @@ -93,5 +93,5 @@ class DocumentationLink(children: List = emptyList(), params: Map = emptyList(), params: Map = emptyMap()) : DocTag(children, params) \ No newline at end of file diff --git a/core/src/main/kotlin/parsers/MarkdownParser.kt b/core/src/main/kotlin/parsers/MarkdownParser.kt index 30a507df..ff27dc2e 100644 --- a/core/src/main/kotlin/parsers/MarkdownParser.kt +++ b/core/src/main/kotlin/parsers/MarkdownParser.kt @@ -6,6 +6,7 @@ import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes import org.intellij.markdown.ast.ASTNode import org.intellij.markdown.ast.CompositeASTNode +import org.intellij.markdown.ast.LeafASTNode import org.intellij.markdown.ast.impl.ListItemCompositeNode import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor import org.jetbrains.dokka.analysis.DokkaResolutionFacade @@ -15,7 +16,6 @@ import org.jetbrains.dokka.utilities.DokkaConsoleLogger import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag -import org.jetbrains.kotlin.kdoc.psi.api.KDoc import org.jetbrains.kotlin.kdoc.psi.impl.KDocImpl import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag @@ -26,12 +26,13 @@ class MarkdownParser ( private val declarationDescriptor: DeclarationDescriptor ) : Parser() { - inner class MarkdownVisitor(val text: String) { + inner class MarkdownVisitor(val text: String, val destinationLinksMap: Map) { private fun headersHandler(node: ASTNode): DocTag = DocNodesFromIElementFactory.getInstance( node.type, - visitNode(node.children.find { it.type == MarkdownTokenTypes.ATX_CONTENT }!!).children + visitNode(node.children.find { it.type == MarkdownTokenTypes.ATX_CONTENT } ?: + throw Error("Wrong AST Tree. ATX Header does not contain expected content")).children ) private fun horizontalRulesHandler(node: ASTNode): DocTag = @@ -44,7 +45,8 @@ class MarkdownParser ( ) private fun blockquotesHandler(node: ASTNode): DocTag = - DocNodesFromIElementFactory.getInstance(node.type, children = node.children.drop(1).map { visitNode(it) }) + DocNodesFromIElementFactory.getInstance(node.type, children = node.children + .filterIsInstance().evaluateChildren()) private fun listsHandler(node: ASTNode): DocTag { @@ -68,7 +70,7 @@ class MarkdownParser ( it.type, children = it .children - .drop(1) + .filterIsInstance() .evaluateChildren() ) else @@ -77,34 +79,63 @@ class MarkdownParser ( params = if (node.type == MarkdownElementTypes.ORDERED_LIST) { val listNumberNode = node.children.first().children.first() - mapOf("start" to text.substring(listNumberNode.startOffset, listNumberNode.endOffset).dropLast(2)) + mapOf("start" to text.substring(listNumberNode.startOffset, listNumberNode.endOffset).trim().dropLast(1)) } else emptyMap() ) } - private fun linksHandler(node: ASTNode): DocTag { - val linkNode = node.children.find { it.type == MarkdownElementTypes.LINK_LABEL }!! - val link = text.substring(linkNode.startOffset + 1, linkNode.endOffset - 1) - - val dri: DRI? = if (link.startsWith("http") || link.startsWith("www")) { - null - } else { - resolveKDocLink( - resolutionFacade.resolveSession.bindingContext, - resolutionFacade, - declarationDescriptor, - null, - link.split('.') - ).also { if (it.size > 1) DokkaConsoleLogger.warn("Markdown link resolved more than one element: $it") }.firstOrNull()//.single() - ?.let { DRI.from(it) } + private fun resolveDRI(link: String): DRI? = if (link.startsWith("http") || link.startsWith("www")) { + null + } else { + resolveKDocLink( + resolutionFacade.resolveSession.bindingContext, + resolutionFacade, + declarationDescriptor, + null, + link.split('.') + ).also { if (it.size > 1) throw Error("Markdown link resolved more than one element: $it") }.firstOrNull()//.single() + ?.let { DRI.from(it) } + } - } - val href = mapOf("href" to link) - return when (node.type) { - MarkdownElementTypes.FULL_REFERENCE_LINK -> DocNodesFromIElementFactory.getInstance(node.type, params = href, children = node.children.find { it.type == MarkdownElementTypes.LINK_TEXT }!!.children.drop(1).dropLast(1).evaluateChildren(), dri = dri) - else -> DocNodesFromIElementFactory.getInstance(node.type, params = href, children = listOf(visitNode(linkNode)), dri = dri) - } + private fun referenceLinksHandler(node: ASTNode): DocTag { + val linkLabel = node.children.find { it.type == MarkdownElementTypes.LINK_LABEL } ?: + throw Error("Wrong AST Tree. Reference link does not contain expected content") + val linkText = node.children.findLast { it.type == MarkdownElementTypes.LINK_TEXT } ?: linkLabel + + val linkKey = text.substring(linkLabel.startOffset, linkLabel.endOffset) + + val link = destinationLinksMap[linkKey.toLowerCase()] ?: linkKey + + return linksHandler(linkText, link) + } + + private fun inlineLinksHandler(node: ASTNode): DocTag { + val linkText = node.children.find { it.type == MarkdownElementTypes.LINK_TEXT } ?: + throw Error("Wrong AST Tree. Inline link does not contain expected content") + val linkDestination = node.children.find { it.type == MarkdownElementTypes.LINK_DESTINATION } ?: + throw Error("Wrong AST Tree. Inline link does not contain expected content") + val linkTitle = node.children.find { it.type == MarkdownElementTypes.LINK_TITLE } + + val link = text.substring(linkDestination.startOffset, linkDestination.endOffset) + + return linksHandler(linkText, link, linkTitle) + } + + private fun autoLinksHandler(node: ASTNode): DocTag { + val link = text.substring(node.startOffset + 1, node.endOffset - 1) + + return linksHandler(node, link) + } + + private fun linksHandler(linkText: ASTNode, link: String, linkTitle: ASTNode? = null): DocTag { + val dri: DRI? = resolveDRI(link) + val params = if(linkTitle == null) + mapOf("href" to link) + else + mapOf("href" to link, "title" to text.substring(linkTitle.startOffset + 1, linkTitle.endOffset - 1)) + + return DocNodesFromIElementFactory.getInstance(MarkdownElementTypes.INLINE_LINK, params = params, children = linkText.children.drop(1).dropLast(1).evaluateChildren(), dri = dri) } private fun imagesHandler(node: ASTNode): DocTag { @@ -132,8 +163,11 @@ class MarkdownParser ( node.type, children = node .children - .filter { it.type == MarkdownTokenTypes.CODE_FENCE_CONTENT } - .map { visitNode(it) }, + .let { listOf(Text( body = text.substring( + it.find { it.type == MarkdownTokenTypes.CODE_FENCE_CONTENT }?.startOffset ?: 0, + it.findLast { it.type == MarkdownTokenTypes.CODE_FENCE_CONTENT }?.endOffset ?: 0 //TODO: Problem with empty code fence + )) + ) }, params = node .children .find { it.type == MarkdownTokenTypes.FENCE_LANG } @@ -161,7 +195,9 @@ class MarkdownParser ( MarkdownElementTypes.STRONG, MarkdownElementTypes.EMPH -> emphasisHandler(node) MarkdownElementTypes.FULL_REFERENCE_LINK, - MarkdownElementTypes.SHORT_REFERENCE_LINK -> linksHandler(node) + MarkdownElementTypes.SHORT_REFERENCE_LINK -> referenceLinksHandler(node) + MarkdownElementTypes.INLINE_LINK -> inlineLinksHandler(node) + MarkdownElementTypes.AUTOLINK -> autoLinksHandler(node) MarkdownElementTypes.BLOCK_QUOTE -> blockquotesHandler(node) MarkdownElementTypes.UNORDERED_LIST, MarkdownElementTypes.ORDERED_LIST -> listsHandler(node) @@ -171,20 +207,84 @@ class MarkdownParser ( MarkdownElementTypes.IMAGE -> imagesHandler(node) MarkdownTokenTypes.CODE_FENCE_CONTENT, MarkdownTokenTypes.CODE_LINE, - MarkdownTokenTypes.TEXT -> DocNodesFromIElementFactory.getInstance(MarkdownTokenTypes.TEXT, body = text.substring(node.startOffset, node.endOffset)) + MarkdownTokenTypes.TEXT -> DocNodesFromIElementFactory.getInstance( + MarkdownTokenTypes.TEXT, + body = text + .substring(node.startOffset, node.endOffset).transform() + ) + MarkdownElementTypes.MARKDOWN_FILE -> if(node.children.size == 1) visitNode(node.children.first()) else defaultHandler(node) else -> defaultHandler(node) } private fun List.evaluateChildren(): List = - this.filter { it is CompositeASTNode || it.type == MarkdownTokenTypes.TEXT }.map { visitNode(it) } + this.removeUselessTokens().mergeLeafASTNodes().map { visitNode(it) } + + private fun List.removeUselessTokens(): List = + this.filterIndexed { index, _ -> + !(this[index].type == MarkdownTokenTypes.EOL && + this.isLeaf(index - 1) && this.getOrNull(index - 1)?.type !in leafNodes && + this.isLeaf(index + 1) && this.getOrNull(index + 1)?.type !in leafNodes) && + this[index].type != MarkdownElementTypes.LINK_DEFINITION + } + + private val notLeafNodes = listOf(MarkdownTokenTypes.HORIZONTAL_RULE) + private val leafNodes = listOf(MarkdownElementTypes.STRONG, MarkdownElementTypes.EMPH) + + private fun List.isLeaf(index: Int): Boolean = + if(index in 0..this.lastIndex) + (this[index] is CompositeASTNode)|| this[index].type in notLeafNodes + else + false + + private fun List.mergeLeafASTNodes(): List { + val children: MutableList = mutableListOf() + var index = 0 + while(index <= this.lastIndex) { + if(this.isLeaf(index)) { + children += this[index] + } + else { + val startOffset = this[index].startOffset + while(index < this.lastIndex) { + if(this.isLeaf(index + 1)) { + val endOffset = this[index].endOffset + if(text.substring(startOffset, endOffset).transform().isNotEmpty()) + children += LeafASTNode(MarkdownTokenTypes.TEXT, startOffset, endOffset) + break + } + index++ + } + if(index == this.lastIndex) { + val endOffset = this[index].endOffset + if(text.substring(startOffset, endOffset).transform().isNotEmpty()) + children += LeafASTNode(MarkdownTokenTypes.TEXT, startOffset, endOffset) + } + } + index++ + } + return children + } + + private fun String.transform() = this + .replace(Regex("\n\n+"), "") + .replace(Regex("\n>+ "), "\n") } + + private fun getAllDestinationLinks(text: String, node: ASTNode): List> = + node.children + .filter { it.type == MarkdownElementTypes.LINK_DEFINITION } + .map { text.substring(it.children[0].startOffset, it.children[0].endOffset).toLowerCase() to + text.substring(it.children[2].startOffset, it.children[2].endOffset) } + + node.children.filterIsInstance().flatMap { getAllDestinationLinks(text, it) } + + private fun markdownToDocNode(text: String): DocTag { val flavourDescriptor = CommonMarkFlavourDescriptor() val markdownAstRoot: ASTNode = IntellijMarkdownParser(flavourDescriptor).buildMarkdownTreeFromString(text) - return MarkdownVisitor(text).visitNode(markdownAstRoot) + return MarkdownVisitor(text, getAllDestinationLinks(text, markdownAstRoot).toMap()).visitNode(markdownAstRoot) } override fun parseStringToDocNode(extractedString: String) = markdownToDocNode(extractedString) diff --git a/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt b/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt index 1a302176..b899679d 100644 --- a/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt +++ b/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt @@ -11,7 +11,8 @@ object DocNodesFromIElementFactory { fun getInstance(type: IElementType, children: List = emptyList(), params: Map = emptyMap(), body: String? = null, dri: DRI? = null) = when(type) { MarkdownElementTypes.SHORT_REFERENCE_LINK, - MarkdownElementTypes.FULL_REFERENCE_LINK -> if(dri == null) A(children, params) else DocumentationLink(children, params, dri) + MarkdownElementTypes.FULL_REFERENCE_LINK, + MarkdownElementTypes.INLINE_LINK -> if(dri == null) A(children, params) else DocumentationLink(children, params, dri) MarkdownElementTypes.STRONG -> B(children, params) MarkdownElementTypes.BLOCK_QUOTE -> BlockQuote(children, params) MarkdownElementTypes.CODE_SPAN, @@ -30,7 +31,7 @@ object DocNodesFromIElementFactory { MarkdownElementTypes.UNORDERED_LIST -> Ul(children, params) MarkdownElementTypes.PARAGRAPH -> P(children, params) MarkdownTokenTypes.TEXT -> Text(children, params, body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!")) - MarkdownTokenTypes.HORIZONTAL_RULE -> HorizontalRule() + MarkdownTokenTypes.HORIZONTAL_RULE -> HorizontalRule else -> CustomDocTag(children, params) } } \ No newline at end of file diff --git a/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt b/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt index 6090cdb4..dc74ecc1 100644 --- a/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt +++ b/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt @@ -70,7 +70,7 @@ object DocNodesFromStringFactory { "ul" -> Ul(children, params) "var" -> Var(children, params) "documentationlink" -> DocumentationLink(children, params, dri ?: throw NullPointerException("DRI cannot be passed null while constructing documentation link!")) - "hr" -> HorizontalRule() + "hr" -> HorizontalRule else -> CustomDocTag(children, params) } } \ No newline at end of file diff --git a/core/src/test/kotlin/markdown/ParserTest.kt b/core/src/test/kotlin/markdown/ParserTest.kt index e5944e17..77ccd769 100644 --- a/core/src/test/kotlin/markdown/ParserTest.kt +++ b/core/src/test/kotlin/markdown/ParserTest.kt @@ -1,154 +1,901 @@ package org.jetbrains.dokka.tests -import org.junit.Test -//import org.jetbrains.dokkatoTestString -//import org.jetbrains.dokka.parseMarkdown +import org.jetbrains.dokka.model.doc.* import org.junit.Ignore +import org.junit.Test +import testApi.testRunner.AbstractKDocTest + + +class ParserTest : AbstractKDocTest() { -@Ignore public class ParserTest { - fun runTestFor(text : String) { - println("MD: ---") - println(text) -// val markdownTree = parseMarkdown(text) - println("AST: ---") -// println(markdownTree.toTestString()) - println() + @Test fun `Simple text`() { + val kdoc = """ + | This is simple test of string + | Next line + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text(body = "This is simple test of string\nNext line"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun text() { - runTestFor("text") + @Test fun `Text with Bold and Emphasis decorators`() { + val kdoc = """ + | This is **simple** test of _string_ + | Next **_line_** + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P( + listOf( + Text(body = "This is "), + B(listOf(Text(body = "simple"))), + Text(body = " test of "), + I(listOf(Text(body = "string"))), + Text(body = "\nNext "), + B(listOf(I(listOf(Text(body = "line"))))) + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun textWithSpaces() { - runTestFor("text and string") + @Test fun `Text with Colon`() { + val kdoc = """ + | This is simple text with: colon! + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text(body = "This is simple text with: colon!"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun textWithColon() { - runTestFor("text and string: cool!") + @Test fun `Multilined text`() { + val kdoc = """ + | Text + | and + | String + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text(body = "Text\nand\nString"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun link() { - runTestFor("text [links]") + @Test fun `Paragraphs`() { + val kdoc = """ + | Paragraph number + | one + | + | Paragraph + | number two + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P( + listOf( + P(listOf(Text(body = "Paragraph number\none"))), + P(listOf(Text(body = "Paragraph\nnumber two"))) + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun linkWithHref() { - runTestFor("text [links](http://google.com)") + @Test fun `Emphasis with star`() { + val kdoc = "*text*" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(I(listOf(Text(body = "text"))))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun multiline() { - runTestFor( - """ -text -and -string -""") + @Test fun `Underscores that are not Emphasis`() { + val kdoc = "text_with_underscores" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text(body = "text_with_underscores"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun para() { - runTestFor( - """ -paragraph number -one + @Test fun `Emphasis with underscores`() { + val kdoc = "_text_" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(I(listOf(Text(body = "text"))))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } -paragraph -number two -""") + @Test fun `Embedded star`() { + val kdoc = "Embedded*Star" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text(body = "Embedded*Star"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun bulletList() { - runTestFor( - """* list item 1 -* list item 2 -""") + + @Test fun `Unordered list`() { + val kdoc = """ + | * list item 1 + | * list item 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ul( + listOf( + Li(listOf(P(listOf(Text(body = "list item 1"))))), + Li(listOf(P(listOf(Text(body = "list item 2"))))) + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun bulletListWithLines() { - runTestFor( - """ -* list item 1 - continue 1 -* list item 2 - continue 2 - """) + @Test fun `Unordered list with multilines`() { + val kdoc = """ + | * list item 1 + | continue 1 + | * list item 2 + | continue 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ul( + listOf( + Li(listOf(P(listOf(Text(body = "list item 1\ncontinue 1"))))), + Li(listOf(P(listOf(Text(body = "list item 2\ncontinue 2"))))) + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun bulletListStrong() { - runTestFor( - """ -* list *item* 1 - continue 1 -* list *item* 2 - continue 2 - """) + @Test fun `Unordered list with Bold`() { + val kdoc = """ + | * list **item** 1 + | continue 1 + | * list __item__ 2 + | continue 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ul(listOf( + Li(listOf(P(listOf( + Text(body = "list "), + B(listOf(Text(body = "item"))), + Text(body = " 1\ncontinue 1") + )))), + Li(listOf(P(listOf( + Text(body = "list "), + B(listOf(Text(body = "item"))), + Text(body = " 2\ncontinue 2") + )))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun emph() { - runTestFor("*text*") + @Test fun `Unordered list with nested bullets`() { + val kdoc = """ + | * Outer first + | Outer next line + | * Outer second + | - Middle first + | Middle next line + | - Middle second + | + Inner first + | Inner next line + | - Middle third + | * Outer third + | + | New paragraph""".trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Ul(listOf( + Li(listOf(P(listOf(Text(body = "Outer first\nOuter next line"))))), + Li(listOf(P(listOf(Text(body = "Outer second"))))), + Ul(listOf( + Li(listOf(P(listOf(Text(body = "Middle first\nMiddle next line"))))), + Li(listOf(P(listOf(Text(body = "Middle second"))))), + Ul(listOf( + Li(listOf(P(listOf(Text(body = "Inner first\nInner next line"))))) + )), + Li(listOf(P(listOf(Text(body = "Middle third"))))) + )), + Li(listOf(P(listOf(Text(body = "Outer third"))))) + )), + P(listOf(Text(body = "New paragraph"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun underscoresNoEmph() { - runTestFor("text_with_underscores") + @Test fun `Ordered list`() { + val kdoc = """ + | 1. list item 1 + | 2. list item 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ol( + listOf( + Li(listOf(P(listOf(Text(body = "list item 1"))))), + Li(listOf(P(listOf(Text(body = "list item 2"))))) + ), + mapOf("start" to "1") + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun emphUnderscores() { - runTestFor("_text_") + + @Test fun `Ordered list beginning from other number`() { + val kdoc = """ + | 9. list item 1 + | 12. list item 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ol( + listOf( + Li(listOf(P(listOf(Text(body = "list item 1"))))), + Li(listOf(P(listOf(Text(body = "list item 2"))))) + ), + mapOf("start" to "9") + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun singleStar() { - runTestFor("Embedded*Star") + @Test fun `Ordered list with multilines`() { + val kdoc = """ + | 2. list item 1 + | continue 1 + | 3. list item 2 + | continue 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ol( + listOf( + Li(listOf(P(listOf(Text(body = "list item 1\ncontinue 1"))))), + Li(listOf(P(listOf(Text(body = "list item 2\ncontinue 2"))))) + ), + mapOf("start" to "2") + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun directive() { - runTestFor("A text \${code with.another.value} with directive") + @Test fun `Ordered list with Bold`() { + val kdoc = """ + | 1. list **item** 1 + | continue 1 + | 2. list __item__ 2 + | continue 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ol(listOf( + Li(listOf(P(listOf( + Text(body = "list "), + B(listOf(Text(body = "item"))), + Text(body = " 1\ncontinue 1") + )))), + Li(listOf(P(listOf( + Text(body = "list "), + B(listOf(Text(body = "item"))), + Text(body = " 2\ncontinue 2") + )))) + ), + mapOf("start" to "1") + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun emphAndEmptySection() { - runTestFor("*text*\n\$sec:\n") + @Test fun `Ordered list with nested bullets`() { + val kdoc = """ + | 1. Outer first + | Outer next line + | 2. Outer second + | 1. Middle first + | Middle next line + | 2. Middle second + | 1. Inner first + | Inner next line + | 5. Middle third + | 4. Outer third + | + | New paragraph""".trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Ol(listOf( + Li(listOf(P(listOf(Text(body = "Outer first\nOuter next line"))))), + Li(listOf(P(listOf(Text(body = "Outer second"))))), + Ol(listOf( + Li(listOf(P(listOf(Text(body = "Middle first\nMiddle next line"))))), + Li(listOf(P(listOf(Text(body = "Middle second"))))), + Ol(listOf( + Li(listOf(P(listOf(Text(body = "Inner first\nInner next line"))))) + ), + mapOf("start" to "1") + ), + Li(listOf(P(listOf(Text(body = "Middle third"))))) + ), + mapOf("start" to "1") + ), + Li(listOf(P(listOf(Text(body = "Outer third"))))) + ), + mapOf("start" to "1") + ), + P(listOf(Text(body = "New paragraph"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun emphAndSection() { - runTestFor("*text*\n\$sec: some text\n") + @Test fun `Ordered nested in Unordered nested in Ordered list`() { + val kdoc = """ + | 1. Outer first + | Outer next line + | 2. Outer second + | + Middle first + | Middle next line + | + Middle second + | 1. Inner first + | Inner next line + | + Middle third + | 4. Outer third + | + | New paragraph""".trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Ol(listOf( + Li(listOf(P(listOf(Text(body = "Outer first\nOuter next line"))))), + Li(listOf(P(listOf(Text(body = "Outer second"))))), + Ul(listOf( + Li(listOf(P(listOf(Text(body = "Middle first\nMiddle next line"))))), + Li(listOf(P(listOf(Text(body = "Middle second"))))), + Ol(listOf( + Li(listOf(P(listOf(Text(body = "Inner first\nInner next line"))))) + ), + mapOf("start" to "1") + ), + Li(listOf(P(listOf(Text(body = "Middle third"))))) + )), + Li(listOf(P(listOf(Text(body = "Outer third"))))) + ), + mapOf("start" to "1") + ), + P(listOf(Text(body = "New paragraph"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun emphAndBracedSection() { - runTestFor("Text *bold* text \n\${sec}: some text") + @Test fun `Header and two paragraphs`() { + val kdoc = """ + | # Header 1 + | Following text + | + | New paragraph + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + H1(listOf(Text(body = "Header 1"))), + P(listOf(Text(body = "Following text"))), + P(listOf(Text(body = "New paragraph"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun section() { - runTestFor( - "Plain text \n\$one: Summary \n\${two}: Description with *emphasis* \n\${An example of a section}: Example") + @Ignore //TODO: ATX_2 to ATX_6 and sometimes ATX_1 from jetbrains parser consumes white space. Need to handle it in their library + @Test fun `All headers`() { + val kdoc = """ + | # Header 1 + | Text 1 + | ## Header 2 + | Text 2 + | ### Header 3 + | Text 3 + | #### Header 4 + | Text 4 + | ##### Header 5 + | Text 5 + | ###### Header 6 + | Text 6 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + H1(listOf(Text(body = "Header 1"))), + P(listOf(Text(body = "Text 1"))), + H2(listOf(Text(body = "Header 2"))), + P(listOf(Text(body = "Text 2"))), + H3(listOf(Text(body = "Header 3"))), + P(listOf(Text(body = "Text 3"))), + H4(listOf(Text(body = "Header 4"))), + P(listOf(Text(body = "Text 4"))), + H5(listOf(Text(body = "Header 5"))), + P(listOf(Text(body = "Text 5"))), + H6(listOf(Text(body = "Header 6"))), + P(listOf(Text(body = "Text 6"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun anonymousSection() { - runTestFor("Summary\n\nDescription\n") + @Test fun `Bold New Line Bold`() { + val kdoc = """ + | **line 1** + | **line 2** + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + B(listOf(Text(body = "line 1"))), + Text(body = "\n"), + B(listOf(Text(body = "line 2"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun specialSection() { - runTestFor( - "Plain text \n\$\$summary: Summary \n\${\$description}: Description \n\${\$An example of a section}: Example") + @Test fun `Horizontal rule`() { + val kdoc = """ + | *** + | text 1 + | ___ + | text 2 + | *** + | text 3 + | ___ + | text 4 + | *** + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + HorizontalRule, + P(listOf(Text(body = "text 1"))), + HorizontalRule, + P(listOf(Text(body = "text 2"))), + HorizontalRule, + P(listOf(Text(body = "text 3"))), + HorizontalRule, + P(listOf(Text(body = "text 4"))), + HorizontalRule + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - @Test fun emptySection() { - runTestFor( - "Plain text \n\$summary:") + @Test fun `Blockquote`() { + val kdoc = """ + | > Blockquotes are very handy in email to emulate reply text. + | > This line is part of the same quote. + | + | Quote break. + | + | > Quote + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + BlockQuote(listOf( + P(listOf(Text(body = "Blockquotes are very handy in email to emulate reply text.\nThis line is part of the same quote."))) + )), + P(listOf(Text(body = "Quote break."))), + BlockQuote(listOf( + P(listOf(Text(body = "Quote"))) + )) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } - val b = "$" - @Test fun pair() { - runTestFor( - """Represents a generic pair of two values. -There is no meaning attached to values in this class, it can be used for any purpose. -Pair exhibits value semantics, i.e. two pairs are equal if both components are equal. + @Test fun `Blockquote nested`() { + val kdoc = """ + | > text 1 + | > text 2 + | >> text 3 + | >> text 4 + | > + | > text 5 + | + | Quote break. + | + | > Quote + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + BlockQuote(listOf( + P(listOf(Text(body = "text 1\ntext 2"))), + BlockQuote(listOf( + P(listOf(Text(body = "text 3\ntext 4"))) + )), + P(listOf(Text(body = "text 5"))) + )), + P(listOf(Text(body = "Quote break."))), + BlockQuote(listOf( + P(listOf(Text(body = "Quote"))) + )) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Ignore //TODO: Again ATX_1 consumes white space + @Test fun `Blockquote nested with fancy text enhancement`() { + val kdoc = """ + | > text **1** + | > text 2 + | >> # text 3 + | >> * text 4 + | >> * text 5 + | > + | > text 6 + | + | Quote break. + | + | > Quote + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + BlockQuote(listOf( + P(listOf( + Text(body = "text "), + B(listOf(Text(body = "1"))), + Text(body = "\ntext 2") + )), + BlockQuote(listOf( + H1(listOf(Text(body = "text 3"))), + Ul(listOf( + Li(listOf(P(listOf(Text(body = "text 4"))))), + Ul(listOf( + Li(listOf(P(listOf(Text(body = "text 5"))))) + ) + ))) + )), + P(listOf(Text(body = "text 6"))) + )), + P(listOf(Text(body = "Quote break."))), + BlockQuote(listOf( + P(listOf(Text(body = "Quote"))) + )) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } -An example of decomposing it into values: -${b}{code test.tuples.PairTest.pairMultiAssignment} + @Test fun `Simple Code Block`() { + val kdoc = """ + | `Some code` + | Sample text + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Code(listOf(Text(body = "Some code"))), + Text(body = "\nSample text") + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } -${b}constructor: Creates new instance of [Pair] -${b}first: First value -${b}second: Second value"""" - ) + @Test fun `Multilined Code Block`() { + val kdoc = """ + | ```kotlin + | val x: Int = 0 + | val y: String = "Text" + | + | val z: Boolean = true + | for(i in 0..10) { + | println(i) + | } + | ``` + | Sample text + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Code( + listOf( + Text(body = "val x: Int = 0\nval y: String = \"Text\"\n\n val z: Boolean = true\n" + + "for(i in 0..10) {\n println(i)\n}") + ), + mapOf("lang" to "kotlin") + ), + P(listOf(Text(body = "Sample text"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) } + + @Test fun `Inline link`() { + val kdoc = """ + | [I'm an inline-style link](https://www.google.com) + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(A( + listOf(Text(body = "I'm an inline-style link")), + mapOf("href" to "https://www.google.com") + ))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Inline link with title`() { + val kdoc = """ + | [I'm an inline-style link with title](https://www.google.com "Google's Homepage") + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(A( + listOf(Text(body = "I'm an inline-style link with title")), + mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") + ))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Full reference link`() { + val kdoc = """ + | [I'm a reference-style link][Arbitrary case-insensitive reference text] + | + | [arbitrary case-insensitive reference text]: https://www.mozilla.org + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(P(listOf(A( + listOf(Text(body = "I'm a reference-style link")), + mapOf("href" to "https://www.mozilla.org") + ))))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Full reference link with number`() { + val kdoc = """ + | [You can use numbers for reference-style link definitions][1] + | + | [1]: http://slashdot.org + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(P(listOf(A( + listOf(Text(body = "You can use numbers for reference-style link definitions")), + mapOf("href" to "http://slashdot.org") + ))))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Short reference link`() { + val kdoc = """ + | Or leave it empty and use the [link text itself]. + | + | [link text itself]: http://www.reddit.com + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(P(listOf( + Text(body = "Or leave it empty and use the "), + A( + listOf(Text(body = "link text itself")), + mapOf("href" to "http://www.reddit.com") + ), + Text(body = ".") + )))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Autolink`() { + val kdoc = """ + | URLs and URLs in angle brackets will automatically get turned into links. + | http://www.example.com or and sometimes + | example.com (but not on Github, for example). + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Text(body = "URLs and URLs in angle brackets will automatically get turned into links.\nhttp://www.example.com or "), + A( + listOf(Text(body = "http://www.example.com")), + mapOf("href" to "http://www.example.com") + ), + Text(body = " and sometimes\nexample.com (but not on Github, for example).") + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Various links`() { + val kdoc = """ + | [I'm an inline-style link](https://www.google.com) + | + | [I'm an inline-style link with title](https://www.google.com "Google's Homepage") + | + | [I'm a reference-style link][Arbitrary case-insensitive reference text] + | + | [You can use numbers for reference-style link definitions][1] + | + | Or leave it empty and use the [link text itself]. + | + | URLs and URLs in angle brackets will automatically get turned into links. + | http://www.example.com or and sometimes + | example.com (but not on Github, for example). + | + | Some text to show that the reference links can follow later. + | + | [arbitrary case-insensitive reference text]: https://www.mozilla.org + | [1]: http://slashdot.org + | [link text itself]: http://www.reddit.com + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + P(listOf(A( + listOf(Text(body = "I'm an inline-style link")), + mapOf("href" to "https://www.google.com") + ))), + P(listOf(A( + listOf(Text(body = "I'm an inline-style link with title")), + mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") + ))), + P(listOf(A( + listOf(Text(body = "I'm a reference-style link")), + mapOf("href" to "https://www.mozilla.org") + ))), + P(listOf(A( + listOf(Text(body = "You can use numbers for reference-style link definitions")), + mapOf("href" to "http://slashdot.org") + ))), + P(listOf( + Text(body = "Or leave it empty and use the "), + A( + listOf(Text(body = "link text itself")), + mapOf("href" to "http://www.reddit.com") + ), + Text(body = ".") + )), + P(listOf( + Text(body = "URLs and URLs in angle brackets will automatically get turned into links.\nhttp://www.example.com or "), + A( + listOf(Text(body = "http://www.example.com")), + mapOf("href" to "http://www.example.com") + ), + Text(body = " and sometimes\nexample.com (but not on Github, for example).") + )), + P(listOf(Text(body = "Some text to show that the reference links can follow later."))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } } diff --git a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt index b8817918..f906755a 100644 --- a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt @@ -2,12 +2,15 @@ package testApi.testRunner import org.jetbrains.dokka.* import org.jetbrains.dokka.model.Module +import org.jetbrains.dokka.model.Package +import org.jetbrains.dokka.model.doc.DocumentationNode import org.jetbrains.dokka.pages.ModulePageNode import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.utilities.DokkaConsoleLogger +import org.junit.Assert import org.junit.rules.TemporaryFolder import java.io.File import java.nio.charset.Charset @@ -200,6 +203,48 @@ abstract class AbstractCoreTest { } } +abstract class AbstractKDocTest : AbstractCoreTest() { + + private val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/example/Test.kt") + } + } + } + + private fun interpolateKdoc(kdoc: String) = """ + |/src/main/kotlin/example/Test.kt + |package example + | /** + ${kdoc.split("\n").joinToString("") { "| * $it\n" } } + | */ + |class Test + """.trimMargin() + + private fun actualDocumentationNode(modulePageNode: ModulePageNode) = + (modulePageNode.documentable?.children?.first() as Package) + .classlikes.first() + .platformInfo.first() + .documentationNode + + + protected fun executeTest(kdoc: String, expectedDocumentationNode: DocumentationNode) { + testInline( + interpolateKdoc(kdoc), + configuration + ) { + pagesGenerationStage = { + Assert.assertEquals( + expectedDocumentationNode, + actualDocumentationNode(it) + ) + } + } + } +} + + data class TestMethods( val analysisSetupStage: (Map) -> Unit, val pluginsSetupStage: (DokkaContext) -> Unit, -- cgit From 2d9f0753bb925f6a6d08ab7e67d5676c196de7d0 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Mon, 10 Feb 2020 17:05:11 +0100 Subject: Adds requested changes --- core/src/main/kotlin/parsers/MarkdownParser.kt | 31 +++++++------- core/src/test/kotlin/markdown/KDocTest.kt | 48 ++++++++++++++++++++++ core/src/test/kotlin/markdown/ParserTest.kt | 18 +++++++- .../main/kotlin/testApi/testRunner/TestRunner.kt | 42 ------------------- 4 files changed, 81 insertions(+), 58 deletions(-) create mode 100644 core/src/test/kotlin/markdown/KDocTest.kt (limited to 'core/src/test/kotlin/markdown/ParserTest.kt') diff --git a/core/src/main/kotlin/parsers/MarkdownParser.kt b/core/src/main/kotlin/parsers/MarkdownParser.kt index ff27dc2e..4f4a7e18 100644 --- a/core/src/main/kotlin/parsers/MarkdownParser.kt +++ b/core/src/main/kotlin/parsers/MarkdownParser.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag import org.jetbrains.kotlin.kdoc.psi.impl.KDocImpl import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag +import java.net.MalformedURLException import org.intellij.markdown.parser.MarkdownParser as IntellijMarkdownParser class MarkdownParser ( @@ -85,18 +86,20 @@ class MarkdownParser ( ) } - private fun resolveDRI(link: String): DRI? = if (link.startsWith("http") || link.startsWith("www")) { - null - } else { - resolveKDocLink( - resolutionFacade.resolveSession.bindingContext, - resolutionFacade, - declarationDescriptor, - null, - link.split('.') - ).also { if (it.size > 1) throw Error("Markdown link resolved more than one element: $it") }.firstOrNull()//.single() - ?.let { DRI.from(it) } - } + private fun resolveDRI(link: String): DRI? = + try { + java.net.URL(link) + null + } catch(e: MalformedURLException) { + resolveKDocLink( + resolutionFacade.resolveSession.bindingContext, + resolutionFacade, + declarationDescriptor, + null, + link.split('.') + ).also { if (it.size > 1) throw Error("Markdown link resolved more than one element: $it") }.firstOrNull()//.single() + ?.let { DRI.from(it) } + } private fun referenceLinksHandler(node: ASTNode): DocTag { val linkLabel = node.children.find { it.type == MarkdownElementTypes.LINK_LABEL } ?: @@ -266,8 +269,8 @@ class MarkdownParser ( } private fun String.transform() = this - .replace(Regex("\n\n+"), "") - .replace(Regex("\n>+ "), "\n") + .replace(Regex("\n\n+"), "") // Squashing new lines between paragraphs + .replace(Regex("\n>+ "), "\n") // Replacement used in blockquotes, get rid of garbage } diff --git a/core/src/test/kotlin/markdown/KDocTest.kt b/core/src/test/kotlin/markdown/KDocTest.kt new file mode 100644 index 00000000..c084154b --- /dev/null +++ b/core/src/test/kotlin/markdown/KDocTest.kt @@ -0,0 +1,48 @@ +package markdown + +import org.jetbrains.dokka.model.Package +import org.jetbrains.dokka.model.doc.DocumentationNode +import org.jetbrains.dokka.pages.ModulePageNode +import org.junit.Assert +import testApi.testRunner.AbstractCoreTest + +open class KDocTest : AbstractCoreTest() { + + private val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/example/Test.kt") + } + } + } + + private fun interpolateKdoc(kdoc: String) = """ + |/src/main/kotlin/example/Test.kt + |package example + | /** + ${kdoc.split("\n").joinToString("") { "| * $it\n" } } + | */ + |class Test + """.trimMargin() + + private fun actualDocumentationNode(modulePageNode: ModulePageNode) = + (modulePageNode.documentable?.children?.first() as Package) + .classlikes.first() + .platformInfo.first() + .documentationNode + + + protected fun executeTest(kdoc: String, expectedDocumentationNode: DocumentationNode) { + testInline( + interpolateKdoc(kdoc), + configuration + ) { + pagesGenerationStage = { + Assert.assertEquals( + expectedDocumentationNode, + actualDocumentationNode(it) + ) + } + } + } +} \ No newline at end of file diff --git a/core/src/test/kotlin/markdown/ParserTest.kt b/core/src/test/kotlin/markdown/ParserTest.kt index 77ccd769..107940f6 100644 --- a/core/src/test/kotlin/markdown/ParserTest.kt +++ b/core/src/test/kotlin/markdown/ParserTest.kt @@ -1,12 +1,12 @@ package org.jetbrains.dokka.tests +import markdown.KDocTest import org.jetbrains.dokka.model.doc.* import org.junit.Ignore import org.junit.Test -import testApi.testRunner.AbstractKDocTest -class ParserTest : AbstractKDocTest() { +class ParserTest : KDocTest() { @Test fun `Simple text`() { val kdoc = """ @@ -897,5 +897,19 @@ class ParserTest : AbstractKDocTest() { ) executeTest(kdoc, expectedDocumentationNode) } + + @Test fun `Windows Carriage Return Line Feed`() { + val kdoc = "text\r\ntext" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Text(body = "text\ntext") + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } } diff --git a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt index f906755a..edeedf10 100644 --- a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt @@ -203,48 +203,6 @@ abstract class AbstractCoreTest { } } -abstract class AbstractKDocTest : AbstractCoreTest() { - - private val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/main/kotlin/example/Test.kt") - } - } - } - - private fun interpolateKdoc(kdoc: String) = """ - |/src/main/kotlin/example/Test.kt - |package example - | /** - ${kdoc.split("\n").joinToString("") { "| * $it\n" } } - | */ - |class Test - """.trimMargin() - - private fun actualDocumentationNode(modulePageNode: ModulePageNode) = - (modulePageNode.documentable?.children?.first() as Package) - .classlikes.first() - .platformInfo.first() - .documentationNode - - - protected fun executeTest(kdoc: String, expectedDocumentationNode: DocumentationNode) { - testInline( - interpolateKdoc(kdoc), - configuration - ) { - pagesGenerationStage = { - Assert.assertEquals( - expectedDocumentationNode, - actualDocumentationNode(it) - ) - } - } - } -} - - data class TestMethods( val analysisSetupStage: (Map) -> Unit, val pluginsSetupStage: (DokkaContext) -> Unit, -- cgit From 193d8259c234c3b73d4f89f10aa0e2cdfc217e6c Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Tue, 11 Feb 2020 15:24:54 +0100 Subject: Removes unnecessary white space --- core/src/test/kotlin/markdown/KDocTest.kt | 2 +- core/src/test/kotlin/markdown/ParserTest.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'core/src/test/kotlin/markdown/ParserTest.kt') diff --git a/core/src/test/kotlin/markdown/KDocTest.kt b/core/src/test/kotlin/markdown/KDocTest.kt index c084154b..c58c4e30 100644 --- a/core/src/test/kotlin/markdown/KDocTest.kt +++ b/core/src/test/kotlin/markdown/KDocTest.kt @@ -20,7 +20,7 @@ open class KDocTest : AbstractCoreTest() { |/src/main/kotlin/example/Test.kt |package example | /** - ${kdoc.split("\n").joinToString("") { "| * $it\n" } } + ${kdoc.split("\n").joinToString("") { "| *$it\n" } } | */ |class Test """.trimMargin() diff --git a/core/src/test/kotlin/markdown/ParserTest.kt b/core/src/test/kotlin/markdown/ParserTest.kt index 107940f6..35b004e7 100644 --- a/core/src/test/kotlin/markdown/ParserTest.kt +++ b/core/src/test/kotlin/markdown/ParserTest.kt @@ -101,7 +101,7 @@ class ParserTest : KDocTest() { } @Test fun `Emphasis with star`() { - val kdoc = "*text*" + val kdoc = " *text*" val expectedDocumentationNode = DocumentationNode( listOf( Description( -- cgit From 135a3118cf9d08bb50ff0c438b60508ecf1994c6 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Wed, 12 Feb 2020 14:22:11 +0100 Subject: Added Br handling --- core/src/main/kotlin/model/doc/DocTag.kt | 5 +- core/src/main/kotlin/parsers/MarkdownParser.kt | 49 ++-- .../factories/DocNodesFromIElementFactory.kt | 5 +- .../parsers/factories/DocNodesFromStringFactory.kt | 9 +- core/src/test/kotlin/markdown/ParserTest.kt | 285 +++++++++++---------- 5 files changed, 193 insertions(+), 160 deletions(-) (limited to 'core/src/test/kotlin/markdown/ParserTest.kt') diff --git a/core/src/main/kotlin/model/doc/DocTag.kt b/core/src/main/kotlin/model/doc/DocTag.kt index 0224634b..94558ca7 100644 --- a/core/src/main/kotlin/model/doc/DocTag.kt +++ b/core/src/main/kotlin/model/doc/DocTag.kt @@ -28,6 +28,7 @@ class A(children: List = emptyList(), params: Map = empt class Big(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) class B(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) class BlockQuote(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +object Br : DocTag(emptyList(), emptyMap()) class Cite(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) class Code(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) class Dd(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) @@ -74,7 +75,7 @@ class Strong(children: List = emptyList(), params: Map = class Sub(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) class Sup(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) class Table(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) -class Text(children: List = emptyList(), params: Map = emptyMap(), val body: String = "") : DocTag(children, params) { +class Text(val body: String = "", children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) { override fun equals(other: Any?): Boolean = super.equals(other) && this.body == (other as Text).body override fun hashCode(): Int = super.hashCode() + body.hashCode() } @@ -89,7 +90,7 @@ class Tt(children: List = emptyList(), params: Map = emp class U(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) class Ul(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) class Var(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) -class DocumentationLink(children: List = emptyList(), params: Map = emptyMap(), val dri: DRI) : DocTag(children, params) { +class DocumentationLink(val dri: DRI, children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) { override fun equals(other: Any?): Boolean = super.equals(other) && this.dri == (other as DocumentationLink).dri override fun hashCode(): Int = super.hashCode() + dri.hashCode() } diff --git a/core/src/main/kotlin/parsers/MarkdownParser.kt b/core/src/main/kotlin/parsers/MarkdownParser.kt index 4f4a7e18..d70a2239 100644 --- a/core/src/main/kotlin/parsers/MarkdownParser.kt +++ b/core/src/main/kotlin/parsers/MarkdownParser.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka.parsers import com.intellij.psi.PsiElement +import org.intellij.markdown.IElementType +import org.intellij.markdown.MarkdownElementType import org.jetbrains.dokka.model.doc.* import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes @@ -47,7 +49,8 @@ class MarkdownParser ( private fun blockquotesHandler(node: ASTNode): DocTag = DocNodesFromIElementFactory.getInstance(node.type, children = node.children - .filterIsInstance().evaluateChildren()) + .filterIsInstance() + .evaluateChildren()) private fun listsHandler(node: ASTNode): DocTag { @@ -166,11 +169,14 @@ class MarkdownParser ( node.type, children = node .children - .let { listOf(Text( body = text.substring( - it.find { it.type == MarkdownTokenTypes.CODE_FENCE_CONTENT }?.startOffset ?: 0, - it.findLast { it.type == MarkdownTokenTypes.CODE_FENCE_CONTENT }?.endOffset ?: 0 //TODO: Problem with empty code fence - )) - ) }, + .dropWhile { it.type != MarkdownTokenTypes.CODE_FENCE_CONTENT } + .dropLastWhile { it.type != MarkdownTokenTypes.CODE_FENCE_CONTENT } + .map { + if(it.type == MarkdownTokenTypes.EOL) + LeafASTNode(MarkdownTokenTypes.HARD_LINE_BREAK, 0, 0) + else + it + }.evaluateChildren(), params = node .children .find { it.type == MarkdownTokenTypes.FENCE_LANG } @@ -208,6 +214,7 @@ class MarkdownParser ( MarkdownElementTypes.CODE_FENCE -> codeFencesHandler(node) MarkdownElementTypes.CODE_SPAN -> codeSpansHandler(node) MarkdownElementTypes.IMAGE -> imagesHandler(node) + MarkdownTokenTypes.HARD_LINE_BREAK -> DocNodesFromIElementFactory.getInstance(node.type) MarkdownTokenTypes.CODE_FENCE_CONTENT, MarkdownTokenTypes.CODE_LINE, MarkdownTokenTypes.TEXT -> DocNodesFromIElementFactory.getInstance( @@ -223,19 +230,16 @@ class MarkdownParser ( this.removeUselessTokens().mergeLeafASTNodes().map { visitNode(it) } private fun List.removeUselessTokens(): List = - this.filterIndexed { index, _ -> - !(this[index].type == MarkdownTokenTypes.EOL && - this.isLeaf(index - 1) && this.getOrNull(index - 1)?.type !in leafNodes && - this.isLeaf(index + 1) && this.getOrNull(index + 1)?.type !in leafNodes) && - this[index].type != MarkdownElementTypes.LINK_DEFINITION - } + this.filterIndexed { index, node -> !(node.type == MarkdownElementTypes.LINK_DEFINITION || ( + node.type == MarkdownTokenTypes.EOL && + this.getOrNull(index - 1)?.type == MarkdownTokenTypes.HARD_LINE_BREAK + )) } - private val notLeafNodes = listOf(MarkdownTokenTypes.HORIZONTAL_RULE) - private val leafNodes = listOf(MarkdownElementTypes.STRONG, MarkdownElementTypes.EMPH) + private val notLeafNodes = listOf(MarkdownTokenTypes.HORIZONTAL_RULE, MarkdownTokenTypes.HARD_LINE_BREAK) - private fun List.isLeaf(index: Int): Boolean = + private fun List.isNotLeaf(index: Int): Boolean = if(index in 0..this.lastIndex) - (this[index] is CompositeASTNode)|| this[index].type in notLeafNodes + (this[index] is CompositeASTNode) || this[index].type in notLeafNodes else false @@ -243,15 +247,15 @@ class MarkdownParser ( val children: MutableList = mutableListOf() var index = 0 while(index <= this.lastIndex) { - if(this.isLeaf(index)) { + if(this.isNotLeaf(index)) { children += this[index] } else { val startOffset = this[index].startOffset - while(index < this.lastIndex) { - if(this.isLeaf(index + 1)) { + while(index < this.lastIndex ) { + if(this.isNotLeaf(index + 1) || this[index+1].startOffset != this[index].endOffset) { val endOffset = this[index].endOffset - if(text.substring(startOffset, endOffset).transform().isNotEmpty()) + if(text.substring(startOffset, endOffset).transform().trim().isNotEmpty()) children += LeafASTNode(MarkdownTokenTypes.TEXT, startOffset, endOffset) break } @@ -259,7 +263,7 @@ class MarkdownParser ( } if(index == this.lastIndex) { val endOffset = this[index].endOffset - if(text.substring(startOffset, endOffset).transform().isNotEmpty()) + if(text.substring(startOffset, endOffset).transform().trim().isNotEmpty()) children += LeafASTNode(MarkdownTokenTypes.TEXT, startOffset, endOffset) } } @@ -270,7 +274,8 @@ class MarkdownParser ( private fun String.transform() = this .replace(Regex("\n\n+"), "") // Squashing new lines between paragraphs - .replace(Regex("\n>+ "), "\n") // Replacement used in blockquotes, get rid of garbage + .replace(Regex("\n"), " ") + .replace(Regex(" >+ +"), " ") // Replacement used in blockquotes, get rid of garbage } diff --git a/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt b/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt index b899679d..d4c6e752 100644 --- a/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt +++ b/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt @@ -12,7 +12,7 @@ object DocNodesFromIElementFactory { when(type) { MarkdownElementTypes.SHORT_REFERENCE_LINK, MarkdownElementTypes.FULL_REFERENCE_LINK, - MarkdownElementTypes.INLINE_LINK -> if(dri == null) A(children, params) else DocumentationLink(children, params, dri) + MarkdownElementTypes.INLINE_LINK -> if(dri == null) A(children, params) else DocumentationLink(dri, children, params) MarkdownElementTypes.STRONG -> B(children, params) MarkdownElementTypes.BLOCK_QUOTE -> BlockQuote(children, params) MarkdownElementTypes.CODE_SPAN, @@ -30,8 +30,9 @@ object DocNodesFromIElementFactory { MarkdownElementTypes.ORDERED_LIST -> Ol(children, params) MarkdownElementTypes.UNORDERED_LIST -> Ul(children, params) MarkdownElementTypes.PARAGRAPH -> P(children, params) - MarkdownTokenTypes.TEXT -> Text(children, params, body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!")) + MarkdownTokenTypes.TEXT -> Text(body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!"), children, params ) MarkdownTokenTypes.HORIZONTAL_RULE -> HorizontalRule + MarkdownTokenTypes.HARD_LINE_BREAK -> Br else -> CustomDocTag(children, params) } } \ No newline at end of file diff --git a/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt b/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt index dc74ecc1..4ff9a9d4 100644 --- a/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt +++ b/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt @@ -11,8 +11,9 @@ object DocNodesFromStringFactory { "big" -> Big(children, params) "b" -> B(children, params) "blockquote" -> BlockQuote(children, params) - "bite" -> Cite(children, params) - "bode" -> Code(children, params) + "br" -> Br + "cite" -> Cite(children, params) + "code" -> Code(children, params) "dd" -> Dd(children, params) "dfn" -> Dfn(children, params) "dir" -> Dir(children, params) @@ -57,7 +58,7 @@ object DocNodesFromStringFactory { "sub" -> Sub(children, params) "sup" -> Sup(children, params) "table" -> Table(children, params) - "#text" -> Text(children, params, body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!")) + "#text" -> Text(body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!"), children, params) "tBody" -> TBody(children, params) "td" -> Td(children, params) "tFoot" -> TFoot(children, params) @@ -69,7 +70,7 @@ object DocNodesFromStringFactory { "u" -> U(children, params) "ul" -> Ul(children, params) "var" -> Var(children, params) - "documentationlink" -> DocumentationLink(children, params, dri ?: throw NullPointerException("DRI cannot be passed null while constructing documentation link!")) + "documentationlink" -> DocumentationLink(dri ?: throw NullPointerException("DRI cannot be passed null while constructing documentation link!"), children, params) "hr" -> HorizontalRule else -> CustomDocTag(children, params) } diff --git a/core/src/test/kotlin/markdown/ParserTest.kt b/core/src/test/kotlin/markdown/ParserTest.kt index 35b004e7..dee8e907 100644 --- a/core/src/test/kotlin/markdown/ParserTest.kt +++ b/core/src/test/kotlin/markdown/ParserTest.kt @@ -16,7 +16,26 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "This is simple test of string\nNext line"))) + P(listOf(Text("This is simple test of string Next line"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Simple text with new line`() { + val kdoc = """ + | This is simple test of string\ + | Next line + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Text("This is simple test of string"), + Br, + Text("Next line") + )) ) ) ) @@ -33,12 +52,12 @@ class ParserTest : KDocTest() { Description( P( listOf( - Text(body = "This is "), - B(listOf(Text(body = "simple"))), - Text(body = " test of "), - I(listOf(Text(body = "string"))), - Text(body = "\nNext "), - B(listOf(I(listOf(Text(body = "line"))))) + Text("This is "), + B(listOf(Text("simple"))), + Text(" test of "), + I(listOf(Text("string"))), + Text(" Next "), + B(listOf(I(listOf(Text("line"))))) ) ) ) @@ -54,7 +73,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "This is simple text with: colon!"))) + P(listOf(Text("This is simple text with: colon!"))) ) ) ) @@ -70,7 +89,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "Text\nand\nString"))) + P(listOf(Text("Text and String"))) ) ) ) @@ -82,7 +101,7 @@ class ParserTest : KDocTest() { | Paragraph number | one | - | Paragraph + | Paragraph\ | number two """.trimMargin() val expectedDocumentationNode = DocumentationNode( @@ -90,8 +109,8 @@ class ParserTest : KDocTest() { Description( P( listOf( - P(listOf(Text(body = "Paragraph number\none"))), - P(listOf(Text(body = "Paragraph\nnumber two"))) + P(listOf(Text("Paragraph number one"))), + P(listOf(Text("Paragraph"), Br, Text("number two"))) ) ) ) @@ -105,7 +124,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(I(listOf(Text(body = "text"))))) + P(listOf(I(listOf(Text("text"))))) ) ) ) @@ -117,7 +136,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "text_with_underscores"))) + P(listOf(Text("text_with_underscores"))) ) ) ) @@ -129,7 +148,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(I(listOf(Text(body = "text"))))) + P(listOf(I(listOf(Text("text"))))) ) ) ) @@ -141,7 +160,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "Embedded*Star"))) + P(listOf(Text("Embedded*Star"))) ) ) ) @@ -159,8 +178,8 @@ class ParserTest : KDocTest() { Description( Ul( listOf( - Li(listOf(P(listOf(Text(body = "list item 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2"))))) + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) ) ) ) @@ -173,7 +192,7 @@ class ParserTest : KDocTest() { val kdoc = """ | * list item 1 | continue 1 - | * list item 2 + | * list item 2\ | continue 2 """.trimMargin() val expectedDocumentationNode = DocumentationNode( @@ -181,8 +200,8 @@ class ParserTest : KDocTest() { Description( Ul( listOf( - Li(listOf(P(listOf(Text(body = "list item 1\ncontinue 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2\ncontinue 2"))))) + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2"), Br, Text("continue 2"))))) ) ) ) @@ -203,14 +222,14 @@ class ParserTest : KDocTest() { Description( Ul(listOf( Li(listOf(P(listOf( - Text(body = "list "), - B(listOf(Text(body = "item"))), - Text(body = " 1\ncontinue 1") + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") )))), Li(listOf(P(listOf( - Text(body = "list "), - B(listOf(Text(body = "item"))), - Text(body = " 2\ncontinue 2") + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") )))) )) ) @@ -238,19 +257,19 @@ class ParserTest : KDocTest() { Description( P(listOf( Ul(listOf( - Li(listOf(P(listOf(Text(body = "Outer first\nOuter next line"))))), - Li(listOf(P(listOf(Text(body = "Outer second"))))), + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "Middle first\nMiddle next line"))))), - Li(listOf(P(listOf(Text(body = "Middle second"))))), + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "Inner first\nInner next line"))))) + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) )), - Li(listOf(P(listOf(Text(body = "Middle third"))))) + Li(listOf(P(listOf(Text("Middle third"))))) )), - Li(listOf(P(listOf(Text(body = "Outer third"))))) + Li(listOf(P(listOf(Text("Outer third"))))) )), - P(listOf(Text(body = "New paragraph"))) + P(listOf(Text("New paragraph"))) )) ) ) @@ -268,8 +287,8 @@ class ParserTest : KDocTest() { Description( Ol( listOf( - Li(listOf(P(listOf(Text(body = "list item 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2"))))) + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) ), mapOf("start" to "1") ) @@ -290,8 +309,8 @@ class ParserTest : KDocTest() { Description( Ol( listOf( - Li(listOf(P(listOf(Text(body = "list item 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2"))))) + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) ), mapOf("start" to "9") ) @@ -313,8 +332,8 @@ class ParserTest : KDocTest() { Description( Ol( listOf( - Li(listOf(P(listOf(Text(body = "list item 1\ncontinue 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2\ncontinue 2"))))) + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2 continue 2"))))) ), mapOf("start" to "2") ) @@ -336,14 +355,14 @@ class ParserTest : KDocTest() { Description( Ol(listOf( Li(listOf(P(listOf( - Text(body = "list "), - B(listOf(Text(body = "item"))), - Text(body = " 1\ncontinue 1") + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") )))), Li(listOf(P(listOf( - Text(body = "list "), - B(listOf(Text(body = "item"))), - Text(body = " 2\ncontinue 2") + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") )))) ), mapOf("start" to "1") @@ -373,25 +392,25 @@ class ParserTest : KDocTest() { Description( P(listOf( Ol(listOf( - Li(listOf(P(listOf(Text(body = "Outer first\nOuter next line"))))), - Li(listOf(P(listOf(Text(body = "Outer second"))))), + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), Ol(listOf( - Li(listOf(P(listOf(Text(body = "Middle first\nMiddle next line"))))), - Li(listOf(P(listOf(Text(body = "Middle second"))))), + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), Ol(listOf( - Li(listOf(P(listOf(Text(body = "Inner first\nInner next line"))))) + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) ), mapOf("start" to "1") ), - Li(listOf(P(listOf(Text(body = "Middle third"))))) + Li(listOf(P(listOf(Text("Middle third"))))) ), mapOf("start" to "1") ), - Li(listOf(P(listOf(Text(body = "Outer third"))))) + Li(listOf(P(listOf(Text("Outer third"))))) ), mapOf("start" to "1") ), - P(listOf(Text(body = "New paragraph"))) + P(listOf(Text("New paragraph"))) )) ) ) @@ -418,23 +437,23 @@ class ParserTest : KDocTest() { Description( P(listOf( Ol(listOf( - Li(listOf(P(listOf(Text(body = "Outer first\nOuter next line"))))), - Li(listOf(P(listOf(Text(body = "Outer second"))))), + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "Middle first\nMiddle next line"))))), - Li(listOf(P(listOf(Text(body = "Middle second"))))), + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), Ol(listOf( - Li(listOf(P(listOf(Text(body = "Inner first\nInner next line"))))) + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) ), mapOf("start" to "1") ), - Li(listOf(P(listOf(Text(body = "Middle third"))))) + Li(listOf(P(listOf(Text("Middle third"))))) )), - Li(listOf(P(listOf(Text(body = "Outer third"))))) + Li(listOf(P(listOf(Text("Outer third"))))) ), mapOf("start" to "1") ), - P(listOf(Text(body = "New paragraph"))) + P(listOf(Text("New paragraph"))) )) ) ) @@ -453,9 +472,9 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - H1(listOf(Text(body = "Header 1"))), - P(listOf(Text(body = "Following text"))), - P(listOf(Text(body = "New paragraph"))) + H1(listOf(Text("Header 1"))), + P(listOf(Text("Following text"))), + P(listOf(Text("New paragraph"))) )) ) ) @@ -483,18 +502,18 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - H1(listOf(Text(body = "Header 1"))), - P(listOf(Text(body = "Text 1"))), - H2(listOf(Text(body = "Header 2"))), - P(listOf(Text(body = "Text 2"))), - H3(listOf(Text(body = "Header 3"))), - P(listOf(Text(body = "Text 3"))), - H4(listOf(Text(body = "Header 4"))), - P(listOf(Text(body = "Text 4"))), - H5(listOf(Text(body = "Header 5"))), - P(listOf(Text(body = "Text 5"))), - H6(listOf(Text(body = "Header 6"))), - P(listOf(Text(body = "Text 6"))) + H1(listOf(Text("Header 1"))), + P(listOf(Text("Text 1"))), + H2(listOf(Text("Header 2"))), + P(listOf(Text("Text 2"))), + H3(listOf(Text("Header 3"))), + P(listOf(Text("Text 3"))), + H4(listOf(Text("Header 4"))), + P(listOf(Text("Text 4"))), + H5(listOf(Text("Header 5"))), + P(listOf(Text("Text 5"))), + H6(listOf(Text("Header 6"))), + P(listOf(Text("Text 6"))) )) ) ) @@ -504,16 +523,16 @@ class ParserTest : KDocTest() { @Test fun `Bold New Line Bold`() { val kdoc = """ - | **line 1** + | **line 1**\ | **line 2** """.trimMargin() val expectedDocumentationNode = DocumentationNode( listOf( Description( P(listOf( - B(listOf(Text(body = "line 1"))), - Text(body = "\n"), - B(listOf(Text(body = "line 2"))) + B(listOf(Text("line 1"))), + Br, + B(listOf(Text("line 2"))) )) ) ) @@ -538,13 +557,13 @@ class ParserTest : KDocTest() { Description( P(listOf( HorizontalRule, - P(listOf(Text(body = "text 1"))), + P(listOf(Text("text 1"))), HorizontalRule, - P(listOf(Text(body = "text 2"))), + P(listOf(Text("text 2"))), HorizontalRule, - P(listOf(Text(body = "text 3"))), + P(listOf(Text("text 3"))), HorizontalRule, - P(listOf(Text(body = "text 4"))), + P(listOf(Text("text 4"))), HorizontalRule )) ) @@ -567,11 +586,13 @@ class ParserTest : KDocTest() { Description( P(listOf( BlockQuote(listOf( - P(listOf(Text(body = "Blockquotes are very handy in email to emulate reply text.\nThis line is part of the same quote."))) + P(listOf( + Text("Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.") + )) )), - P(listOf(Text(body = "Quote break."))), + P(listOf(Text("Quote break."))), BlockQuote(listOf( - P(listOf(Text(body = "Quote"))) + P(listOf(Text("Quote"))) )) )) ) @@ -599,15 +620,15 @@ class ParserTest : KDocTest() { Description( P(listOf( BlockQuote(listOf( - P(listOf(Text(body = "text 1\ntext 2"))), + P(listOf(Text("text 1 text 2"))), BlockQuote(listOf( - P(listOf(Text(body = "text 3\ntext 4"))) + P(listOf(Text("text 3 text 4"))) )), - P(listOf(Text(body = "text 5"))) + P(listOf(Text("text 5"))) )), - P(listOf(Text(body = "Quote break."))), + P(listOf(Text("Quote break."))), BlockQuote(listOf( - P(listOf(Text(body = "Quote"))) + P(listOf(Text("Quote"))) )) )) ) @@ -637,24 +658,24 @@ class ParserTest : KDocTest() { P(listOf( BlockQuote(listOf( P(listOf( - Text(body = "text "), - B(listOf(Text(body = "1"))), - Text(body = "\ntext 2") + Text("text "), + B(listOf(Text("1"))), + Text("\ntext 2") )), BlockQuote(listOf( - H1(listOf(Text(body = "text 3"))), + H1(listOf(Text("text 3"))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "text 4"))))), + Li(listOf(P(listOf(Text("text 4"))))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "text 5"))))) + Li(listOf(P(listOf(Text("text 5"))))) ) ))) )), - P(listOf(Text(body = "text 6"))) + P(listOf(Text("text 6"))) )), - P(listOf(Text(body = "Quote break."))), + P(listOf(Text("Quote break."))), BlockQuote(listOf( - P(listOf(Text(body = "Quote"))) + P(listOf(Text("Quote"))) )) )) ) @@ -672,8 +693,8 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - Code(listOf(Text(body = "Some code"))), - Text(body = "\nSample text") + Code(listOf(Text("Some code"))), + Text(" Sample text") )) ) ) @@ -700,12 +721,16 @@ class ParserTest : KDocTest() { P(listOf( Code( listOf( - Text(body = "val x: Int = 0\nval y: String = \"Text\"\n\n val z: Boolean = true\n" + - "for(i in 0..10) {\n println(i)\n}") + Text("val x: Int = 0"), Br, + Text("val y: String = \"Text\""), Br, Br, + Text(" val z: Boolean = true"), Br, + Text("for(i in 0..10) {"), Br, + Text(" println(i)"), Br, + Text("}") ), mapOf("lang" to "kotlin") ), - P(listOf(Text(body = "Sample text"))) + P(listOf(Text("Sample text"))) )) ) ) @@ -722,7 +747,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(A( - listOf(Text(body = "I'm an inline-style link")), + listOf(Text("I'm an inline-style link")), mapOf("href" to "https://www.google.com") ))) ) @@ -739,7 +764,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(A( - listOf(Text(body = "I'm an inline-style link with title")), + listOf(Text("I'm an inline-style link with title")), mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") ))) ) @@ -758,7 +783,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(P(listOf(A( - listOf(Text(body = "I'm a reference-style link")), + listOf(Text("I'm a reference-style link")), mapOf("href" to "https://www.mozilla.org") ))))) ) @@ -777,7 +802,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(P(listOf(A( - listOf(Text(body = "You can use numbers for reference-style link definitions")), + listOf(Text("You can use numbers for reference-style link definitions")), mapOf("href" to "http://slashdot.org") ))))) ) @@ -796,12 +821,12 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(P(listOf( - Text(body = "Or leave it empty and use the "), + Text("Or leave it empty and use the "), A( - listOf(Text(body = "link text itself")), + listOf(Text("link text itself")), mapOf("href" to "http://www.reddit.com") ), - Text(body = ".") + Text(".") )))) ) ) @@ -819,12 +844,12 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - Text(body = "URLs and URLs in angle brackets will automatically get turned into links.\nhttp://www.example.com or "), + Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), A( - listOf(Text(body = "http://www.example.com")), + listOf(Text("http://www.example.com")), mapOf("href" to "http://www.example.com") ), - Text(body = " and sometimes\nexample.com (but not on Github, for example).") + Text(" and sometimes example.com (but not on Github, for example).") )) ) ) @@ -859,38 +884,38 @@ class ParserTest : KDocTest() { Description( P(listOf( P(listOf(A( - listOf(Text(body = "I'm an inline-style link")), + listOf(Text("I'm an inline-style link")), mapOf("href" to "https://www.google.com") ))), P(listOf(A( - listOf(Text(body = "I'm an inline-style link with title")), + listOf(Text("I'm an inline-style link with title")), mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") ))), P(listOf(A( - listOf(Text(body = "I'm a reference-style link")), + listOf(Text("I'm a reference-style link")), mapOf("href" to "https://www.mozilla.org") ))), P(listOf(A( - listOf(Text(body = "You can use numbers for reference-style link definitions")), + listOf(Text("You can use numbers for reference-style link definitions")), mapOf("href" to "http://slashdot.org") ))), P(listOf( - Text(body = "Or leave it empty and use the "), + Text("Or leave it empty and use the "), A( - listOf(Text(body = "link text itself")), + listOf(Text("link text itself")), mapOf("href" to "http://www.reddit.com") ), - Text(body = ".") + Text(".") )), P(listOf( - Text(body = "URLs and URLs in angle brackets will automatically get turned into links.\nhttp://www.example.com or "), + Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), A( - listOf(Text(body = "http://www.example.com")), + listOf(Text("http://www.example.com")), mapOf("href" to "http://www.example.com") ), - Text(body = " and sometimes\nexample.com (but not on Github, for example).") + Text(" and sometimes example.com (but not on Github, for example).") )), - P(listOf(Text(body = "Some text to show that the reference links can follow later."))) + P(listOf(Text("Some text to show that the reference links can follow later."))) )) ) ) @@ -904,7 +929,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - Text(body = "text\ntext") + Text("text text") )) ) ) -- cgit From 46b4bbb68ce1285a1aea700cc0d0000c6b7ed97b Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Wed, 12 Feb 2020 18:05:24 +0100 Subject: Moves all core tests to base plugin --- core/src/test/kotlin/basic/DRITest.kt | 168 ---- core/src/test/kotlin/basic/DokkaBasicTests.kt | 41 - core/src/test/kotlin/enums/EnumsTest.kt | 45 - core/src/test/kotlin/markdown/KDocTest.kt | 48 -- core/src/test/kotlin/markdown/ParserTest.kt | 940 --------------------- .../kotlin/multiplatform/BasicMultiplatformTest.kt | 55 -- .../test/kotlin/pageMerger/PageNodeMergerTest.kt | 127 --- .../commonMain/kotlin/Clock.kt | 15 - .../commonMain/kotlin/House.kt | 24 - .../basicMultiplatformTest/jsMain/kotlin/Clock.kt | 21 - .../jvmAndJsSecondCommonMain/kotlin/Greeter.kt | 10 - .../jvmMain/kotlin/example/Clock.kt | 34 - .../jvmMain/kotlin/example/ClockDays.kt | 15 - .../jvmMain/kotlin/example/ParticularClock.kt | 32 - plugins/base/src/test/kotlin/basic/DRITest.kt | 168 ++++ .../base/src/test/kotlin/basic/DokkaBasicTests.kt | 41 + plugins/base/src/test/kotlin/enums/EnumsTest.kt | 45 + plugins/base/src/test/kotlin/markdown/KDocTest.kt | 48 ++ .../base/src/test/kotlin/markdown/ParserTest.kt | 940 +++++++++++++++++++++ .../kotlin/multiplatform/BasicMultiplatformTest.kt | 55 ++ .../test/kotlin/pageMerger/PageNodeMergerTest.kt | 127 +++ .../commonMain/kotlin/Clock.kt | 15 + .../commonMain/kotlin/House.kt | 24 + .../basicMultiplatformTest/jsMain/kotlin/Clock.kt | 21 + .../jvmAndJsSecondCommonMain/kotlin/Greeter.kt | 10 + .../jvmMain/kotlin/example/Clock.kt | 34 + .../jvmMain/kotlin/example/ClockDays.kt | 15 + .../jvmMain/kotlin/example/ParticularClock.kt | 32 + plugins/build.gradle.kts | 5 +- 29 files changed, 1578 insertions(+), 1577 deletions(-) delete mode 100644 core/src/test/kotlin/basic/DRITest.kt delete mode 100644 core/src/test/kotlin/basic/DokkaBasicTests.kt delete mode 100644 core/src/test/kotlin/enums/EnumsTest.kt delete mode 100644 core/src/test/kotlin/markdown/KDocTest.kt delete mode 100644 core/src/test/kotlin/markdown/ParserTest.kt delete mode 100644 core/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt delete mode 100644 core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt delete mode 100644 core/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt delete mode 100644 core/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt delete mode 100644 core/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt delete mode 100644 core/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt delete mode 100644 core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt delete mode 100644 core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt delete mode 100644 core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt create mode 100644 plugins/base/src/test/kotlin/basic/DRITest.kt create mode 100644 plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt create mode 100644 plugins/base/src/test/kotlin/enums/EnumsTest.kt create mode 100644 plugins/base/src/test/kotlin/markdown/KDocTest.kt create mode 100644 plugins/base/src/test/kotlin/markdown/ParserTest.kt create mode 100644 plugins/base/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt create mode 100644 plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt (limited to 'core/src/test/kotlin/markdown/ParserTest.kt') diff --git a/core/src/test/kotlin/basic/DRITest.kt b/core/src/test/kotlin/basic/DRITest.kt deleted file mode 100644 index c7dc85fb..00000000 --- a/core/src/test/kotlin/basic/DRITest.kt +++ /dev/null @@ -1,168 +0,0 @@ -package basic - -import org.jetbrains.dokka.links.* -import org.jetbrains.dokka.pages.ContentPage -import org.jetbrains.dokka.pages.asSequence -import org.junit.Assert.assertEquals -import org.junit.Test -import testApi.testRunner.AbstractCoreTest - -class DRITest : AbstractCoreTest() { - @Test - fun `#634`() { - val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/") - } - } - } - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package toplevel - | - |inline fun > Array.mySortBy( - | crossinline selector: (T) -> R?): Array = TODO() - |} - """.trimMargin(), - configuration - ) { - documentablesMergingStage = { module -> - val expected = TypeConstructor( - "kotlin.Function1", listOf( - TypeParam(listOf(Nullable(TypeConstructor("kotlin.Any", emptyList())))), - Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) - ) - ) - val actual = module.packages.single() - .functions.single() - .dri.callable?.params?.single() - assertEquals(expected, actual) - } - } - } - - @Test - fun `#634 with immediate nullable self`() { - val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/") - } - } - } - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package toplevel - | - |fun > Array.doSomething(t: T?): Array = TODO() - |} - """.trimMargin(), - configuration - ) { - documentablesMergingStage = { module -> - val expected = Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) - val actual = module.packages.single() - .functions.single() - .dri.callable?.params?.single() - assertEquals(expected, actual) - } - } - } - - @Test - fun `#634 with generic nullable receiver`() { - val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/") - } - } - } - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package toplevel - | - |fun > T?.doSomethingWithNullable() = TODO() - |} - """.trimMargin(), - configuration - ) { - documentablesMergingStage = { module -> - val expected = Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) - val actual = module.packages.single() - .functions.single() - .dri.callable?.receiver - assertEquals(expected, actual) - } - } - } - - @Test - fun `#642 with * and Any?`() { - val configuration = dokkaConfiguration { - passes { - pass { - analysisPlatform = "js" - sourceRoots = listOf("src/") - } - } - } - - testInline( - """ - |/src/main/kotlin/Test.kt - | - |open class Bar - |class ReBarBar : Bar() - |class Foo, R : List>> - | - |fun > Foo.qux(): String = TODO() - |fun > Foo.qux(): String = TODO() - | - """.trimMargin(), - configuration - ) { - pagesGenerationStage = { module -> - // DRI(//qux/Foo[TypeParam(bounds=[kotlin.Comparable[kotlin.Any?]]),kotlin.Any?]#//) - val expectedDRI = DRI( - "", - null, - Callable( - "qux", - TypeConstructor( - "Foo", - listOf( - TypeParam( - listOf( - TypeConstructor( - "kotlin.Comparable", - listOf( - Nullable(TypeConstructor("kotlin.Any", emptyList())) - ) - ) - ) - ), - Nullable(TypeConstructor("kotlin.Any", emptyList())) - ) - ), - emptyList() - ) - ) - - val driCount = module - .asSequence() - .filterIsInstance() - .sumBy { it.dri.count { dri -> dri == expectedDRI } } - - assertEquals(1, driCount) - } - } - } -} \ No newline at end of file diff --git a/core/src/test/kotlin/basic/DokkaBasicTests.kt b/core/src/test/kotlin/basic/DokkaBasicTests.kt deleted file mode 100644 index 021f110c..00000000 --- a/core/src/test/kotlin/basic/DokkaBasicTests.kt +++ /dev/null @@ -1,41 +0,0 @@ -package basic - -import org.jetbrains.dokka.pages.ClasslikePageNode -import org.jetbrains.dokka.pages.ModulePageNode -import org.junit.Test -import testApi.testRunner.AbstractCoreTest - -class DokkaBasicTests : AbstractCoreTest() { - - @Test - fun basic1() { - val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/main/kotlin/basic/Test.kt") - } - } - } - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package basic - | - |class Test { - | val tI = 1 - | fun tF() = 2 - |} - """.trimMargin(), - configuration - ) { - pagesGenerationStage = { - println(it.dri) - assert(it.getClasslikeToMemberMap().filterKeys { it.name == "Test" }.entries.firstOrNull()?.value?.size == 5) - } - } - } - - fun ModulePageNode.getClasslikeToMemberMap() = - this.parentMap.filterValues { it is ClasslikePageNode }.entries.groupBy ({it.value}){it.key} -} \ No newline at end of file diff --git a/core/src/test/kotlin/enums/EnumsTest.kt b/core/src/test/kotlin/enums/EnumsTest.kt deleted file mode 100644 index efc46595..00000000 --- a/core/src/test/kotlin/enums/EnumsTest.kt +++ /dev/null @@ -1,45 +0,0 @@ -package enums - -import org.jetbrains.dokka.pages.ClasslikePageNode -import org.jetbrains.dokka.pages.ModulePageNode -import org.junit.Test -import testApi.testRunner.AbstractCoreTest - -class EnumsTest : AbstractCoreTest() { - - @Test - fun basicEnums() { - val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/") - } - } - } - - testInline( - """ - |/src/main/kotlin/basic/Test.kt - |package enums - | - |enum class Test { - | E1, - | E2 - |} - """.trimMargin(), - configuration - ) { - pagesGenerationStage = { - val map = it.getClasslikeToMemberMap() - val test = map.filterKeys { it.name == "Test" }.values.firstOrNull() - assert(test != null) { "Test not found" } - assert(test!!.any { it.name == "E1" } && test.any { it.name == "E2" }) { "Enum entries missing in parent" } - assert(map.keys.any { it.name == "E1" } && map.keys.any { it.name == "E2" }) { "Enum entries missing" } - } - } - } - - - fun ModulePageNode.getClasslikeToMemberMap() = - this.parentMap.filterValues { it is ClasslikePageNode }.entries.groupBy({ it.value }) { it.key } -} \ No newline at end of file diff --git a/core/src/test/kotlin/markdown/KDocTest.kt b/core/src/test/kotlin/markdown/KDocTest.kt deleted file mode 100644 index c58c4e30..00000000 --- a/core/src/test/kotlin/markdown/KDocTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package markdown - -import org.jetbrains.dokka.model.Package -import org.jetbrains.dokka.model.doc.DocumentationNode -import org.jetbrains.dokka.pages.ModulePageNode -import org.junit.Assert -import testApi.testRunner.AbstractCoreTest - -open class KDocTest : AbstractCoreTest() { - - private val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/main/kotlin/example/Test.kt") - } - } - } - - private fun interpolateKdoc(kdoc: String) = """ - |/src/main/kotlin/example/Test.kt - |package example - | /** - ${kdoc.split("\n").joinToString("") { "| *$it\n" } } - | */ - |class Test - """.trimMargin() - - private fun actualDocumentationNode(modulePageNode: ModulePageNode) = - (modulePageNode.documentable?.children?.first() as Package) - .classlikes.first() - .platformInfo.first() - .documentationNode - - - protected fun executeTest(kdoc: String, expectedDocumentationNode: DocumentationNode) { - testInline( - interpolateKdoc(kdoc), - configuration - ) { - pagesGenerationStage = { - Assert.assertEquals( - expectedDocumentationNode, - actualDocumentationNode(it) - ) - } - } - } -} \ No newline at end of file diff --git a/core/src/test/kotlin/markdown/ParserTest.kt b/core/src/test/kotlin/markdown/ParserTest.kt deleted file mode 100644 index dee8e907..00000000 --- a/core/src/test/kotlin/markdown/ParserTest.kt +++ /dev/null @@ -1,940 +0,0 @@ -package org.jetbrains.dokka.tests - -import markdown.KDocTest -import org.jetbrains.dokka.model.doc.* -import org.junit.Ignore -import org.junit.Test - - -class ParserTest : KDocTest() { - - @Test fun `Simple text`() { - val kdoc = """ - | This is simple test of string - | Next line - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(Text("This is simple test of string Next line"))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Simple text with new line`() { - val kdoc = """ - | This is simple test of string\ - | Next line - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - Text("This is simple test of string"), - Br, - Text("Next line") - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Text with Bold and Emphasis decorators`() { - val kdoc = """ - | This is **simple** test of _string_ - | Next **_line_** - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P( - listOf( - Text("This is "), - B(listOf(Text("simple"))), - Text(" test of "), - I(listOf(Text("string"))), - Text(" Next "), - B(listOf(I(listOf(Text("line"))))) - ) - ) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Text with Colon`() { - val kdoc = """ - | This is simple text with: colon! - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(Text("This is simple text with: colon!"))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Multilined text`() { - val kdoc = """ - | Text - | and - | String - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(Text("Text and String"))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Paragraphs`() { - val kdoc = """ - | Paragraph number - | one - | - | Paragraph\ - | number two - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P( - listOf( - P(listOf(Text("Paragraph number one"))), - P(listOf(Text("Paragraph"), Br, Text("number two"))) - ) - ) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Emphasis with star`() { - val kdoc = " *text*" - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(I(listOf(Text("text"))))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Underscores that are not Emphasis`() { - val kdoc = "text_with_underscores" - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(Text("text_with_underscores"))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Emphasis with underscores`() { - val kdoc = "_text_" - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(I(listOf(Text("text"))))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Embedded star`() { - val kdoc = "Embedded*Star" - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(Text("Embedded*Star"))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - - @Test fun `Unordered list`() { - val kdoc = """ - | * list item 1 - | * list item 2 - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - Ul( - listOf( - Li(listOf(P(listOf(Text("list item 1"))))), - Li(listOf(P(listOf(Text("list item 2"))))) - ) - ) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Unordered list with multilines`() { - val kdoc = """ - | * list item 1 - | continue 1 - | * list item 2\ - | continue 2 - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - Ul( - listOf( - Li(listOf(P(listOf(Text("list item 1 continue 1"))))), - Li(listOf(P(listOf(Text("list item 2"), Br, Text("continue 2"))))) - ) - ) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Unordered list with Bold`() { - val kdoc = """ - | * list **item** 1 - | continue 1 - | * list __item__ 2 - | continue 2 - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - Ul(listOf( - Li(listOf(P(listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 1 continue 1") - )))), - Li(listOf(P(listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 2 continue 2") - )))) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Unordered list with nested bullets`() { - val kdoc = """ - | * Outer first - | Outer next line - | * Outer second - | - Middle first - | Middle next line - | - Middle second - | + Inner first - | Inner next line - | - Middle third - | * Outer third - | - | New paragraph""".trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - Ul(listOf( - Li(listOf(P(listOf(Text("Outer first Outer next line"))))), - Li(listOf(P(listOf(Text("Outer second"))))), - Ul(listOf( - Li(listOf(P(listOf(Text("Middle first Middle next line"))))), - Li(listOf(P(listOf(Text("Middle second"))))), - Ul(listOf( - Li(listOf(P(listOf(Text("Inner first Inner next line"))))) - )), - Li(listOf(P(listOf(Text("Middle third"))))) - )), - Li(listOf(P(listOf(Text("Outer third"))))) - )), - P(listOf(Text("New paragraph"))) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Ordered list`() { - val kdoc = """ - | 1. list item 1 - | 2. list item 2 - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - Ol( - listOf( - Li(listOf(P(listOf(Text("list item 1"))))), - Li(listOf(P(listOf(Text("list item 2"))))) - ), - mapOf("start" to "1") - ) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - - @Test fun `Ordered list beginning from other number`() { - val kdoc = """ - | 9. list item 1 - | 12. list item 2 - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - Ol( - listOf( - Li(listOf(P(listOf(Text("list item 1"))))), - Li(listOf(P(listOf(Text("list item 2"))))) - ), - mapOf("start" to "9") - ) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Ordered list with multilines`() { - val kdoc = """ - | 2. list item 1 - | continue 1 - | 3. list item 2 - | continue 2 - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - Ol( - listOf( - Li(listOf(P(listOf(Text("list item 1 continue 1"))))), - Li(listOf(P(listOf(Text("list item 2 continue 2"))))) - ), - mapOf("start" to "2") - ) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Ordered list with Bold`() { - val kdoc = """ - | 1. list **item** 1 - | continue 1 - | 2. list __item__ 2 - | continue 2 - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - Ol(listOf( - Li(listOf(P(listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 1 continue 1") - )))), - Li(listOf(P(listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 2 continue 2") - )))) - ), - mapOf("start" to "1") - ) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Ordered list with nested bullets`() { - val kdoc = """ - | 1. Outer first - | Outer next line - | 2. Outer second - | 1. Middle first - | Middle next line - | 2. Middle second - | 1. Inner first - | Inner next line - | 5. Middle third - | 4. Outer third - | - | New paragraph""".trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - Ol(listOf( - Li(listOf(P(listOf(Text("Outer first Outer next line"))))), - Li(listOf(P(listOf(Text("Outer second"))))), - Ol(listOf( - Li(listOf(P(listOf(Text("Middle first Middle next line"))))), - Li(listOf(P(listOf(Text("Middle second"))))), - Ol(listOf( - Li(listOf(P(listOf(Text("Inner first Inner next line"))))) - ), - mapOf("start" to "1") - ), - Li(listOf(P(listOf(Text("Middle third"))))) - ), - mapOf("start" to "1") - ), - Li(listOf(P(listOf(Text("Outer third"))))) - ), - mapOf("start" to "1") - ), - P(listOf(Text("New paragraph"))) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Ordered nested in Unordered nested in Ordered list`() { - val kdoc = """ - | 1. Outer first - | Outer next line - | 2. Outer second - | + Middle first - | Middle next line - | + Middle second - | 1. Inner first - | Inner next line - | + Middle third - | 4. Outer third - | - | New paragraph""".trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - Ol(listOf( - Li(listOf(P(listOf(Text("Outer first Outer next line"))))), - Li(listOf(P(listOf(Text("Outer second"))))), - Ul(listOf( - Li(listOf(P(listOf(Text("Middle first Middle next line"))))), - Li(listOf(P(listOf(Text("Middle second"))))), - Ol(listOf( - Li(listOf(P(listOf(Text("Inner first Inner next line"))))) - ), - mapOf("start" to "1") - ), - Li(listOf(P(listOf(Text("Middle third"))))) - )), - Li(listOf(P(listOf(Text("Outer third"))))) - ), - mapOf("start" to "1") - ), - P(listOf(Text("New paragraph"))) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Header and two paragraphs`() { - val kdoc = """ - | # Header 1 - | Following text - | - | New paragraph - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - H1(listOf(Text("Header 1"))), - P(listOf(Text("Following text"))), - P(listOf(Text("New paragraph"))) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Ignore //TODO: ATX_2 to ATX_6 and sometimes ATX_1 from jetbrains parser consumes white space. Need to handle it in their library - @Test fun `All headers`() { - val kdoc = """ - | # Header 1 - | Text 1 - | ## Header 2 - | Text 2 - | ### Header 3 - | Text 3 - | #### Header 4 - | Text 4 - | ##### Header 5 - | Text 5 - | ###### Header 6 - | Text 6 - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - H1(listOf(Text("Header 1"))), - P(listOf(Text("Text 1"))), - H2(listOf(Text("Header 2"))), - P(listOf(Text("Text 2"))), - H3(listOf(Text("Header 3"))), - P(listOf(Text("Text 3"))), - H4(listOf(Text("Header 4"))), - P(listOf(Text("Text 4"))), - H5(listOf(Text("Header 5"))), - P(listOf(Text("Text 5"))), - H6(listOf(Text("Header 6"))), - P(listOf(Text("Text 6"))) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Bold New Line Bold`() { - val kdoc = """ - | **line 1**\ - | **line 2** - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - B(listOf(Text("line 1"))), - Br, - B(listOf(Text("line 2"))) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Horizontal rule`() { - val kdoc = """ - | *** - | text 1 - | ___ - | text 2 - | *** - | text 3 - | ___ - | text 4 - | *** - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - HorizontalRule, - P(listOf(Text("text 1"))), - HorizontalRule, - P(listOf(Text("text 2"))), - HorizontalRule, - P(listOf(Text("text 3"))), - HorizontalRule, - P(listOf(Text("text 4"))), - HorizontalRule - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Blockquote`() { - val kdoc = """ - | > Blockquotes are very handy in email to emulate reply text. - | > This line is part of the same quote. - | - | Quote break. - | - | > Quote - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - BlockQuote(listOf( - P(listOf( - Text("Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.") - )) - )), - P(listOf(Text("Quote break."))), - BlockQuote(listOf( - P(listOf(Text("Quote"))) - )) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - - @Test fun `Blockquote nested`() { - val kdoc = """ - | > text 1 - | > text 2 - | >> text 3 - | >> text 4 - | > - | > text 5 - | - | Quote break. - | - | > Quote - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - BlockQuote(listOf( - P(listOf(Text("text 1 text 2"))), - BlockQuote(listOf( - P(listOf(Text("text 3 text 4"))) - )), - P(listOf(Text("text 5"))) - )), - P(listOf(Text("Quote break."))), - BlockQuote(listOf( - P(listOf(Text("Quote"))) - )) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Ignore //TODO: Again ATX_1 consumes white space - @Test fun `Blockquote nested with fancy text enhancement`() { - val kdoc = """ - | > text **1** - | > text 2 - | >> # text 3 - | >> * text 4 - | >> * text 5 - | > - | > text 6 - | - | Quote break. - | - | > Quote - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - BlockQuote(listOf( - P(listOf( - Text("text "), - B(listOf(Text("1"))), - Text("\ntext 2") - )), - BlockQuote(listOf( - H1(listOf(Text("text 3"))), - Ul(listOf( - Li(listOf(P(listOf(Text("text 4"))))), - Ul(listOf( - Li(listOf(P(listOf(Text("text 5"))))) - ) - ))) - )), - P(listOf(Text("text 6"))) - )), - P(listOf(Text("Quote break."))), - BlockQuote(listOf( - P(listOf(Text("Quote"))) - )) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Simple Code Block`() { - val kdoc = """ - | `Some code` - | Sample text - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - Code(listOf(Text("Some code"))), - Text(" Sample text") - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Multilined Code Block`() { - val kdoc = """ - | ```kotlin - | val x: Int = 0 - | val y: String = "Text" - | - | val z: Boolean = true - | for(i in 0..10) { - | println(i) - | } - | ``` - | Sample text - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - Code( - listOf( - Text("val x: Int = 0"), Br, - Text("val y: String = \"Text\""), Br, Br, - Text(" val z: Boolean = true"), Br, - Text("for(i in 0..10) {"), Br, - Text(" println(i)"), Br, - Text("}") - ), - mapOf("lang" to "kotlin") - ), - P(listOf(Text("Sample text"))) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - - @Test fun `Inline link`() { - val kdoc = """ - | [I'm an inline-style link](https://www.google.com) - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(A( - listOf(Text("I'm an inline-style link")), - mapOf("href" to "https://www.google.com") - ))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Inline link with title`() { - val kdoc = """ - | [I'm an inline-style link with title](https://www.google.com "Google's Homepage") - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(A( - listOf(Text("I'm an inline-style link with title")), - mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") - ))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Full reference link`() { - val kdoc = """ - | [I'm a reference-style link][Arbitrary case-insensitive reference text] - | - | [arbitrary case-insensitive reference text]: https://www.mozilla.org - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(P(listOf(A( - listOf(Text("I'm a reference-style link")), - mapOf("href" to "https://www.mozilla.org") - ))))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Full reference link with number`() { - val kdoc = """ - | [You can use numbers for reference-style link definitions][1] - | - | [1]: http://slashdot.org - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(P(listOf(A( - listOf(Text("You can use numbers for reference-style link definitions")), - mapOf("href" to "http://slashdot.org") - ))))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Short reference link`() { - val kdoc = """ - | Or leave it empty and use the [link text itself]. - | - | [link text itself]: http://www.reddit.com - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf(P(listOf( - Text("Or leave it empty and use the "), - A( - listOf(Text("link text itself")), - mapOf("href" to "http://www.reddit.com") - ), - Text(".") - )))) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Autolink`() { - val kdoc = """ - | URLs and URLs in angle brackets will automatically get turned into links. - | http://www.example.com or and sometimes - | example.com (but not on Github, for example). - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), - A( - listOf(Text("http://www.example.com")), - mapOf("href" to "http://www.example.com") - ), - Text(" and sometimes example.com (but not on Github, for example).") - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Various links`() { - val kdoc = """ - | [I'm an inline-style link](https://www.google.com) - | - | [I'm an inline-style link with title](https://www.google.com "Google's Homepage") - | - | [I'm a reference-style link][Arbitrary case-insensitive reference text] - | - | [You can use numbers for reference-style link definitions][1] - | - | Or leave it empty and use the [link text itself]. - | - | URLs and URLs in angle brackets will automatically get turned into links. - | http://www.example.com or and sometimes - | example.com (but not on Github, for example). - | - | Some text to show that the reference links can follow later. - | - | [arbitrary case-insensitive reference text]: https://www.mozilla.org - | [1]: http://slashdot.org - | [link text itself]: http://www.reddit.com - """.trimMargin() - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - P(listOf(A( - listOf(Text("I'm an inline-style link")), - mapOf("href" to "https://www.google.com") - ))), - P(listOf(A( - listOf(Text("I'm an inline-style link with title")), - mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") - ))), - P(listOf(A( - listOf(Text("I'm a reference-style link")), - mapOf("href" to "https://www.mozilla.org") - ))), - P(listOf(A( - listOf(Text("You can use numbers for reference-style link definitions")), - mapOf("href" to "http://slashdot.org") - ))), - P(listOf( - Text("Or leave it empty and use the "), - A( - listOf(Text("link text itself")), - mapOf("href" to "http://www.reddit.com") - ), - Text(".") - )), - P(listOf( - Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), - A( - listOf(Text("http://www.example.com")), - mapOf("href" to "http://www.example.com") - ), - Text(" and sometimes example.com (but not on Github, for example).") - )), - P(listOf(Text("Some text to show that the reference links can follow later."))) - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } - - @Test fun `Windows Carriage Return Line Feed`() { - val kdoc = "text\r\ntext" - val expectedDocumentationNode = DocumentationNode( - listOf( - Description( - P(listOf( - Text("text text") - )) - ) - ) - ) - executeTest(kdoc, expectedDocumentationNode) - } -} - diff --git a/core/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt b/core/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt deleted file mode 100644 index f9431bbb..00000000 --- a/core/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt +++ /dev/null @@ -1,55 +0,0 @@ -package multiplatform - -import org.junit.Assert.assertEquals -import org.junit.Test -import testApi.testRunner.AbstractCoreTest - -class BasicMultiplatformTest : AbstractCoreTest() { - - @Test - fun dataTestExample() { - val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() - - val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("$testDataDir/jvmMain/") - } - } - } - - testFromData(configuration) { - pagesTransformationStage = { - assertEquals(6, it.children.firstOrNull()?.children?.count() ?: 0) - } - } - } - - @Test - fun inlineTestExample() { - val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/main/kotlin/multiplatform/Test.kt") - } - } - } - - testInline( - """ - |/src/main/kotlin/multiplatform/Test.kt - |package multiplatform - | - |object Test { - | fun test2(str: String): Unit {println(str)} - |} - """.trimMargin(), - configuration - ) { - pagesGenerationStage = { - println(it.dri) - assertEquals(7, it.parentMap.size) - } - } - } -} \ No newline at end of file diff --git a/core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt b/core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt deleted file mode 100644 index 88e57ddb..00000000 --- a/core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt +++ /dev/null @@ -1,127 +0,0 @@ -package pageMerger - -import org.jetbrains.dokka.CoreExtensions -import org.jetbrains.dokka.pages.ContentPage -import org.jetbrains.dokka.pages.PageNode -import org.jetbrains.dokka.plugability.DokkaPlugin -import org.jetbrains.dokka.transformers.pages.DefaultPageMergerStrategy -import org.jetbrains.dokka.transformers.pages.SameMethodNamePageMergerStrategy -import org.jetbrains.dokka.utilities.DokkaLogger -import org.junit.Test -import testApi.testRunner.AbstractCoreTest - -class PageNodeMergerTest : AbstractCoreTest() { - - object SameNameStrategy : DokkaPlugin() { - val strategy by extending { CoreExtensions.pageMergerStrategy with SameMethodNamePageMergerStrategy } - } - - class DefaultStrategy(val strList: MutableList = mutableListOf()) : DokkaPlugin(), DokkaLogger { - val strategy by extending { CoreExtensions.pageMergerStrategy with DefaultPageMergerStrategy(this@DefaultStrategy) } - - override var warningsCount: Int = 0 - override var errorsCount: Int = 0 - - override fun debug(message: String) = TODO() - - override fun info(message: String) = TODO() - - override fun progress(message: String) = TODO() - - override fun warn(message: String) { - strList += message - } - - override fun error(message: String) = TODO() - - override fun report() = TODO() - } - - @Test - fun sameNameStrategyTest() { - - val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt") - } - } - } - - testInline( - """ - |/src/main/kotlin/pageMerger/Test.kt - |package pageMerger - | - |fun testT(): Int = 1 - |fun testT(i: Int): Int = i - | - |object Test { - | fun test(): String = "" - | fun test(str: String): String = str - |} - """.trimMargin(), - configuration, - pluginOverrides = listOf(SameNameStrategy) - ) { - pagesTransformationStage = { - val allChildren = it.childrenRec().filterIsInstance() - val testT = allChildren.filter { it.name == "testT" } - val test = allChildren.filter { it.name == "test" } - - assert(testT.size == 1) { "There can be only one testT page" } - assert(testT.first().dri.size == 2) { "testT page should have 2 DRI, but has ${testT.first().dri.size}" } - - assert(test.size == 1) { "There can be only one test page" } - assert(test.first().dri.size == 2) { "test page should have 2 DRI, but has ${test.first().dri.size}" } - } - } - } - - @Test - fun defaultStrategyTest() { - val strList: MutableList = mutableListOf() - - val configuration = dokkaConfiguration { - passes { - pass { - sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt") - } - } - } - - testInline( - """ - |/src/main/kotlin/pageMerger/Test.kt - |package pageMerger - | - |fun testT(): Int = 1 - |fun testT(i: Int): Int = i - | - |object Test { - | fun test(): String = "" - | fun test(str: String): String = str - |} - """.trimMargin(), - configuration, - pluginOverrides = listOf(DefaultStrategy(strList)) - ) { - pagesTransformationStage = { root -> - val allChildren = root.childrenRec().filterIsInstance() - val testT = allChildren.filter { it.name == "testT" } - val test = allChildren.filter { it.name == "test" } - - assert(testT.size == 1) { "There can be only one testT page" } - assert(testT.first().dri.size == 1) { "testT page should have single DRI, but has ${testT.first().dri.size}" } - - assert(test.size == 1) { "There can be only one test page" } - assert(test.first().dri.size == 1) { "test page should have single DRI, but has ${test.first().dri.size}" } - - assert(strList.count() == 2) { "Expected 2 warnings, got ${strList.count()}" } - } - } - } - - fun PageNode.childrenRec(): List = listOf(this) + children.flatMap { it.childrenRec() } - -} \ No newline at end of file diff --git a/core/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt b/core/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt deleted file mode 100644 index 4753cb32..00000000 --- a/core/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt +++ /dev/null @@ -1,15 +0,0 @@ -package example - -/** - * Documentation for expected class Clock - * in common module - */ -expect open class Clock() { - fun getTime(): String - /** - * Time in minis - */ - fun getTimesInMillis(): String - fun getYear(): String -} - diff --git a/core/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt b/core/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt deleted file mode 100644 index c879dee7..00000000 --- a/core/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt +++ /dev/null @@ -1,24 +0,0 @@ -package example - -class House(val street: String, val number: Int) { - - /** - * The owner of the house - */ - var owner: String = "" - - /** - * The owner of the house - */ - val differentOwner: String = "" - - fun addFloor() {} - - class Basement { - val pickles : List = mutableListOf() - } - - companion object { - val DEFAULT = House("",0) - } -} \ No newline at end of file diff --git a/core/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt b/core/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt deleted file mode 100644 index 967cffcd..00000000 --- a/core/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt +++ /dev/null @@ -1,21 +0,0 @@ -package example - -import greeteer.Greeter -import kotlin.js.Date - -/** - * Documentation for actual class Clock in JS - */ -actual open class Clock { - actual fun getTime() = Date.now().toString() - fun onlyJsFunction(): Int = 42 - actual fun getTimesInMillis(): String = Date.now().toString() - - actual fun getYear(): String { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } -} - -fun main() { - Greeter().greet().also { println(it) } -} \ No newline at end of file diff --git a/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt b/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt deleted file mode 100644 index 8a52e2f3..00000000 --- a/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt +++ /dev/null @@ -1,10 +0,0 @@ -package greeteer - -import example.Clock - -class Greeter { - /** - * Some docs for the [greet] function - */ - fun greet() = Clock().let{ "Hello there! THe time is ${it.getTime()}" } -} \ No newline at end of file diff --git a/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt b/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt deleted file mode 100644 index 9ec01fb6..00000000 --- a/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt +++ /dev/null @@ -1,34 +0,0 @@ -package example - -import greeteer.Greeter - -actual open class Clock { - actual fun getTime(): String = System.currentTimeMillis().toString() - actual fun getTimesInMillis(): String = System.currentTimeMillis().toString() - - /** - * Documentation for onlyJVMFunction on... - * wait for it... - * ...JVM! - */ - fun onlyJVMFunction(): Double = 2.5 - /** - * Custom equals function - */ - override fun equals(other: Any?): Boolean { - return super.equals(other) - } - - open fun getDayOfTheWeek(): String { - TODO("not implemented") - } - actual fun getYear(): String { - TODO("not implemented") - } -} - -fun clockList() = listOf(Clock()) - -fun main() { - Greeter().greet().also { println(it) } -} \ No newline at end of file diff --git a/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt b/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt deleted file mode 100644 index 136ae5c8..00000000 --- a/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt +++ /dev/null @@ -1,15 +0,0 @@ -package example - -/** - * frgergergrthe - * */ -enum class ClockDays { - /** - * dfsdfsdfds - * */ - FIRST, - SECOND, // test2 - THIRD, // test3 - FOURTH, // test4 - FIFTH // test5 -} \ No newline at end of file diff --git a/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt b/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt deleted file mode 100644 index 40813b50..00000000 --- a/core/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt +++ /dev/null @@ -1,32 +0,0 @@ -package example - -import greeteer.Greeter - -class ParticularClock(private val clockDay: ClockDays) : Clock() { - - /** - * Rings bell [times] - */ - fun ringBell(times: Int) {} - - /** - * Uses provider [greeter] - */ - fun useGreeter(greeter: Greeter) { - - } - - /** - * Day of the week - */ - override fun getDayOfTheWeek() = clockDay.name -} - -/** - * A sample extension function - * When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$ - * @usesMathJax - */ -fun Clock.extensionFun() { - -} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/basic/DRITest.kt b/plugins/base/src/test/kotlin/basic/DRITest.kt new file mode 100644 index 00000000..c7dc85fb --- /dev/null +++ b/plugins/base/src/test/kotlin/basic/DRITest.kt @@ -0,0 +1,168 @@ +package basic + +import org.jetbrains.dokka.links.* +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.asSequence +import org.junit.Assert.assertEquals +import org.junit.Test +import testApi.testRunner.AbstractCoreTest + +class DRITest : AbstractCoreTest() { + @Test + fun `#634`() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package toplevel + | + |inline fun > Array.mySortBy( + | crossinline selector: (T) -> R?): Array = TODO() + |} + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + val expected = TypeConstructor( + "kotlin.Function1", listOf( + TypeParam(listOf(Nullable(TypeConstructor("kotlin.Any", emptyList())))), + Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) + ) + ) + val actual = module.packages.single() + .functions.single() + .dri.callable?.params?.single() + assertEquals(expected, actual) + } + } + } + + @Test + fun `#634 with immediate nullable self`() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package toplevel + | + |fun > Array.doSomething(t: T?): Array = TODO() + |} + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + val expected = Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) + val actual = module.packages.single() + .functions.single() + .dri.callable?.params?.single() + assertEquals(expected, actual) + } + } + } + + @Test + fun `#634 with generic nullable receiver`() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package toplevel + | + |fun > T?.doSomethingWithNullable() = TODO() + |} + """.trimMargin(), + configuration + ) { + documentablesMergingStage = { module -> + val expected = Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) + val actual = module.packages.single() + .functions.single() + .dri.callable?.receiver + assertEquals(expected, actual) + } + } + } + + @Test + fun `#642 with * and Any?`() { + val configuration = dokkaConfiguration { + passes { + pass { + analysisPlatform = "js" + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + | + |open class Bar + |class ReBarBar : Bar() + |class Foo, R : List>> + | + |fun > Foo.qux(): String = TODO() + |fun > Foo.qux(): String = TODO() + | + """.trimMargin(), + configuration + ) { + pagesGenerationStage = { module -> + // DRI(//qux/Foo[TypeParam(bounds=[kotlin.Comparable[kotlin.Any?]]),kotlin.Any?]#//) + val expectedDRI = DRI( + "", + null, + Callable( + "qux", + TypeConstructor( + "Foo", + listOf( + TypeParam( + listOf( + TypeConstructor( + "kotlin.Comparable", + listOf( + Nullable(TypeConstructor("kotlin.Any", emptyList())) + ) + ) + ) + ), + Nullable(TypeConstructor("kotlin.Any", emptyList())) + ) + ), + emptyList() + ) + ) + + val driCount = module + .asSequence() + .filterIsInstance() + .sumBy { it.dri.count { dri -> dri == expectedDRI } } + + assertEquals(1, driCount) + } + } + } +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt b/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt new file mode 100644 index 00000000..021f110c --- /dev/null +++ b/plugins/base/src/test/kotlin/basic/DokkaBasicTests.kt @@ -0,0 +1,41 @@ +package basic + +import org.jetbrains.dokka.pages.ClasslikePageNode +import org.jetbrains.dokka.pages.ModulePageNode +import org.junit.Test +import testApi.testRunner.AbstractCoreTest + +class DokkaBasicTests : AbstractCoreTest() { + + @Test + fun basic1() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/basic/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package basic + | + |class Test { + | val tI = 1 + | fun tF() = 2 + |} + """.trimMargin(), + configuration + ) { + pagesGenerationStage = { + println(it.dri) + assert(it.getClasslikeToMemberMap().filterKeys { it.name == "Test" }.entries.firstOrNull()?.value?.size == 5) + } + } + } + + fun ModulePageNode.getClasslikeToMemberMap() = + this.parentMap.filterValues { it is ClasslikePageNode }.entries.groupBy ({it.value}){it.key} +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/enums/EnumsTest.kt b/plugins/base/src/test/kotlin/enums/EnumsTest.kt new file mode 100644 index 00000000..efc46595 --- /dev/null +++ b/plugins/base/src/test/kotlin/enums/EnumsTest.kt @@ -0,0 +1,45 @@ +package enums + +import org.jetbrains.dokka.pages.ClasslikePageNode +import org.jetbrains.dokka.pages.ModulePageNode +import org.junit.Test +import testApi.testRunner.AbstractCoreTest + +class EnumsTest : AbstractCoreTest() { + + @Test + fun basicEnums() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/basic/Test.kt + |package enums + | + |enum class Test { + | E1, + | E2 + |} + """.trimMargin(), + configuration + ) { + pagesGenerationStage = { + val map = it.getClasslikeToMemberMap() + val test = map.filterKeys { it.name == "Test" }.values.firstOrNull() + assert(test != null) { "Test not found" } + assert(test!!.any { it.name == "E1" } && test.any { it.name == "E2" }) { "Enum entries missing in parent" } + assert(map.keys.any { it.name == "E1" } && map.keys.any { it.name == "E2" }) { "Enum entries missing" } + } + } + } + + + fun ModulePageNode.getClasslikeToMemberMap() = + this.parentMap.filterValues { it is ClasslikePageNode }.entries.groupBy({ it.value }) { it.key } +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/markdown/KDocTest.kt b/plugins/base/src/test/kotlin/markdown/KDocTest.kt new file mode 100644 index 00000000..c58c4e30 --- /dev/null +++ b/plugins/base/src/test/kotlin/markdown/KDocTest.kt @@ -0,0 +1,48 @@ +package markdown + +import org.jetbrains.dokka.model.Package +import org.jetbrains.dokka.model.doc.DocumentationNode +import org.jetbrains.dokka.pages.ModulePageNode +import org.junit.Assert +import testApi.testRunner.AbstractCoreTest + +open class KDocTest : AbstractCoreTest() { + + private val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/example/Test.kt") + } + } + } + + private fun interpolateKdoc(kdoc: String) = """ + |/src/main/kotlin/example/Test.kt + |package example + | /** + ${kdoc.split("\n").joinToString("") { "| *$it\n" } } + | */ + |class Test + """.trimMargin() + + private fun actualDocumentationNode(modulePageNode: ModulePageNode) = + (modulePageNode.documentable?.children?.first() as Package) + .classlikes.first() + .platformInfo.first() + .documentationNode + + + protected fun executeTest(kdoc: String, expectedDocumentationNode: DocumentationNode) { + testInline( + interpolateKdoc(kdoc), + configuration + ) { + pagesGenerationStage = { + Assert.assertEquals( + expectedDocumentationNode, + actualDocumentationNode(it) + ) + } + } + } +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/markdown/ParserTest.kt b/plugins/base/src/test/kotlin/markdown/ParserTest.kt new file mode 100644 index 00000000..dee8e907 --- /dev/null +++ b/plugins/base/src/test/kotlin/markdown/ParserTest.kt @@ -0,0 +1,940 @@ +package org.jetbrains.dokka.tests + +import markdown.KDocTest +import org.jetbrains.dokka.model.doc.* +import org.junit.Ignore +import org.junit.Test + + +class ParserTest : KDocTest() { + + @Test fun `Simple text`() { + val kdoc = """ + | This is simple test of string + | Next line + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text("This is simple test of string Next line"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Simple text with new line`() { + val kdoc = """ + | This is simple test of string\ + | Next line + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Text("This is simple test of string"), + Br, + Text("Next line") + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Text with Bold and Emphasis decorators`() { + val kdoc = """ + | This is **simple** test of _string_ + | Next **_line_** + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P( + listOf( + Text("This is "), + B(listOf(Text("simple"))), + Text(" test of "), + I(listOf(Text("string"))), + Text(" Next "), + B(listOf(I(listOf(Text("line"))))) + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Text with Colon`() { + val kdoc = """ + | This is simple text with: colon! + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text("This is simple text with: colon!"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Multilined text`() { + val kdoc = """ + | Text + | and + | String + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text("Text and String"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Paragraphs`() { + val kdoc = """ + | Paragraph number + | one + | + | Paragraph\ + | number two + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P( + listOf( + P(listOf(Text("Paragraph number one"))), + P(listOf(Text("Paragraph"), Br, Text("number two"))) + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Emphasis with star`() { + val kdoc = " *text*" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(I(listOf(Text("text"))))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Underscores that are not Emphasis`() { + val kdoc = "text_with_underscores" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text("text_with_underscores"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Emphasis with underscores`() { + val kdoc = "_text_" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(I(listOf(Text("text"))))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Embedded star`() { + val kdoc = "Embedded*Star" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(Text("Embedded*Star"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + + @Test fun `Unordered list`() { + val kdoc = """ + | * list item 1 + | * list item 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ul( + listOf( + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Unordered list with multilines`() { + val kdoc = """ + | * list item 1 + | continue 1 + | * list item 2\ + | continue 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ul( + listOf( + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2"), Br, Text("continue 2"))))) + ) + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Unordered list with Bold`() { + val kdoc = """ + | * list **item** 1 + | continue 1 + | * list __item__ 2 + | continue 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ul(listOf( + Li(listOf(P(listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") + )))), + Li(listOf(P(listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") + )))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Unordered list with nested bullets`() { + val kdoc = """ + | * Outer first + | Outer next line + | * Outer second + | - Middle first + | Middle next line + | - Middle second + | + Inner first + | Inner next line + | - Middle third + | * Outer third + | + | New paragraph""".trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Ul(listOf( + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), + Ul(listOf( + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), + Ul(listOf( + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) + )), + Li(listOf(P(listOf(Text("Middle third"))))) + )), + Li(listOf(P(listOf(Text("Outer third"))))) + )), + P(listOf(Text("New paragraph"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Ordered list`() { + val kdoc = """ + | 1. list item 1 + | 2. list item 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ol( + listOf( + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) + ), + mapOf("start" to "1") + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + + @Test fun `Ordered list beginning from other number`() { + val kdoc = """ + | 9. list item 1 + | 12. list item 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ol( + listOf( + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) + ), + mapOf("start" to "9") + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Ordered list with multilines`() { + val kdoc = """ + | 2. list item 1 + | continue 1 + | 3. list item 2 + | continue 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ol( + listOf( + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2 continue 2"))))) + ), + mapOf("start" to "2") + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Ordered list with Bold`() { + val kdoc = """ + | 1. list **item** 1 + | continue 1 + | 2. list __item__ 2 + | continue 2 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + Ol(listOf( + Li(listOf(P(listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") + )))), + Li(listOf(P(listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") + )))) + ), + mapOf("start" to "1") + ) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Ordered list with nested bullets`() { + val kdoc = """ + | 1. Outer first + | Outer next line + | 2. Outer second + | 1. Middle first + | Middle next line + | 2. Middle second + | 1. Inner first + | Inner next line + | 5. Middle third + | 4. Outer third + | + | New paragraph""".trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Ol(listOf( + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), + Ol(listOf( + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), + Ol(listOf( + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) + ), + mapOf("start" to "1") + ), + Li(listOf(P(listOf(Text("Middle third"))))) + ), + mapOf("start" to "1") + ), + Li(listOf(P(listOf(Text("Outer third"))))) + ), + mapOf("start" to "1") + ), + P(listOf(Text("New paragraph"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Ordered nested in Unordered nested in Ordered list`() { + val kdoc = """ + | 1. Outer first + | Outer next line + | 2. Outer second + | + Middle first + | Middle next line + | + Middle second + | 1. Inner first + | Inner next line + | + Middle third + | 4. Outer third + | + | New paragraph""".trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Ol(listOf( + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), + Ul(listOf( + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), + Ol(listOf( + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) + ), + mapOf("start" to "1") + ), + Li(listOf(P(listOf(Text("Middle third"))))) + )), + Li(listOf(P(listOf(Text("Outer third"))))) + ), + mapOf("start" to "1") + ), + P(listOf(Text("New paragraph"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Header and two paragraphs`() { + val kdoc = """ + | # Header 1 + | Following text + | + | New paragraph + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + H1(listOf(Text("Header 1"))), + P(listOf(Text("Following text"))), + P(listOf(Text("New paragraph"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Ignore //TODO: ATX_2 to ATX_6 and sometimes ATX_1 from jetbrains parser consumes white space. Need to handle it in their library + @Test fun `All headers`() { + val kdoc = """ + | # Header 1 + | Text 1 + | ## Header 2 + | Text 2 + | ### Header 3 + | Text 3 + | #### Header 4 + | Text 4 + | ##### Header 5 + | Text 5 + | ###### Header 6 + | Text 6 + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + H1(listOf(Text("Header 1"))), + P(listOf(Text("Text 1"))), + H2(listOf(Text("Header 2"))), + P(listOf(Text("Text 2"))), + H3(listOf(Text("Header 3"))), + P(listOf(Text("Text 3"))), + H4(listOf(Text("Header 4"))), + P(listOf(Text("Text 4"))), + H5(listOf(Text("Header 5"))), + P(listOf(Text("Text 5"))), + H6(listOf(Text("Header 6"))), + P(listOf(Text("Text 6"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Bold New Line Bold`() { + val kdoc = """ + | **line 1**\ + | **line 2** + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + B(listOf(Text("line 1"))), + Br, + B(listOf(Text("line 2"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Horizontal rule`() { + val kdoc = """ + | *** + | text 1 + | ___ + | text 2 + | *** + | text 3 + | ___ + | text 4 + | *** + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + HorizontalRule, + P(listOf(Text("text 1"))), + HorizontalRule, + P(listOf(Text("text 2"))), + HorizontalRule, + P(listOf(Text("text 3"))), + HorizontalRule, + P(listOf(Text("text 4"))), + HorizontalRule + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Blockquote`() { + val kdoc = """ + | > Blockquotes are very handy in email to emulate reply text. + | > This line is part of the same quote. + | + | Quote break. + | + | > Quote + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + BlockQuote(listOf( + P(listOf( + Text("Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.") + )) + )), + P(listOf(Text("Quote break."))), + BlockQuote(listOf( + P(listOf(Text("Quote"))) + )) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + + @Test fun `Blockquote nested`() { + val kdoc = """ + | > text 1 + | > text 2 + | >> text 3 + | >> text 4 + | > + | > text 5 + | + | Quote break. + | + | > Quote + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + BlockQuote(listOf( + P(listOf(Text("text 1 text 2"))), + BlockQuote(listOf( + P(listOf(Text("text 3 text 4"))) + )), + P(listOf(Text("text 5"))) + )), + P(listOf(Text("Quote break."))), + BlockQuote(listOf( + P(listOf(Text("Quote"))) + )) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Ignore //TODO: Again ATX_1 consumes white space + @Test fun `Blockquote nested with fancy text enhancement`() { + val kdoc = """ + | > text **1** + | > text 2 + | >> # text 3 + | >> * text 4 + | >> * text 5 + | > + | > text 6 + | + | Quote break. + | + | > Quote + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + BlockQuote(listOf( + P(listOf( + Text("text "), + B(listOf(Text("1"))), + Text("\ntext 2") + )), + BlockQuote(listOf( + H1(listOf(Text("text 3"))), + Ul(listOf( + Li(listOf(P(listOf(Text("text 4"))))), + Ul(listOf( + Li(listOf(P(listOf(Text("text 5"))))) + ) + ))) + )), + P(listOf(Text("text 6"))) + )), + P(listOf(Text("Quote break."))), + BlockQuote(listOf( + P(listOf(Text("Quote"))) + )) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Simple Code Block`() { + val kdoc = """ + | `Some code` + | Sample text + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Code(listOf(Text("Some code"))), + Text(" Sample text") + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Multilined Code Block`() { + val kdoc = """ + | ```kotlin + | val x: Int = 0 + | val y: String = "Text" + | + | val z: Boolean = true + | for(i in 0..10) { + | println(i) + | } + | ``` + | Sample text + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Code( + listOf( + Text("val x: Int = 0"), Br, + Text("val y: String = \"Text\""), Br, Br, + Text(" val z: Boolean = true"), Br, + Text("for(i in 0..10) {"), Br, + Text(" println(i)"), Br, + Text("}") + ), + mapOf("lang" to "kotlin") + ), + P(listOf(Text("Sample text"))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + + @Test fun `Inline link`() { + val kdoc = """ + | [I'm an inline-style link](https://www.google.com) + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(A( + listOf(Text("I'm an inline-style link")), + mapOf("href" to "https://www.google.com") + ))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Inline link with title`() { + val kdoc = """ + | [I'm an inline-style link with title](https://www.google.com "Google's Homepage") + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(A( + listOf(Text("I'm an inline-style link with title")), + mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") + ))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Full reference link`() { + val kdoc = """ + | [I'm a reference-style link][Arbitrary case-insensitive reference text] + | + | [arbitrary case-insensitive reference text]: https://www.mozilla.org + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(P(listOf(A( + listOf(Text("I'm a reference-style link")), + mapOf("href" to "https://www.mozilla.org") + ))))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Full reference link with number`() { + val kdoc = """ + | [You can use numbers for reference-style link definitions][1] + | + | [1]: http://slashdot.org + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(P(listOf(A( + listOf(Text("You can use numbers for reference-style link definitions")), + mapOf("href" to "http://slashdot.org") + ))))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Short reference link`() { + val kdoc = """ + | Or leave it empty and use the [link text itself]. + | + | [link text itself]: http://www.reddit.com + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf(P(listOf( + Text("Or leave it empty and use the "), + A( + listOf(Text("link text itself")), + mapOf("href" to "http://www.reddit.com") + ), + Text(".") + )))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Autolink`() { + val kdoc = """ + | URLs and URLs in angle brackets will automatically get turned into links. + | http://www.example.com or and sometimes + | example.com (but not on Github, for example). + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), + A( + listOf(Text("http://www.example.com")), + mapOf("href" to "http://www.example.com") + ), + Text(" and sometimes example.com (but not on Github, for example).") + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Various links`() { + val kdoc = """ + | [I'm an inline-style link](https://www.google.com) + | + | [I'm an inline-style link with title](https://www.google.com "Google's Homepage") + | + | [I'm a reference-style link][Arbitrary case-insensitive reference text] + | + | [You can use numbers for reference-style link definitions][1] + | + | Or leave it empty and use the [link text itself]. + | + | URLs and URLs in angle brackets will automatically get turned into links. + | http://www.example.com or and sometimes + | example.com (but not on Github, for example). + | + | Some text to show that the reference links can follow later. + | + | [arbitrary case-insensitive reference text]: https://www.mozilla.org + | [1]: http://slashdot.org + | [link text itself]: http://www.reddit.com + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + P(listOf(A( + listOf(Text("I'm an inline-style link")), + mapOf("href" to "https://www.google.com") + ))), + P(listOf(A( + listOf(Text("I'm an inline-style link with title")), + mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") + ))), + P(listOf(A( + listOf(Text("I'm a reference-style link")), + mapOf("href" to "https://www.mozilla.org") + ))), + P(listOf(A( + listOf(Text("You can use numbers for reference-style link definitions")), + mapOf("href" to "http://slashdot.org") + ))), + P(listOf( + Text("Or leave it empty and use the "), + A( + listOf(Text("link text itself")), + mapOf("href" to "http://www.reddit.com") + ), + Text(".") + )), + P(listOf( + Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), + A( + listOf(Text("http://www.example.com")), + mapOf("href" to "http://www.example.com") + ), + Text(" and sometimes example.com (but not on Github, for example).") + )), + P(listOf(Text("Some text to show that the reference links can follow later."))) + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Windows Carriage Return Line Feed`() { + val kdoc = "text\r\ntext" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Text("text text") + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } +} + diff --git a/plugins/base/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt b/plugins/base/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt new file mode 100644 index 00000000..f9431bbb --- /dev/null +++ b/plugins/base/src/test/kotlin/multiplatform/BasicMultiplatformTest.kt @@ -0,0 +1,55 @@ +package multiplatform + +import org.junit.Assert.assertEquals +import org.junit.Test +import testApi.testRunner.AbstractCoreTest + +class BasicMultiplatformTest : AbstractCoreTest() { + + @Test + fun dataTestExample() { + val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("$testDataDir/jvmMain/") + } + } + } + + testFromData(configuration) { + pagesTransformationStage = { + assertEquals(6, it.children.firstOrNull()?.children?.count() ?: 0) + } + } + } + + @Test + fun inlineTestExample() { + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/multiplatform/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/multiplatform/Test.kt + |package multiplatform + | + |object Test { + | fun test2(str: String): Unit {println(str)} + |} + """.trimMargin(), + configuration + ) { + pagesGenerationStage = { + println(it.dri) + assertEquals(7, it.parentMap.size) + } + } + } +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt b/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt new file mode 100644 index 00000000..88e57ddb --- /dev/null +++ b/plugins/base/src/test/kotlin/pageMerger/PageNodeMergerTest.kt @@ -0,0 +1,127 @@ +package pageMerger + +import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.PageNode +import org.jetbrains.dokka.plugability.DokkaPlugin +import org.jetbrains.dokka.transformers.pages.DefaultPageMergerStrategy +import org.jetbrains.dokka.transformers.pages.SameMethodNamePageMergerStrategy +import org.jetbrains.dokka.utilities.DokkaLogger +import org.junit.Test +import testApi.testRunner.AbstractCoreTest + +class PageNodeMergerTest : AbstractCoreTest() { + + object SameNameStrategy : DokkaPlugin() { + val strategy by extending { CoreExtensions.pageMergerStrategy with SameMethodNamePageMergerStrategy } + } + + class DefaultStrategy(val strList: MutableList = mutableListOf()) : DokkaPlugin(), DokkaLogger { + val strategy by extending { CoreExtensions.pageMergerStrategy with DefaultPageMergerStrategy(this@DefaultStrategy) } + + override var warningsCount: Int = 0 + override var errorsCount: Int = 0 + + override fun debug(message: String) = TODO() + + override fun info(message: String) = TODO() + + override fun progress(message: String) = TODO() + + override fun warn(message: String) { + strList += message + } + + override fun error(message: String) = TODO() + + override fun report() = TODO() + } + + @Test + fun sameNameStrategyTest() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |fun testT(): Int = 1 + |fun testT(i: Int): Int = i + | + |object Test { + | fun test(): String = "" + | fun test(str: String): String = str + |} + """.trimMargin(), + configuration, + pluginOverrides = listOf(SameNameStrategy) + ) { + pagesTransformationStage = { + val allChildren = it.childrenRec().filterIsInstance() + val testT = allChildren.filter { it.name == "testT" } + val test = allChildren.filter { it.name == "test" } + + assert(testT.size == 1) { "There can be only one testT page" } + assert(testT.first().dri.size == 2) { "testT page should have 2 DRI, but has ${testT.first().dri.size}" } + + assert(test.size == 1) { "There can be only one test page" } + assert(test.first().dri.size == 2) { "test page should have 2 DRI, but has ${test.first().dri.size}" } + } + } + } + + @Test + fun defaultStrategyTest() { + val strList: MutableList = mutableListOf() + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt") + } + } + } + + testInline( + """ + |/src/main/kotlin/pageMerger/Test.kt + |package pageMerger + | + |fun testT(): Int = 1 + |fun testT(i: Int): Int = i + | + |object Test { + | fun test(): String = "" + | fun test(str: String): String = str + |} + """.trimMargin(), + configuration, + pluginOverrides = listOf(DefaultStrategy(strList)) + ) { + pagesTransformationStage = { root -> + val allChildren = root.childrenRec().filterIsInstance() + val testT = allChildren.filter { it.name == "testT" } + val test = allChildren.filter { it.name == "test" } + + assert(testT.size == 1) { "There can be only one testT page" } + assert(testT.first().dri.size == 1) { "testT page should have single DRI, but has ${testT.first().dri.size}" } + + assert(test.size == 1) { "There can be only one test page" } + assert(test.first().dri.size == 1) { "test page should have single DRI, but has ${test.first().dri.size}" } + + assert(strList.count() == 2) { "Expected 2 warnings, got ${strList.count()}" } + } + } + } + + fun PageNode.childrenRec(): List = listOf(this) + children.flatMap { it.childrenRec() } + +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt new file mode 100644 index 00000000..4753cb32 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt @@ -0,0 +1,15 @@ +package example + +/** + * Documentation for expected class Clock + * in common module + */ +expect open class Clock() { + fun getTime(): String + /** + * Time in minis + */ + fun getTimesInMillis(): String + fun getYear(): String +} + diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt new file mode 100644 index 00000000..c879dee7 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt @@ -0,0 +1,24 @@ +package example + +class House(val street: String, val number: Int) { + + /** + * The owner of the house + */ + var owner: String = "" + + /** + * The owner of the house + */ + val differentOwner: String = "" + + fun addFloor() {} + + class Basement { + val pickles : List = mutableListOf() + } + + companion object { + val DEFAULT = House("",0) + } +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt new file mode 100644 index 00000000..967cffcd --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt @@ -0,0 +1,21 @@ +package example + +import greeteer.Greeter +import kotlin.js.Date + +/** + * Documentation for actual class Clock in JS + */ +actual open class Clock { + actual fun getTime() = Date.now().toString() + fun onlyJsFunction(): Int = 42 + actual fun getTimesInMillis(): String = Date.now().toString() + + actual fun getYear(): String { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun main() { + Greeter().greet().also { println(it) } +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt new file mode 100644 index 00000000..8a52e2f3 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt @@ -0,0 +1,10 @@ +package greeteer + +import example.Clock + +class Greeter { + /** + * Some docs for the [greet] function + */ + fun greet() = Clock().let{ "Hello there! THe time is ${it.getTime()}" } +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt new file mode 100644 index 00000000..9ec01fb6 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt @@ -0,0 +1,34 @@ +package example + +import greeteer.Greeter + +actual open class Clock { + actual fun getTime(): String = System.currentTimeMillis().toString() + actual fun getTimesInMillis(): String = System.currentTimeMillis().toString() + + /** + * Documentation for onlyJVMFunction on... + * wait for it... + * ...JVM! + */ + fun onlyJVMFunction(): Double = 2.5 + /** + * Custom equals function + */ + override fun equals(other: Any?): Boolean { + return super.equals(other) + } + + open fun getDayOfTheWeek(): String { + TODO("not implemented") + } + actual fun getYear(): String { + TODO("not implemented") + } +} + +fun clockList() = listOf(Clock()) + +fun main() { + Greeter().greet().also { println(it) } +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt new file mode 100644 index 00000000..136ae5c8 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt @@ -0,0 +1,15 @@ +package example + +/** + * frgergergrthe + * */ +enum class ClockDays { + /** + * dfsdfsdfds + * */ + FIRST, + SECOND, // test2 + THIRD, // test3 + FOURTH, // test4 + FIFTH // test5 +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt new file mode 100644 index 00000000..40813b50 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt @@ -0,0 +1,32 @@ +package example + +import greeteer.Greeter + +class ParticularClock(private val clockDay: ClockDays) : Clock() { + + /** + * Rings bell [times] + */ + fun ringBell(times: Int) {} + + /** + * Uses provider [greeter] + */ + fun useGreeter(greeter: Greeter) { + + } + + /** + * Day of the week + */ + override fun getDayOfTheWeek() = clockDay.name +} + +/** + * A sample extension function + * When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$ + * @usesMathJax + */ +fun Clock.extensionFun() { + +} \ No newline at end of file diff --git a/plugins/build.gradle.kts b/plugins/build.gradle.kts index e29f1355..923fb48b 100644 --- a/plugins/build.gradle.kts +++ b/plugins/build.gradle.kts @@ -5,11 +5,12 @@ subprojects { dependencies { compileOnly(project(":core")) - compileOnly(kotlin("stdlib-jdk8")) // compileOnly(project(":coreDependencies", configuration = "shadow")) // uncomment if IntelliJ does not recognize pacakges from IntelliJ + implementation(kotlin("stdlib-jdk8")) + testImplementation(project(":core")) + testImplementation(project(":coreDependencies", configuration = "shadow")) testImplementation(project(":testApi")) - testImplementation(kotlin("stdlib-jdk8")) testImplementation("junit:junit:4.13") } } \ No newline at end of file -- cgit