aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt
blob: 472581e733abf645f3cb2558d782238ec1b42f5e (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
package model

import org.jetbrains.dokka.DokkaSourceSetID
import org.jetbrains.dokka.model.CompositeSourceSetID
import org.jetbrains.dokka.model.plus
import kotlin.test.*

class CompositeSourceSetIDTest {

    @Test
    fun `constructor fails with empty collection`() {
        assertFailsWith<IllegalArgumentException>("Expected no construction of empty `CompositeSourceSetID`") {
            CompositeSourceSetID(emptyList())
        }
    }

    @Test
    fun `merged for single source set`() {
        val sourceSetID = DokkaSourceSetID("module", "sourceSet")
        val composite = CompositeSourceSetID(sourceSetID)

        assertEquals(
            composite.merged, sourceSetID,
            "Expected merged source set id to be equal to single child"
        )
    }

    @Test
    fun `merged with multiple source sets`() {
        val composite = CompositeSourceSetID(
            listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2"), DokkaSourceSetID("m3", "s3"))
        )

        assertEquals(
            DokkaSourceSetID("m1+m2+m3", "s1+s2+s3"), composite.merged,
            "Expected merged source set id to concatenate source sets"
        )
    }

    @Test
    fun `contains with child sourceSetID`() {
        val composite = CompositeSourceSetID(listOf(DokkaSourceSetID("m1", "s1"), DokkaSourceSetID("m2", "s2")))

        assertFalse(
            DokkaSourceSetID("m3", "s3") in composite,
            "Expected source set id not being contained in composite"
        )

        assertTrue(
            DokkaSourceSetID("m1", "s1") in composite,
            "Expected child source set id being contained in composite"
        )

        assertTrue(
            DokkaSourceSetID("m1+m2", "s1+s2") in composite,
            "Expected merged source set id being contained in composite"
        )
    }

    @Test
    fun `plus operator`() {
        val composite = DokkaSourceSetID("m1", "s1") + DokkaSourceSetID("m2", "s2") + DokkaSourceSetID("m3", "s3")
        assertEquals(
            DokkaSourceSetID("m1+m2+m3", "s1+s2+s3"), composite.merged,
            "Expected all three source sets being merged in order"
        )
    }
}