aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/kotlin')
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt7
-rw-r--r--core/src/test/kotlin/javadoc/JavadocTest.kt25
-rw-r--r--core/src/test/kotlin/model/CommentTest.kt4
-rw-r--r--core/src/test/kotlin/model/TypeAliasTest.kt123
4 files changed, 155 insertions, 4 deletions
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 7f0922ba..6e4c44c8 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -27,8 +27,6 @@ class MarkdownFormatTest {
verifyMarkdownPackage("annotationClass", withKotlinRuntime = true)
}
- //TODO: Enable after typealias support
- @Ignore("Disabled until we will correctly support typealias")
@Test fun exceptionClass() {
verifyMarkdownNode("exceptionClass", withKotlinRuntime = true)
verifyMarkdownPackage("exceptionClass", withKotlinRuntime = true)
@@ -229,6 +227,11 @@ class MarkdownFormatTest {
verifyMarkdownNodeByName("qualifiedNameLink", "foo", withKotlinRuntime = true)
}
+ @Test fun typeAliases() {
+ verifyMarkdownNode("typeAliases")
+ verifyMarkdownPackage("typeAliases")
+ }
+
private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) {
verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output ->
markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members)
diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt
index 41d22b47..f7f86881 100644
--- a/core/src/test/kotlin/javadoc/JavadocTest.kt
+++ b/core/src/test/kotlin/javadoc/JavadocTest.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.javadoc
+import com.sun.javadoc.Type
import org.jetbrains.dokka.DokkaConsoleLogger
import org.jetbrains.dokka.tests.verifyModel
import org.junit.Assert.*
@@ -107,6 +108,30 @@ class JavadocTest {
}
}
+ @Test fun testTypeAliases() {
+ verifyJavadoc("testdata/javadoc/typealiases.kt", withKotlinRuntime = true) { doc ->
+ assertNull(doc.classNamed("B"))
+ assertNull(doc.classNamed("D"))
+
+ assertEquals("A", doc.classNamed("C")!!.superclass().name())
+ val methodParamType = doc.classNamed("TypealiasesKt")!!.methods()
+ .find { it.name() == "some" }!!.parameters().first()
+ .type()
+ assertEquals("kotlin.jvm.functions.Function1", methodParamType.qualifiedTypeName())
+ assertEquals("? super A, C", methodParamType.asParameterizedType().typeArguments()
+ .map(Type::qualifiedTypeName).joinToString())
+ }
+ }
+
+ @Test fun testKDocKeywordsOnMethod() {
+ verifyJavadoc("testdata/javadoc/kdocKeywordsOnMethod.kt", withKotlinRuntime = true) { doc ->
+ val method = doc.classNamed("KdocKeywordsOnMethodKt")!!.methods()[0]
+ assertEquals("@return [ContentText(text=value of a)]", method.tags("return").first().text())
+ assertEquals("@param a [ContentText(text=Some string)]", method.paramTags().first().text())
+ assertEquals("@throws FireException [ContentText(text=in case of fire)]", method.throwsTags().first().text())
+ }
+ }
+
private fun verifyJavadoc(name: String,
withJdk: Boolean = false,
withKotlinRuntime: Boolean = false,
diff --git a/core/src/test/kotlin/model/CommentTest.kt b/core/src/test/kotlin/model/CommentTest.kt
index 55fa3fc0..25fea48d 100644
--- a/core/src/test/kotlin/model/CommentTest.kt
+++ b/core/src/test/kotlin/model/CommentTest.kt
@@ -9,14 +9,14 @@ public class CommentTest {
@Test fun codeBlockComment() {
verifyModel("testdata/comments/codeBlockComment.kt") { model ->
with(model.members.single().members.first()) {
- assertEquals("""[code lang=brainfuck]
+ assertEqualsIgnoringSeparators("""[code lang=brainfuck]
|++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
|[/code]
|""".trimMargin(),
content.toTestString())
}
with(model.members.single().members.last()) {
- assertEquals("""[code]
+ assertEqualsIgnoringSeparators("""[code]
|a + b - c
|[/code]
|""".trimMargin(),
diff --git a/core/src/test/kotlin/model/TypeAliasTest.kt b/core/src/test/kotlin/model/TypeAliasTest.kt
new file mode 100644
index 00000000..812fd9dc
--- /dev/null
+++ b/core/src/test/kotlin/model/TypeAliasTest.kt
@@ -0,0 +1,123 @@
+package org.jetbrains.dokka.tests
+
+import junit.framework.TestCase.assertEquals
+import org.jetbrains.dokka.Content
+import org.jetbrains.dokka.NodeKind
+import org.junit.Test
+
+class TypeAliasTest {
+ @Test
+ fun testSimple() {
+ verifyModel("testdata/typealias/simple.kt") {
+ val pkg = it.members.single()
+ with(pkg.member(NodeKind.TypeAlias)) {
+ assertEquals(Content.Empty, content)
+ assertEquals("B", name)
+ assertEquals("A", detail(NodeKind.TypeAliasUnderlyingType).name)
+ }
+ }
+ }
+
+ @Test
+ fun testInheritanceFromTypeAlias() {
+ verifyModel("testdata/typealias/inheritanceFromTypeAlias.kt") {
+ val pkg = it.members.single()
+ with(pkg.member(NodeKind.TypeAlias)) {
+ assertEquals(Content.Empty, content)
+ assertEquals("Same", name)
+ assertEquals("Some", detail(NodeKind.TypeAliasUnderlyingType).name)
+ assertEquals("My", inheritors.single().name)
+ }
+ with(pkg.members(NodeKind.Class).find { it.name == "My" }!!) {
+ assertEquals("Same", detail(NodeKind.Supertype).name)
+ }
+ }
+ }
+
+ @Test
+ fun testChain() {
+ verifyModel("testdata/typealias/chain.kt") {
+ val pkg = it.members.single()
+ with(pkg.members(NodeKind.TypeAlias).find { it.name == "B" }!!) {
+ assertEquals(Content.Empty, content)
+ assertEquals("A", detail(NodeKind.TypeAliasUnderlyingType).name)
+ }
+ with(pkg.members(NodeKind.TypeAlias).find { it.name == "C" }!!) {
+ assertEquals(Content.Empty, content)
+ assertEquals("B", detail(NodeKind.TypeAliasUnderlyingType).name)
+ }
+ }
+ }
+
+ @Test
+ fun testDocumented() {
+ verifyModel("testdata/typealias/documented.kt") {
+ val pkg = it.members.single()
+ with(pkg.member(NodeKind.TypeAlias)) {
+ assertEquals("Just typealias", content.summary.toTestString())
+ }
+ }
+ }
+
+ @Test
+ fun testDeprecated() {
+ verifyModel("testdata/typealias/deprecated.kt") {
+ val pkg = it.members.single()
+ with(pkg.member(NodeKind.TypeAlias)) {
+ assertEquals(Content.Empty, content)
+ assertEquals("Deprecated", deprecation!!.name)
+ assertEquals("\"Not mainstream now\"", deprecation!!.detail(NodeKind.Parameter).detail(NodeKind.Value).name)
+ }
+ }
+ }
+
+ @Test
+ fun testGeneric() {
+ verifyModel("testdata/typealias/generic.kt") {
+ val pkg = it.members.single()
+ with(pkg.members(NodeKind.TypeAlias).find { it.name == "B" }!!) {
+ assertEquals("Any", detail(NodeKind.TypeAliasUnderlyingType).detail(NodeKind.Type).name)
+ }
+
+ with(pkg.members(NodeKind.TypeAlias).find { it.name == "C" }!!) {
+ assertEquals("T", detail(NodeKind.TypeAliasUnderlyingType).detail(NodeKind.Type).name)
+ assertEquals("T", detail(NodeKind.TypeParameter).name)
+ }
+ }
+ }
+
+ @Test
+ fun testFunctional() {
+ verifyModel("testdata/typealias/functional.kt") {
+ val pkg = it.members.single()
+ with(pkg.member(NodeKind.TypeAlias)) {
+ assertEquals("Function1", detail(NodeKind.TypeAliasUnderlyingType).name)
+ val typeParams = detail(NodeKind.TypeAliasUnderlyingType).details(NodeKind.Type)
+ assertEquals("A", typeParams.first().name)
+ assertEquals("B", typeParams.last().name)
+ }
+
+ with(pkg.member(NodeKind.Function)) {
+ assertEquals("Spell", detail(NodeKind.Parameter).detail(NodeKind.Type).name)
+ }
+ }
+ }
+
+ @Test
+ fun testAsTypeBoundWithVariance() {
+ verifyModel("testdata/typealias/asTypeBoundWithVariance.kt") {
+ val pkg = it.members.single()
+ with(pkg.members(NodeKind.Class).find { it.name == "C" }!!) {
+ val tParam = detail(NodeKind.TypeParameter)
+ assertEquals("out", tParam.detail(NodeKind.Modifier).name)
+ assertEquals("B", tParam.detail(NodeKind.Type).link(NodeKind.TypeAlias).name)
+ }
+
+ with(pkg.members(NodeKind.Class).find { it.name == "D" }!!) {
+ val tParam = detail(NodeKind.TypeParameter)
+ assertEquals("in", tParam.detail(NodeKind.Modifier).name)
+ assertEquals("B", tParam.detail(NodeKind.Type).link(NodeKind.TypeAlias).name)
+ }
+ }
+ }
+} \ No newline at end of file