forked from pinterest/ktlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoVarRuleTest.kt
25 lines (22 loc) · 908 Bytes
/
NoVarRuleTest.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
package yourpkgname
import com.pinterest.ktlint.test.KtLintAssertThat.Companion.assertThat
import org.junit.jupiter.api.Test
class NoVarRuleTest {
private val wrappingRuleAssertThat = NoVarRule().assertThat()
@Test
fun `No var rule`() {
// whenever KTLINT_DEBUG env variable is set to "ast" or -DktlintDebug=ast is used
// com.pinterest.ktlint.test.(lint|format) will print AST (along with other debug info) to the stderr.
// this can be extremely helpful while writing and testing rules.
// uncomment the line below to take a quick look at it
// System.setProperty("ktlintDebug", "ast")
val code =
"""
fun fn() {
var v = "var"
}
""".trimIndent()
wrappingRuleAssertThat(code)
.hasLintViolationWithoutAutoCorrect(2, 5, "Unexpected var, use val instead")
}
}