aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinControlStructuresTarget.kt
blob: 4cb5732b64caebff61871dd183adfeefac134c23 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*******************************************************************************
 * Copyright (c) 2009, 2019 Mountainminds GmbH & Co. KG and Contributors
 * This program and the accompanying materials are made available under
 * the terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Evgeny Mandrikov - initial API and implementation
 *
 *******************************************************************************/
package org.jacoco.core.test.validation.kotlin.targets

import org.jacoco.core.test.validation.targets.Stubs.*

/**
 * Test target for Kotlin control structures.
 */
object KotlinControlStructuresTarget {

    private fun unconditionalExecution() {

        nop() // assertFullyCovered()

    }

    private fun missedIfBlock() {

        if (f()) { // assertFullyCovered(1, 1)
            nop() // assertNotCovered()
        } else {
            nop() // assertFullyCovered()
        }

    }

    private fun executedIfBlock() {

        if (t()) { // assertFullyCovered(1, 1)
            nop() // assertFullyCovered()
        } else {
            nop() // assertNotCovered()
        }

    }

    private fun missedWhileBlock() {

        while (f()) { // assertPartlyCovered(1, 1)
            nop() // assertNotCovered()
        }

    }

    private fun executedWhileBlock() {

        var i = 0
        while (i++ < 3) { // assertFullyCovered(0, 2)
            nop() // assertFullyCovered()
        }

    }

    private fun executedDoWhileBlock() {

        do {
            nop() // assertFullyCovered()
        } while (f()) // assertFullyCovered(1, 1)

    }

    private fun missedForBlock() {

        for (j in 0..-1) { // assertPartlyCovered(1, 1)
            nop() // assertNotCovered()
        }

    }

    private fun executedForBlock() {

        for (j in 0..0) { // assertFullyCovered(0, 2)
            nop() // assertFullyCovered()
        }

    }

    private fun missedForEachBlock() {

        for (o in emptyList<Any>()) { // assertPartlyCovered(1, 1)
            nop(o) // assertNotCovered()
        }

    }

    private fun executedForEachBlock() {

        for (o in setOf(Any())) { // assertFullyCovered(0,2)
            nop(o) // assertFullyCovered()
        }

    }

    private fun whenExpression() {

        when (i2()) { // assertFullyCovered(2, 1)
            1 -> nop() // assertNotCovered()
            2 -> nop() // assertFullyCovered()
            else -> nop() // assertNotCovered()
        }

    }

    private fun breakStatement() {

        while (true) {
            if (t()) {
                break // assertFullyCovered()
            }
            nop() // assertNotCovered()
        }

    }

    private fun continueStatement() {

        for (j in 0..0) {
            if (t()) {
                continue // assertFullyCovered()
            }
            nop() // assertNotCovered()
        }

    }

    private fun implicitReturn() {
    } // assertFullyCovered()

    private fun explicitReturn() {

        return // assertFullyCovered()

    } // assertEmpty()

    @JvmStatic
    fun main(args: Array<String>) {
        unconditionalExecution()
        missedIfBlock()
        executedIfBlock()
        missedWhileBlock()
        executedWhileBlock()
        executedDoWhileBlock()
        missedForBlock()
        executedForBlock()
        missedForEachBlock()
        executedForEachBlock()
        whenExpression()
        breakStatement()
        continueStatement()
        implicitReturn()
        explicitReturn()
    }

}