aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/kotlin/model/PropertyTest.kt
blob: 716aac547677be302b9956c9a4605d61dfcc61fa (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
package org.jetbrains.dokka.tests

import org.jetbrains.dokka.Content
import org.jetbrains.dokka.DocumentationNode
import org.jetbrains.dokka.DocumentationReference
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

public class PropertyTest {
    @Test fun valueProperty() {
        verifyModel("testdata/properties/valueProperty.kt") { model ->
            with(model.members.single().members.single()) {
                assertEquals("property", name)
                assertEquals(DocumentationNode.Kind.Property, kind)
                assertEquals(Content.Empty, content)
                assertEquals("String", detail(DocumentationNode.Kind.Type).name)
                assertTrue(members.none())
                assertTrue(links.none())
            }
        }
    }

    @Test fun variableProperty() {
        verifyModel("testdata/properties/variableProperty.kt") { model ->
            with(model.members.single().members.single()) {
                assertEquals("property", name)
                assertEquals(DocumentationNode.Kind.Property, kind)
                assertEquals(Content.Empty, content)
                assertEquals("String", detail(DocumentationNode.Kind.Type).name)
                assertTrue(members.none())
                assertTrue(links.none())
            }
        }
    }

    @Test fun valuePropertyWithGetter() {
        verifyModel("testdata/properties/valuePropertyWithGetter.kt") { model ->
            with(model.members.single().members.single()) {
                assertEquals("property", name)
                assertEquals(DocumentationNode.Kind.Property, kind)
                assertEquals(Content.Empty, content)
                assertEquals("String", detail(DocumentationNode.Kind.Type).name)
                assertTrue(links.none())
                assertTrue(members.none())
            }
        }
    }

    @Test fun variablePropertyWithAccessors() {
        verifyModel("testdata/properties/variablePropertyWithAccessors.kt") { model ->
            with(model.members.single().members.single()) {
                assertEquals("property", name)
                assertEquals(DocumentationNode.Kind.Property, kind)
                assertEquals(Content.Empty, content)
                assertEquals("String", detail(DocumentationNode.Kind.Type).name)
                val modifiers = details(DocumentationNode.Kind.Modifier).map { it.name }
                assertTrue("final" in modifiers)
                assertTrue("public" in modifiers)
                assertTrue("var" in modifiers)
                assertTrue(links.none())
                assertTrue(members.none())
            }
        }
    }

    @Test fun annotatedProperty() {
        verifyModel("testdata/properties/annotatedProperty.kt", withKotlinRuntime = true) { model ->
            with(model.members.single().members.single()) {
                assertEquals(1, annotations.count())
                with(annotations[0]) {
                    assertEquals("Volatile", name)
                    assertEquals(Content.Empty, content)
                    assertEquals(DocumentationNode.Kind.Annotation, kind)
                }
            }
        }
    }

    @Test fun propertyWithReceiver() {
        verifyModel("testdata/properties/propertyWithReceiver.kt") { model ->
            with(model.members.single().members.single()) {
                assertEquals("kotlin.String", name)
                assertEquals(DocumentationNode.Kind.ExternalClass, kind)
                with(members.single()) {
                    assertEquals("foobar", name)
                    assertEquals(DocumentationNode.Kind.Property, kind)
                }
            }
        }
    }

    @Test fun propertyOverride() {
        verifyModel("testdata/properties/propertyOverride.kt") { model ->
            with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) {
                assertEquals("xyzzy", name)
                val override = references(DocumentationReference.Kind.Override).single().to
                assertEquals("xyzzy", override.name)
                assertEquals("Foo", override.owner!!.name)
            }
        }
    }
}