aboutsummaryrefslogtreecommitdiff
path: root/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/src')
-rw-r--r--test/src/TestAPI.kt56
-rw-r--r--test/src/format/HtmlFormatTest.kt10
-rw-r--r--test/src/format/MarkdownFormatTest.kt10
-rw-r--r--test/src/model/JavaTest.kt69
4 files changed, 88 insertions, 57 deletions
diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt
index 4a0e4fb4..82353610 100644
--- a/test/src/TestAPI.kt
+++ b/test/src/TestAPI.kt
@@ -2,6 +2,7 @@ package org.jetbrains.dokka.tests
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.util.Disposer
+import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.dokka.*
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
@@ -66,11 +67,34 @@ public fun verifyModel(source: String,
verifier = verifier)
}
-public fun verifyPackageMember(kotlinSource: String,
+public fun verifyPackageMember(source: String,
withJdk: Boolean = false,
withKotlinRuntime: Boolean = false,
verifier: (DocumentationNode) -> Unit) {
- verifyModel(kotlinSource, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) { model ->
+ verifyModel(source, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) { model ->
+ val pkg = model.members.single()
+ verifier(pkg.members.single())
+ }
+}
+
+public fun verifyJavaModel(source: String,
+ withKotlinRuntime: Boolean = false,
+ verifier: (DocumentationModule) -> Unit) {
+ val tempDir = FileUtil.createTempDirectory("dokka", "")
+ try {
+ val sourceFile = File(source)
+ FileUtil.copy(sourceFile, File(tempDir, sourceFile.name))
+ verifyModel(JavaSourceRoot(tempDir), withJdk = true, withKotlinRuntime = withKotlinRuntime, verifier = verifier)
+ }
+ finally {
+ FileUtil.delete(tempDir)
+ }
+}
+
+public fun verifyJavaPackageMember(source: String,
+ withKotlinRuntime: Boolean = false,
+ verifier: (DocumentationNode) -> Unit) {
+ verifyJavaModel(source, withKotlinRuntime) { model ->
val pkg = model.members.single()
verifier(pkg.members.single())
}
@@ -82,15 +106,22 @@ public fun verifyOutput(roots: Array<ContentRoot>,
withKotlinRuntime: Boolean = false,
outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
verifyModel(*roots, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) {
- val output = StringBuilder()
- outputGenerator(it, output)
- val ext = outputExtension.removePrefix(".")
- val path = roots.first().path
- val expectedOutput = File(path.replaceAfterLast(".", ext, path + "." + ext)).readText()
- assertEqualsIgnoringSeparators(expectedOutput, output.toString())
+ verifyModelOutput(it, outputExtension, outputGenerator, roots.first().path)
}
}
+private fun verifyModelOutput(it: DocumentationModule,
+ outputExtension: String,
+ outputGenerator: (DocumentationModule, StringBuilder) -> Unit,
+ sourcePath: String) {
+ val output = StringBuilder()
+ outputGenerator(it, output)
+ val ext = outputExtension.removePrefix(".")
+ val path = sourcePath
+ val expectedOutput = File(path.replaceAfterLast(".", ext, path + "." + ext)).readText()
+ assertEqualsIgnoringSeparators(expectedOutput, output.toString())
+}
+
public fun verifyOutput(path: String,
outputExtension: String,
withJdk: Boolean = false,
@@ -99,6 +130,15 @@ public fun verifyOutput(path: String,
verifyOutput(arrayOf(contentRootFromPath(path)), outputExtension, withJdk, withKotlinRuntime, outputGenerator)
}
+public fun verifyJavaOutput(path: String,
+ outputExtension: String,
+ withKotlinRuntime: Boolean = false,
+ outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
+ verifyJavaModel(path, withKotlinRuntime) { model ->
+ verifyModelOutput(model, outputExtension, outputGenerator, path)
+ }
+}
+
public fun assertEqualsIgnoringSeparators(expectedOutput: String, output: String) {
Assert.assertEquals(expectedOutput.replace("\r\n", "\n"), output.replace("\r\n", "\n"))
}
diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt
index 66fd0fee..752e4424 100644
--- a/test/src/format/HtmlFormatTest.kt
+++ b/test/src/format/HtmlFormatTest.kt
@@ -99,31 +99,31 @@ public class HtmlFormatTest {
}
@Test fun javaSupertypeLink() {
- verifyOutput("test/data/format/javaSupertype.java", ".html") { model, output ->
+ verifyJavaOutput("test/data/format/javaSupertype.java", ".html") { model, output ->
htmlService.appendNodes(tempLocation, output, model.members.single().members.single { it.name == "C"}.members.filter { it.name == "Bar"} )
}
}
@Test fun javaLinkTag() {
- verifyOutput("test/data/format/javaLinkTag.java", ".html", withJdk = true) { model, output ->
+ verifyJavaOutput("test/data/format/javaLinkTag.java", ".html") { model, output ->
htmlService.appendNodes(tempLocation, output, model.members.single().members)
}
}
@Test fun javaLinkTagWithLabel() {
- verifyOutput("test/data/format/javaLinkTagWithLabel.java", ".html", withJdk = true) { model, output ->
+ verifyJavaOutput("test/data/format/javaLinkTagWithLabel.java", ".html") { model, output ->
htmlService.appendNodes(tempLocation, output, model.members.single().members)
}
}
@Test fun javaSeeTag() {
- verifyOutput("test/data/format/javaSeeTag.java", ".html", withJdk = true) { model, output ->
+ verifyJavaOutput("test/data/format/javaSeeTag.java", ".html") { model, output ->
htmlService.appendNodes(tempLocation, output, model.members.single().members)
}
}
@Test fun javaDeprecated() {
- verifyOutput("test/data/format/javaDeprecated.java", ".html") { model, output ->
+ verifyJavaOutput("test/data/format/javaDeprecated.java", ".html") { model, output ->
htmlService.appendNodes(tempLocation, output, model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" })
}
}
diff --git a/test/src/format/MarkdownFormatTest.kt b/test/src/format/MarkdownFormatTest.kt
index bb61fa1c..1a09ae60 100644
--- a/test/src/format/MarkdownFormatTest.kt
+++ b/test/src/format/MarkdownFormatTest.kt
@@ -121,25 +121,25 @@ public class MarkdownFormatTest {
}
@Test fun javadocHtml() {
- verifyOutput("test/data/format/javadocHtml.java", ".md", withJdk = true) { model, output ->
+ verifyJavaOutput("test/data/format/javadocHtml.java", ".md") { model, output ->
markdownService.appendNodes(tempLocation, output, model.members.single().members)
}
}
@Test fun javaCodeLiteralTags() {
- verifyOutput("test/data/format/javaCodeLiteralTags.java", ".md", withJdk = true) { model, output ->
+ verifyJavaOutput("test/data/format/javaCodeLiteralTags.java", ".md") { model, output ->
markdownService.appendNodes(tempLocation, output, model.members.single().members)
}
}
@Test fun javaCodeInParam() {
- verifyOutput("test/data/format/javaCodeInParam.java", ".md", withJdk = true) { model, output ->
+ verifyJavaOutput("test/data/format/javaCodeInParam.java", ".md") { model, output ->
markdownService.appendNodes(tempLocation, output, model.members.single().members)
}
}
@Test fun javaSpaceInAuthor() {
- verifyOutput("test/data/format/javaSpaceInAuthor.java", ".md", withJdk = true) { model, output ->
+ verifyJavaOutput("test/data/format/javaSpaceInAuthor.java", ".md") { model, output ->
markdownService.appendNodes(tempLocation, output, model.members.single().members)
}
}
@@ -157,7 +157,7 @@ public class MarkdownFormatTest {
}
@Test fun javadocOrderedList() {
- verifyOutput("test/data/format/javadocOrderedList.java", ".md", withJdk = true) { model, output ->
+ verifyJavaOutput("test/data/format/javadocOrderedList.java", ".md") { model, output ->
markdownService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == "Bar" })
}
}
diff --git a/test/src/model/JavaTest.kt b/test/src/model/JavaTest.kt
index 5ec29b25..0633a5cc 100644
--- a/test/src/model/JavaTest.kt
+++ b/test/src/model/JavaTest.kt
@@ -9,12 +9,11 @@ import kotlin.test.assertTrue
public class JavaTest {
@Test fun function() {
- verifyPackageMember("test/data/java/member.java") { cls ->
+ verifyJavaPackageMember("test/data/java/member.java") { cls ->
assertEquals("Test", cls.name)
assertEquals(DocumentationNode.Kind.Class, cls.kind)
- with(cls.members.single()) {
+ with(cls.members(DocumentationNode.Kind.Function).single()) {
assertEquals("fn", name)
- assertEquals(DocumentationNode.Kind.Function, kind)
assertEquals("Summary for Function", content.summary.toTestString().trimEnd())
assertEquals(3, content.sections.size)
with(content.sections[0]) {
@@ -47,8 +46,9 @@ public class JavaTest {
}
@Test fun memberWithModifiers() {
- verifyPackageMember("test/data/java/memberWithModifiers.java") { cls ->
- assertEquals("abstract", cls.details[0].name)
+ verifyJavaPackageMember("test/data/java/memberWithModifiers.java") { cls ->
+ val modifiers = cls.details(DocumentationNode.Kind.Modifier).map { it.name }
+ assertTrue("abstract" in modifiers)
with(cls.members.single { it.name == "fn" }) {
assertEquals("protected", details[0].name)
}
@@ -59,7 +59,7 @@ public class JavaTest {
}
@Test fun superClass() {
- verifyPackageMember("test/data/java/superClass.java") { cls ->
+ verifyJavaPackageMember("test/data/java/superClass.java") { cls ->
val superTypes = cls.details(DocumentationNode.Kind.Supertype)
assertEquals(2, superTypes.size)
assertEquals("Exception", superTypes[0].name)
@@ -68,22 +68,21 @@ public class JavaTest {
}
@Test fun arrayType() {
- verifyPackageMember("test/data/java/arrayType.java") { cls ->
- with(cls.members.single()) {
+ verifyJavaPackageMember("test/data/java/arrayType.java") { cls ->
+ with(cls.members(DocumentationNode.Kind.Function).single()) {
val type = detail(DocumentationNode.Kind.Type)
assertEquals("Array", type.name)
assertEquals("String", type.detail(DocumentationNode.Kind.Type).name)
with(details(DocumentationNode.Kind.Parameter).single()) {
val parameterType = detail(DocumentationNode.Kind.Type)
- assertEquals("Array", parameterType.name)
- assertEquals("Int", parameterType.detail(DocumentationNode.Kind.Type).name)
+ assertEquals("IntArray", parameterType.name)
}
}
}
}
@Test fun typeParameter() {
- verifyPackageMember("test/data/java/typeParameter.java") { cls ->
+ verifyJavaPackageMember("test/data/java/typeParameter.java") { cls ->
val typeParameters = cls.details(DocumentationNode.Kind.TypeParameter)
with(typeParameters.single()) {
assertEquals("T", name)
@@ -92,7 +91,7 @@ public class JavaTest {
assertEquals("T", detail(DocumentationNode.Kind.Type).name)
}
}
- with(cls.members.single()) {
+ with(cls.members(DocumentationNode.Kind.Function).single()) {
val methodTypeParameters = details(DocumentationNode.Kind.TypeParameter)
with(methodTypeParameters.single()) {
assertEquals("E", name)
@@ -102,7 +101,7 @@ public class JavaTest {
}
@Test fun constructors() {
- verifyPackageMember("test/data/java/constructors.java") { cls ->
+ verifyJavaPackageMember("test/data/java/constructors.java") { cls ->
val constructors = cls.members(DocumentationNode.Kind.Constructor)
assertEquals(2, constructors.size)
with(constructors[0]) {
@@ -112,17 +111,17 @@ public class JavaTest {
}
@Test fun innerClass() {
- verifyPackageMember("test/data/java/innerClass.java") { cls ->
+ verifyJavaPackageMember("test/data/java/innerClass.java") { cls ->
val innerClass = cls.members(DocumentationNode.Kind.Class).single()
assertEquals("D", innerClass.name)
}
}
@Test fun varargs() {
- verifyPackageMember("test/data/java/varargs.java") { cls ->
+ verifyJavaPackageMember("test/data/java/varargs.java") { cls ->
val fn = cls.members(DocumentationNode.Kind.Function).single()
val param = fn.detail(DocumentationNode.Kind.Parameter)
- assertEquals("vararg", param.annotations.first().name)
+ assertEquals("vararg", param.details(DocumentationNode.Kind.Modifier).first().name)
val psiType = param.detail(DocumentationNode.Kind.Type)
assertEquals("String", psiType.name)
assertTrue(psiType.details(DocumentationNode.Kind.Type).isEmpty())
@@ -130,26 +129,28 @@ public class JavaTest {
}
@Test fun fields() {
- verifyPackageMember("test/data/java/field.java") { cls ->
+ verifyJavaPackageMember("test/data/java/field.java") { cls ->
val i = cls.members(DocumentationNode.Kind.Property).single { it.name == "i" }
assertEquals("Int", i.detail(DocumentationNode.Kind.Type).name)
assertTrue("var" in i.details(DocumentationNode.Kind.Modifier).map { it.name })
- val s = cls.members(DocumentationNode.Kind.CompanionObjectProperty).single { it.name == "s" }
+
+ val s = cls.members(DocumentationNode.Kind.Property).single { it.name == "s" }
assertEquals("String", s.detail(DocumentationNode.Kind.Type).name)
assertFalse("var" in s.details(DocumentationNode.Kind.Modifier).map { it.name })
+ assertTrue("static" in s.details(DocumentationNode.Kind.Modifier).map { it.name })
}
}
@Test fun staticMethod() {
- verifyPackageMember("test/data/java/staticMethod.java") { cls ->
- val m = cls.members(DocumentationNode.Kind.CompanionObjectFunction).single { it.name == "foo" }
- assertFalse("static" in m.details(DocumentationNode.Kind.Modifier).map { it.name })
+ verifyJavaPackageMember("test/data/java/staticMethod.java") { cls ->
+ val m = cls.members(DocumentationNode.Kind.Function).single { it.name == "foo" }
+ assertTrue("static" in m.details(DocumentationNode.Kind.Modifier).map { it.name })
}
}
@Test fun annotatedAnnotation() {
- verifyPackageMember("test/data/java/annotatedAnnotation.java") { cls ->
- assertEquals(2, cls.annotations.size)
+ verifyJavaPackageMember("test/data/java/annotatedAnnotation.java") { cls ->
+ assertEquals(1, cls.annotations.size)
with(cls.annotations[0]) {
assertEquals(1, details.count())
with(details[0]) {
@@ -157,7 +158,7 @@ public class JavaTest {
assertEquals(1, details.count())
with(details[0]) {
assertEquals(DocumentationNode.Kind.Value, kind)
- assertEquals("RetentionPolicy.RUNTIME", name)
+ assertEquals("[AnnotationTarget.FIELD, AnnotationTarget.CLASS, AnnotationTarget.FILE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER]", name)
}
}
}
@@ -165,31 +166,21 @@ public class JavaTest {
}
@Test fun deprecation() {
- verifyPackageMember("test/data/java/deprecation.java", withJdk = true) { cls ->
+ verifyJavaPackageMember("test/data/java/deprecation.java") { cls ->
val fn = cls.members(DocumentationNode.Kind.Function).single()
- with(fn.deprecation!!) {
- assertEquals(1, details.count())
- with(details[0]) {
- assertEquals(DocumentationNode.Kind.Parameter, kind)
- assertEquals(1, details.count())
- with(details[0]) {
- assertEquals(DocumentationNode.Kind.Value, kind)
- assertEquals("This should no longer be used", name)
- }
- }
- }
+ assertEquals("This should no longer be used", fn.deprecation!!.content.toTestString())
}
}
@Test fun javaLangObject() {
- verifyPackageMember("test/data/java/javaLangObject.java", withJdk = true) { cls ->
+ verifyJavaPackageMember("test/data/java/javaLangObject.java") { cls ->
val fn = cls.members(DocumentationNode.Kind.Function).single()
assertEquals("Any", fn.detail(DocumentationNode.Kind.Type).name)
}
}
@Test fun enumValues() {
- verifyPackageMember("test/data/java/enumValues.java", withJdk = true) { cls ->
+ verifyJavaPackageMember("test/data/java/enumValues.java") { cls ->
val superTypes = cls.details(DocumentationNode.Kind.Supertype)
assertEquals(0, superTypes.size)
assertEquals(1, cls.members(DocumentationNode.Kind.EnumItem).size)
@@ -197,7 +188,7 @@ public class JavaTest {
}
@Test fun inheritorLinks() {
- verifyPackageMember("test/data/java/inheritorLinks.java") { cls ->
+ verifyJavaPackageMember("test/data/java/inheritorLinks.java") { cls ->
val fooClass = cls.members.single { it.name == "Foo" }
val inheritors = fooClass.references(DocumentationReference.Kind.Inheritor)
assertEquals(1, inheritors.size)