-
Notifications
You must be signed in to change notification settings - Fork 501
/
NoTrailingSpacesRuleTest.kt
68 lines (58 loc) · 1.78 KB
/
NoTrailingSpacesRuleTest.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
package com.pinterest.ktlint.ruleset.standard
import com.pinterest.ktlint.core.LintError
import com.pinterest.ktlint.test.format
import com.pinterest.ktlint.test.lint
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
class NoTrailingSpacesRuleTest {
@Test
fun testLint() {
assertThat(NoTrailingSpacesRule().lint("fun main() {\n val a = 1\n\n \n} "))
.isEqualTo(
listOf(
LintError(4, 1, "no-trailing-spaces", "Trailing space(s)"),
LintError(5, 2, "no-trailing-spaces", "Trailing space(s)")
)
)
}
@Test
fun testFormat() {
assertThat(NoTrailingSpacesRule().format("fun main() {\n val a = 1 \n \n \n} "))
.isEqualTo("fun main() {\n val a = 1\n\n\n}")
}
@Test
fun `lint trailing spaces inside block comments`() {
val code =
"""
/*${" "}
* Some comment${" "}
*/
""".trimIndent()
val actual = NoTrailingSpacesRule().lint(code)
assertThat(actual)
.isEqualTo(
listOf(
LintError(1, 1, "no-trailing-spaces", "Trailing space(s)"),
LintError(2, 1, "no-trailing-spaces", "Trailing space(s)")
)
)
}
@Test
fun `format trailing spaces inside block comments`() {
val code =
"""
/*${" "}
* Some comment${" "}
*/
""".trimIndent()
val actual = NoTrailingSpacesRule().format(code)
assertThat(actual)
.isEqualTo(
"""
/*
* Some comment
*/
""".trimIndent()
)
}
}