forked from detekt/detekt
/
ClassNamingSpec.kt
106 lines (88 loc) · 2.75 KB
/
ClassNamingSpec.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
95
96
97
98
99
100
101
102
103
104
105
106
package io.gitlab.arturbosch.detekt.rules.naming
import io.gitlab.arturbosch.detekt.test.TestConfig
import io.gitlab.arturbosch.detekt.test.assertThat
import io.gitlab.arturbosch.detekt.test.compileAndLint
import org.junit.jupiter.api.Test
class ClassNamingSpec {
@Test
fun `should detekt no violations for abstract class implementation`() {
val code = """
abstract class AbstractClass {
abstract fun foo()
}
val foo = object : AbstractClass() {
override fun foo() {}
}
""".trimIndent()
assertThat(ClassNaming().compileAndLint(code)).isEmpty()
}
@Test
fun `should use custom name for method and class`() {
val config = TestConfig(mapOf(ClassNaming.CLASS_PATTERN to "^aBbD$"))
assertThat(
ClassNaming(config).compileAndLint(
"""
class aBbD{}
""".trimIndent()
)
).isEmpty()
}
@Test
fun `should detect no violations class with numbers`() {
val code = """
class MyClassWithNumbers5
""".trimIndent()
assertThat(ClassNaming().compileAndLint(code)).isEmpty()
}
@Test
fun `should detect no violations`() {
val code = """
class NamingConventions {
}
""".trimIndent()
assertThat(ClassNaming().compileAndLint(code)).isEmpty()
}
@Test
fun `should detect no violations with class using backticks`() {
val code = """
class `NamingConventions`
""".trimIndent()
assertThat(ClassNaming().compileAndLint(code)).isEmpty()
}
@Test
fun `should detect because it have a _`() {
val code = """
class _NamingConventions
""".trimIndent()
assertThat(ClassNaming().compileAndLint(code))
.hasSize(1)
.hasTextLocations(6 to 24)
}
@Test
fun `should detect because it have starts with lowercase`() {
val code = """
class namingConventions {}
""".trimIndent()
assertThat(ClassNaming().compileAndLint(code))
.hasSize(1)
.hasTextLocations(6 to 23)
}
@Test
fun `should ignore the issue by alias suppression`() {
val code = """
@Suppress("ClassName")
class namingConventions {}
""".trimIndent()
assertThat(ClassNaming().compileAndLint(code)).isEmpty()
}
@Test
fun `should not detect any`() {
val code = """
data class D(val i: Int, val j: Int)
fun doStuff() {
val (_, HOLY_GRAIL) = D(5, 4)
}
""".trimIndent()
assertThat(ClassNaming().compileAndLint(code)).isEmpty()
}
}