forked from pinterest/ktlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoVarRuleTest.kt
27 lines (21 loc) · 995 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
26
27
package yourpkgname
import com.github.shyiko.ktlint.core.LintError
import com.github.shyiko.ktlint.test.lint
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
class NoVarRuleTest : Spek({
describe("no-var rule") {
// whenever KTLINT_DEBUG env variable is set to "ast" or -DktlintDebug=ast is used
// com.github.shyiko.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 rule = NoVarRule()
it("should prohibit usage of var") {
assertThat(rule.lint("""fun fn() { var v = "var" }"""))
.isEqualTo(listOf(LintError(1, 12, "no-var", "Unexpected var, use val instead")))
}
}
})