Skip to content

Commit 530b10d

Browse files
committed
(WIP) add validation tests
1 parent bfa22da commit 530b10d

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

org.jacoco.core.test.validation.kotlin/src/org/jacoco/core/test/validation/kotlin/targets/KotlinSafeCallOperatorTarget.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,45 @@ object KotlinSafeCallOperatorTarget {
7676
fullCoverage(A(B("")))
7777
}
7878

79+
private fun safeCallFollowedByElvis() {
80+
fun nullOnly(b: B?): String =
81+
b?.c ?: "" // assertPartlyCovered(2, 2)
82+
83+
fun nonNullOnly(b: B?): String =
84+
b?.c ?: "" // assertPartlyCovered(2, 2)
85+
86+
fun fullCoverage(b: B?): String =
87+
b?.c ?: "" // assertFullyCovered(0, 4)
88+
89+
nullOnly(null)
90+
nonNullOnly(B(""))
91+
fullCoverage(null)
92+
fullCoverage(B(""))
93+
}
94+
95+
private fun safeCallChainFollowedByElvis() {
96+
fun nullOnly(a: A?): String =
97+
a?.b?.c ?: "" // assertPartlyCovered(3, 3)
98+
99+
fun nonNullOnly(a: A?): String =
100+
a?.b?.c ?: "" // assertPartlyCovered(3, 3)
101+
102+
fun fullCoverage(a: A?): String =
103+
a?.b?.c ?: "" // assertFullyCovered(0, 6)
104+
105+
nullOnly(null)
106+
nonNullOnly(A(B("")))
107+
fullCoverage(null)
108+
fullCoverage(A(B("")))
109+
}
110+
79111
@JvmStatic
80112
fun main(args: Array<String>) {
81113
safeCall()
82114
safeCallChain()
83115
safeCallChainMultiline()
116+
safeCallFollowedByElvis()
117+
safeCallChainFollowedByElvis()
84118
}
85119

86120
}

0 commit comments

Comments
 (0)