forked from detekt/detekt
/
IndentationSpec.kt
75 lines (60 loc) · 2.05 KB
/
IndentationSpec.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
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
package io.gitlab.arturbosch.detekt.formatting
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.formatting.wrappers.Indentation
import io.gitlab.arturbosch.detekt.test.TestConfig
import io.gitlab.arturbosch.detekt.test.assert
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
class IndentationSpec {
private lateinit var subject: Indentation
@BeforeEach
fun createSubject() {
subject = Indentation(Config.empty)
}
@Nested
inner class `indentation level equals 1` {
val code = "fun main() {\n println()\n}"
@Nested
inner class `indentation level config of default` {
@Test
fun `reports wrong indentation level`() {
assertThat(subject.lint(code)).hasSize(1)
}
@Test
fun `places finding location to the indentation`() {
subject.lint(code).assert()
.hasStartSourceLocation(2, 1)
.hasTextLocations(13 to 14)
}
}
@Test
fun `does not report when using an indentation level config of 1`() {
val config = TestConfig("indentSize" to "1")
assertThat(Indentation(config).lint(code)).isEmpty()
}
}
@Test
fun `does not report correct indentation level`() {
val code = "fun main() {\n println()\n}"
assertThat(subject.lint(code)).isEmpty()
}
@Nested
inner class `parameter list indent size equals 1` {
val code = """
fun f(
a: Int
) {}
""".trimIndent()
@Test
fun `reports wrong indent size`() {
assertThat(subject.lint(code)).hasSize(1)
}
@Test
fun `does not report when using an indentation level config of 1`() {
val config = TestConfig("indentSize" to "1")
assertThat(Indentation(config).lint(code)).isEmpty()
}
}
}