-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/magic-number-not-work-in-test
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...at-rules/src/test/kotlin/org/cqfn/diktat/ruleset/utils/SuppressAnnotatedExpressionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.cqfn.diktat.ruleset.utils | ||
|
||
import org.cqfn.diktat.ruleset.constants.Warnings | ||
import org.cqfn.diktat.ruleset.rules.DIKTAT_RULE_SET_ID | ||
import org.cqfn.diktat.ruleset.rules.chapter3.CollapseIfStatementsRule | ||
import org.cqfn.diktat.util.LintTestBase | ||
|
||
import com.pinterest.ktlint.core.LintError | ||
import org.junit.jupiter.api.Test | ||
|
||
class SuppressAnnotatedExpressionTest : LintTestBase(::CollapseIfStatementsRule) { | ||
private val ruleId: String = "$DIKTAT_RULE_SET_ID:collapse-if" | ||
|
||
@Test | ||
fun `should lint errors without suppress`() { | ||
val code = | ||
""" | ||
|fun foo() { | ||
| if (true) { | ||
| if (true) { | ||
| if (true) { | ||
| | ||
| } | ||
| } | ||
| } | ||
|} | ||
""".trimMargin() | ||
lintMethod(code, | ||
LintError(3, 8, ruleId, "${Warnings.COLLAPSE_IF_STATEMENTS.warnText()} avoid using redundant nested if-statements", true), | ||
LintError(4, 12, ruleId, "${Warnings.COLLAPSE_IF_STATEMENTS.warnText()} avoid using redundant nested if-statements", true) | ||
) | ||
} | ||
|
||
@Test | ||
fun `should suppress annotated expressions`() { | ||
val code = | ||
""" | ||
|fun foo() { | ||
| if (true) { | ||
| @Suppress("COLLAPSE_IF_STATEMENTS") | ||
| if (true) { | ||
| if (true) { | ||
| | ||
| } | ||
| } | ||
| } | ||
|} | ||
""".trimMargin() | ||
lintMethod(code) | ||
} | ||
} |