-
-
Notifications
You must be signed in to change notification settings - Fork 757
/
UnnecessaryBackticksSpec.kt
139 lines (125 loc) · 3.83 KB
/
UnnecessaryBackticksSpec.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package io.gitlab.arturbosch.detekt.rules.style
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.test.assertThat
import io.gitlab.arturbosch.detekt.test.compileAndLint
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
class UnnecessaryBackticksSpec {
val subject = UnnecessaryBackticks(Config.empty)
@Nested
inner class `Reports UnnecessaryInnerClass Rule` {
@Test
fun `class`() {
val code = """
class `Foo` {
val x: `Foo` = `Foo`()
val y = ::`Foo`
}
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(4)
}
@Test
fun function() {
val code = """
fun `foo`() = 1
val x = `foo`()
val y = ::`foo`
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(3)
}
@Test
fun property() {
val code = """
val `foo` = ""
val x = `foo`
val y = ::`foo`
val z = `foo`.length
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(4)
}
@Test
fun `import`() {
val code = """
import kotlin.`let`
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(1)
}
@Test
fun `in string template`() {
val code = """
val foo = ""
val x = "${'$'}`foo`"
val y = "${'$'}`foo` bar"
val z = "${'$'}{`foo`}bar"
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(3)
}
}
@Nested
inner class `Does not report UnnecessaryInnerClass Rule` {
@Test
fun `class with spaces`() {
val code = """
class `Foo Bar`
val x: `Foo Bar` = `Foo Bar`()
val y = ::`Foo Bar`
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(0)
}
@Test
fun `function with spaces`() {
val code = """
fun `foo bar`() = 1
val x = `foo bar`()
val y = ::`foo bar`
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(0)
}
@Test
fun `property with spaces`() {
val code = """
val `foo bar` = ""
val x = `foo bar`
val y = ::`foo bar`
val z = `foo bar`.length
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(0)
}
@Test
fun keyword() {
val code = """
val `is` = 1
val `fun` = 2
val `yield` = 3
""".trimIndent()
assertThat(subject.compileAndLint(code)).isEmpty()
}
@Test
fun underscore() {
val code = """
val `_` = 1
val `__` = 2
""".trimIndent()
assertThat(subject.compileAndLint(code)).isEmpty()
}
@Test
fun `import`() {
val code = """
package test
import test.`Foo Bar`
class `Foo Bar`
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(0)
}
@Test
fun `in string template`() {
val code = """
val foo = ""
val x = "${'$'}`foo`bar"
val `bar baz` = ""
val y = "${'$'}`bar baz`"
""".trimIndent()
assertThat(subject.compileAndLint(code)).hasSize(0)
}
}
}