From e4a6e2d908b285a3a92a65d99322f810fb5ff37d Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Fri, 11 Jul 2014 19:49:25 +0400 Subject: Use more structural approach to testing using with(node) { ... } --- test/src/ClassTest.kt | 74 +++++++++++++++++++++++++++++++++--------------- test/src/FunctionTest.kt | 34 +++++++++++----------- test/src/PackageTest.kt | 45 +++++++++++++++-------------- 3 files changed, 93 insertions(+), 60 deletions(-) diff --git a/test/src/ClassTest.kt b/test/src/ClassTest.kt index be9a29b1..348e74d4 100644 --- a/test/src/ClassTest.kt +++ b/test/src/ClassTest.kt @@ -7,39 +7,67 @@ import com.jetbrains.dokka.* public class ClassTest { Test fun emptyClass() { verifyModel("test/data/classes/emptyClass.kt") { model -> - val item = model.nodes.single().members.single() - assertEquals(DocumentationNodeKind.Class, item.kind) - assertEquals("Klass", item.name) - assertEquals("", item.doc) - assertTrue(item.details.none()) - assertEquals("", item.members.single().name) - assertTrue(item.links.none()) + with(model.nodes.single().members.single()) { + assertEquals(DocumentationNodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals("", doc) + assertTrue(details.none()) + assertEquals("", members.single().name) + assertTrue(links.none()) + } } } Test fun classWithConstructor() { verifyModel("test/data/classes/classWithConstructor.kt") { model -> - val item = model.nodes.single().members.single() - assertEquals(DocumentationNodeKind.Class, item.kind) - assertEquals("Klass", item.name) - assertEquals("", item.doc) - assertTrue(item.details.none()) - assertEquals("", item.members.single().name) - assertTrue(item.links.none()) + with (model.nodes.single().members.single()) { + assertEquals(DocumentationNodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals("", doc) + assertTrue(details.none()) + assertTrue(links.none()) + + assertEquals(1, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals("", doc) + assertEquals(1, details.count()) + with(details.elementAt(0)) { + assertEquals("name", name) + assertEquals("", doc) + } + assertTrue(members.none()) + assertTrue(links.none()) + } + } } } Test fun classWithFunction() { verifyModel("test/data/classes/classWithFunction.kt") { model -> - val item = model.nodes.single().members.single() - assertEquals(DocumentationNodeKind.Class, item.kind) - assertEquals("Klass", item.name) - assertEquals("", item.doc) - assertTrue(item.details.none()) - assertEquals(2, item.members.count()) - assertEquals("", item.members.elementAt(0).name) - assertEquals("fn", item.members.elementAt(1).name) - assertTrue(item.links.none()) + with(model.nodes.single().members.single()) { + assertEquals(DocumentationNodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals("", doc) + assertTrue(details.none()) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals("", doc) + assertTrue(details.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(1)) { + assertEquals("fn", name) + assertEquals("", doc) + assertTrue(details.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } + } } } } \ No newline at end of file diff --git a/test/src/FunctionTest.kt b/test/src/FunctionTest.kt index e8afe97b..2c0955d1 100644 --- a/test/src/FunctionTest.kt +++ b/test/src/FunctionTest.kt @@ -8,30 +8,32 @@ import com.jetbrains.dokka.* public class FunctionTest { Test fun function() { verifyModel("test/data/functions/function.kt") { model -> - val item = model.nodes.single().members.single() - assertEquals(DocumentationNodeKind.Function, item.kind) - assertEquals("fn", item.name) - assertEquals("Function fn", item.doc) - assertTrue(item.details.none()) - assertTrue(item.members.none()) - assertTrue(item.links.none()) + with(model.nodes.single().members.single()) { + assertEquals(DocumentationNodeKind.Function, kind) + assertEquals("fn", name) + assertEquals("Function fn", doc) + assertTrue(details.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } } } Test fun functionWithParams() { verifyModel("test/data/functions/functionWithParams.kt") { model -> - val item = model.nodes.single().members.single() - assertEquals(DocumentationNodeKind.Function, item.kind) - assertEquals("function", item.name) - assertEquals("""Multiline + with(model.nodes.single().members.single()) { + assertEquals(DocumentationNodeKind.Function, kind) + assertEquals("function", name) + assertEquals("""Multiline Function Documentation""" - , item.doc) - assertEquals("x", item.details.single().name) - assertEquals(DocumentationNodeKind.Parameter, item.details.single().kind) + , doc) + assertEquals("x", details.single().name) + assertEquals(DocumentationNodeKind.Parameter, details.single().kind) - assertTrue(item.members.none()) - assertTrue(item.links.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } } } } \ No newline at end of file diff --git a/test/src/PackageTest.kt b/test/src/PackageTest.kt index 46e25c9f..6ab40ba6 100644 --- a/test/src/PackageTest.kt +++ b/test/src/PackageTest.kt @@ -7,37 +7,40 @@ import com.jetbrains.dokka.* public class PackageTest { Test fun rootPackage() { verifyModel("test/data/packages/rootPackage.kt") { model -> - val item = model.nodes.single() - assertEquals(DocumentationNodeKind.Package, item.kind) - assertEquals("", item.name) - assertEquals("", item.doc) - assertTrue(item.details.none()) - assertTrue(item.members.none()) - assertTrue(item.links.none()) + with(model.nodes.single()) { + assertEquals(DocumentationNodeKind.Package, kind) + assertEquals("", name) + assertEquals("", doc) + assertTrue(details.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } } } Test fun simpleNamePackage() { verifyModel("test/data/packages/simpleNamePackage.kt") { model -> - val item = model.nodes.single() - assertEquals(DocumentationNodeKind.Package, item.kind) - assertEquals("simple", item.name) - assertEquals("", item.doc) - assertTrue(item.details.none()) - assertTrue(item.members.none()) - assertTrue(item.links.none()) + with(model.nodes.single()) { + assertEquals(DocumentationNodeKind.Package, kind) + assertEquals("simple", name) + assertEquals("", doc) + assertTrue(details.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } } } Test fun dottedNamePackage() { verifyModel("test/data/packages/dottedNamePackage.kt") { model -> - val item = model.nodes.single() - assertEquals(DocumentationNodeKind.Package, item.kind) - assertEquals("dot.name", item.name) - assertEquals("", item.doc) - assertTrue(item.details.none()) - assertTrue(item.members.none()) - assertTrue(item.links.none()) + with(model.nodes.single()) { + assertEquals(DocumentationNodeKind.Package, kind) + assertEquals("dot.name", name) + assertEquals("", doc) + assertTrue(details.none()) + assertTrue(members.none()) + assertTrue(links.none()) + } } } } \ No newline at end of file -- cgit