/
TestFiles.kt
96 lines (88 loc) · 2.64 KB
/
TestFiles.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
package io.gitlab.arturbosch.detekt.formatting
import com.pinterest.ktlint.core.ast.visit
import io.github.detekt.test.utils.compileContentForTest
import io.github.detekt.test.utils.compileForTest
import io.github.detekt.test.utils.resource
import io.gitlab.arturbosch.detekt.api.Finding
import org.intellij.lang.annotations.Language
import org.jetbrains.kotlin.com.intellij.openapi.util.text.StringUtilRt
import java.io.File
import java.nio.file.Paths
fun FormattingRule.lint(@Language("kotlin") content: String, fileName: String = "Test.kt"): List<Finding> {
val root = compileContentForTest(content, fileName)
this.visit(root)
return this.findings
}
fun loadFile(resourceName: String) = compileForTest(Paths.get(resource(resourceName)))
fun loadFileContent(resourceName: String) =
StringUtilRt.convertLineSeparators(File(resource(resourceName)).readText())
val contentAfterChainWrapping = """
fun main() {
val anchor = owner.firstChild!!
.siblings(forward = true)
.dropWhile { it is PsiComment || it is PsiWhiteSpace }
val s = foo()
?: bar
val s = foo()
?.bar
val s = 1
+ 2
val s = true &&
false
val s = b.equals(o.b) &&
g == o.g
val d = 1 +
-1
val d = 1
+ -1
when (foo){
0 -> {
}
1 -> {
}
-2 -> {
}
}
if (
-3 == a()
) {}
if (
// comment
-3 == a()
) {}
if (
/* comment */
-3 == a()
) {}
if (c)
-7
else
-8
try {
fn()
} catch(e: Exception) {
-9
}
var x =
-2 >
(2 + 2)
-3
}
""".trimIndent()
val longLines = """
/**
* These are class docs.
*/
class C {
/**
* These are function docs.
*/
fun getLoremIpsum() = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
companion object {
/**
* This is a constant for "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
*/
val LOREM_IPSUM = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
}
}
""".trimIndent()