-
-
Notifications
You must be signed in to change notification settings - Fork 755
/
DuplicateCaseInWhenExpressionSpec.kt
42 lines (37 loc) · 1.25 KB
/
DuplicateCaseInWhenExpressionSpec.kt
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
package io.gitlab.arturbosch.detekt.rules.bugs
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.test.compileAndLint
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
class DuplicateCaseInWhenExpressionSpec {
private val subject = DuplicateCaseInWhenExpression(Config.empty)
@Test
fun `reports duplicated label in when`() {
val code = """
fun f() {
when (1) {
1 -> println()
1 -> kotlin.io.println()
1, 2 -> println()
1, 2 -> kotlin.io.println()
else -> println()
}
}
""".trimIndent()
val result = subject.compileAndLint(code)
assertThat(result).hasSize(1)
assertThat(result.first().message).isEqualTo("When expression has multiple case statements for 1; 1, 2.")
}
@Test
fun `does not report duplicated label in when`() {
val code = """
fun f() {
when (1) {
1 -> println()
else -> println()
}
}
""".trimIndent()
assertThat(subject.compileAndLint(code)).isEmpty()
}
}