-
-
Notifications
You must be signed in to change notification settings - Fork 755
/
FormattingRuleSpec.kt
94 lines (77 loc) · 2.5 KB
/
FormattingRuleSpec.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package io.gitlab.arturbosch.detekt.formatting
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.formatting.wrappers.NoLineBreakBeforeAssignment
import io.gitlab.arturbosch.detekt.test.assertThat
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
import java.nio.file.Paths
class FormattingRuleSpec {
private lateinit var subject: NoLineBreakBeforeAssignment
@BeforeEach
fun createSubject() {
subject = NoLineBreakBeforeAssignment(Config.empty)
}
@Nested
inner class `formatting rules can be suppressed` {
@Test
fun `does support suppression only on file level`() {
val findings = subject.lint(
"""
@file:Suppress("NoLineBreakBeforeAssignment")
fun main()
= Unit
""".trimIndent()
)
assertThat(findings).isEmpty()
}
@Test
fun `does not support suppression on node level`() {
val findings = subject.lint(
"""
@Suppress("NoLineBreakBeforeAssignment")
fun main()
= Unit
""".trimIndent()
)
assertThat(findings).hasSize(1)
}
}
@Nested
inner class `formatting rules have a signature` {
@Test
fun `has no package name`() {
val findings = subject.lint(
"""
fun main()
= Unit
""".trimIndent()
)
assertThat(findings.first().signature).isEqualTo("Test.kt:2")
}
@Test
fun `has a package name`() {
val findings = subject.lint(
"""
package test.test.test
fun main()
= Unit
""".trimIndent()
)
assertThat(findings.first().signature).isEqualTo("test.test.test.Test.kt:3")
}
}
@Test
fun `#3063_ formatting issues have an absolute path`() {
val expectedPath = Paths.get("/root/kotlin/test.kt").toString()
val findings = subject.lint(
"""
fun main()
= Unit
""",
expectedPath
)
assertThat(findings.first().location.filePath.absolutePath.toString()).isEqualTo(expectedPath)
}
}