aboutsummaryrefslogtreecommitdiff
path: root/test/src/model/FunctionTest.kt
blob: 217e97f4688f4db8cc42c5d64de0311e54620fd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package org.jetbrains.dokka.tests

import org.junit.Test
import kotlin.test.*
import org.jetbrains.dokka.*

public class FunctionTest {
    Test fun function() {
        verifyModel("test/data/functions/function.kt") { model ->
            with(model.nodes.single().members.single()) {
                assertEquals("fn", name)
                assertEquals(DocumentationNodeKind.Function, kind)
                assertEquals("Function fn", doc)
                assertTrue(details.none())
                assertTrue(members.none())
                assertTrue(links.none())
            }
        }
    }

    Test fun functionWithReceiver() {
        verifyModel("test/data/functions/functionWithReceiver.kt") { model ->
            with(model.nodes.single().members.single()) {
                assertEquals("fn", name)
                assertEquals(DocumentationNodeKind.Function, kind)
                assertEquals("Function with receiver", doc)
                with(details.single()) {
                    assertEquals("<this>", name)
                    assertEquals(DocumentationNodeKind.Receiver, kind)
                    assertEquals("", doc)
                    assertTrue(details.none())
                    assertTrue(members.none())
                    assertTrue(links.none())
                }
                assertTrue(members.none())
                assertTrue(links.none())
            }
        }
    }

    Test fun genericFunction() {
        verifyModel("test/data/functions/genericFunction.kt") { model ->
            with(model.nodes.single().members.single()) {
                assertEquals("generic", name)
                assertEquals(DocumentationNodeKind.Function, kind)
                assertEquals("generic function", doc)

                with(details.single()) {
                    assertEquals("T", name)
                    assertEquals(DocumentationNodeKind.TypeParameter, kind)
                    assertEquals("", doc)
                    assertTrue(details.none())
                    assertTrue(members.none())
                    assertTrue(links.none())
                }

                assertTrue(members.none())
                assertTrue(links.none())
            }
        }
    }
    Test fun genericFunctionWithConstraints() {
        verifyModel("test/data/functions/genericFunctionWithConstraints.kt") { model ->
            with(model.nodes.single().members.single()) {
                assertEquals("generic", name)
                assertEquals(DocumentationNodeKind.Function, kind)
                assertEquals("generic function", doc)

                with(details.single()) {
                    assertEquals("T", name)
                    assertEquals(DocumentationNodeKind.TypeParameter, kind)
                    assertEquals("", doc)
                    with(details.single()) {
                        assertEquals("CharSequence", name)
                        assertEquals(DocumentationNodeKind.UpperBound, kind)
                        assertEquals("", doc)
                        assertTrue(details.none())
                        assertTrue(members.none())
                        assertTrue(links.none())
                    }
                    assertTrue(members.none())
                    assertTrue(links.none())
                }

                assertTrue(members.none())
                assertTrue(links.none())
            }
        }
    }

    Test fun functionWithParams() {
        verifyModel("test/data/functions/functionWithParams.kt") { model ->
            with(model.nodes.single().members.single()) {
                assertEquals("function", name)
                assertEquals(DocumentationNodeKind.Function, kind)
                assertEquals("""Multiline
Function
Documentation"""
                             , doc)
                with(details.single()) {
                    assertEquals("x", name)
                    assertEquals(DocumentationNodeKind.Parameter, kind)
                    assertEquals("parameter", doc)
                    assertTrue(details.none())
                    assertTrue(members.none())
                    assertTrue(links.none())
                }

                assertTrue(members.none())
                assertTrue(links.none())
            }
        }
    }
}