-
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.
Add unit tests for mis-indented expression body functions
### What's done: * Added unit tests for mis-indented expression body functions. * See #1330.
- Loading branch information
1 parent
48f0c3d
commit fac713f
Showing
8 changed files
with
619 additions
and
40 deletions.
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
166 changes: 166 additions & 0 deletions
166
...rules/src/test/kotlin/org/cqfn/diktat/ruleset/chapter3/spaces/IndentationRuleTestMixin.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,166 @@ | ||
package org.cqfn.diktat.ruleset.chapter3.spaces | ||
|
||
import org.cqfn.diktat.common.config.rules.RulesConfig | ||
import org.cqfn.diktat.ruleset.constants.Warnings.WRONG_INDENTATION | ||
import org.cqfn.diktat.ruleset.utils.indentation.IndentationConfig | ||
import org.intellij.lang.annotations.Language | ||
|
||
import java.lang.Boolean.getBoolean as getBooleanProperty | ||
|
||
internal interface IndentationRuleTestMixin { | ||
/** | ||
* See [#1330](https://github.com/saveourtool/diktat/issues/1330). | ||
* | ||
* @see expressionBodyFunctionsContinuationIndent | ||
*/ | ||
val expressionBodyFunctionsSingleIndent: Array<String> | ||
@Language("kotlin") | ||
get() = | ||
arrayOf( | ||
""" | ||
|@Test | ||
|fun `checking that suppression with ignore everything works`() { | ||
| val code = | ||
| ""${'"'} | ||
| @Suppress("diktat") | ||
| fun foo() { | ||
| val a = 1 | ||
| } | ||
| ""${'"'}.trimIndent() | ||
| lintMethod(code) | ||
|} | ||
""".trimMargin(), | ||
|
||
""" | ||
|val currentTime: Time | ||
| get() = | ||
| with(currentDateTime) { | ||
| Time(hour = hour, minute = minute, second = second) | ||
| } | ||
""".trimMargin(), | ||
|
||
""" | ||
|fun formatDateByPattern(date: String, pattern: String = "ddMMyy"): String = | ||
| DateTimeFormatter.ofPattern(pattern).format(LocalDate.parse(date)) | ||
""".trimMargin(), | ||
|
||
""" | ||
|private fun createLayoutParams(): WindowManager.LayoutParams = | ||
| WindowManager.LayoutParams().apply { /* ... */ } | ||
""".trimMargin(), | ||
|
||
""" | ||
|val offsetDelta = | ||
| if (shimmerAnimationType != ShimmerAnimationType.FADE) translateAnim.dp | ||
| else 2000.dp | ||
""".trimMargin(), | ||
|
||
""" | ||
|private fun lerp(start: Float, stop: Float, fraction: Float): Float = | ||
| (1 - fraction) * start + fraction * stop | ||
""".trimMargin() | ||
) | ||
|
||
/** | ||
* See [#1330](https://github.com/saveourtool/diktat/issues/1330). | ||
* | ||
* @see expressionBodyFunctionsSingleIndent | ||
*/ | ||
val expressionBodyFunctionsContinuationIndent: Array<String> | ||
@Language("kotlin") | ||
get() = | ||
arrayOf( | ||
""" | ||
|@Test | ||
|fun `checking that suppression with ignore everything works`() { | ||
| val code = | ||
| ""${'"'} | ||
| @Suppress("diktat") | ||
| fun foo() { | ||
| val a = 1 | ||
| } | ||
| ""${'"'}.trimIndent() | ||
| lintMethod(code) | ||
|} | ||
""".trimMargin(), | ||
|
||
""" | ||
|val currentTime: Time | ||
| get() = | ||
| with(currentDateTime) { | ||
| Time(hour = hour, minute = minute, second = second) | ||
| } | ||
""".trimMargin(), | ||
|
||
""" | ||
|fun formatDateByPattern(date: String, pattern: String = "ddMMyy"): String = | ||
| DateTimeFormatter.ofPattern(pattern).format(LocalDate.parse(date)) | ||
""".trimMargin(), | ||
|
||
""" | ||
|private fun createLayoutParams(): WindowManager.LayoutParams = | ||
| WindowManager.LayoutParams().apply { /* ... */ } | ||
""".trimMargin(), | ||
|
||
""" | ||
|val offsetDelta = | ||
| if (shimmerAnimationType != ShimmerAnimationType.FADE) translateAnim.dp | ||
| else 2000.dp | ||
""".trimMargin(), | ||
|
||
""" | ||
|private fun lerp(start: Float, stop: Float, fraction: Float): Float = | ||
| (1 - fraction) * start + fraction * stop | ||
""".trimMargin(), | ||
) | ||
|
||
/** | ||
* Creates an `IndentationConfig` from zero or more | ||
* [config entries][configEntries]. Invoke without arguments to create a | ||
* default `IndentationConfig`. | ||
* | ||
* @see [IndentationConfig] | ||
*/ | ||
@Suppress("TestFunctionName") | ||
fun IndentationConfig(vararg configEntries: Pair<String, Any>): IndentationConfig = | ||
IndentationConfig(mapOf(*configEntries).mapValues(Any::toString)) | ||
|
||
fun IndentationConfig.withCustomParameters(vararg configEntries: Pair<String, Any>): Map<String, String> = | ||
mutableMapOf( | ||
"alignedParameters" to "$alignedParameters", | ||
"indentationSize" to "$indentationSize", | ||
"newlineAtEnd" to "$newlineAtEnd", | ||
"extendedIndentOfParameters" to "$extendedIndentOfParameters", | ||
"extendedIndentAfterOperators" to "$extendedIndentAfterOperators", | ||
"extendedIndentBeforeDot" to "$extendedIndentBeforeDot", | ||
).apply { | ||
configEntries.forEach { (key, value) -> | ||
this[key] = value.toString() | ||
} | ||
} | ||
|
||
/** | ||
* Converts this map to a list containing a single [RulesConfig]. | ||
*/ | ||
fun Map<String, String>.asRulesConfigList(): List<RulesConfig> { | ||
return listOf( | ||
RulesConfig( | ||
name = WRONG_INDENTATION.name, | ||
enabled = true, | ||
configuration = this | ||
) | ||
) | ||
} | ||
|
||
val Array<String>.concatenated: String | ||
get() = | ||
joinToString(separator = "\n\n") | ||
|
||
/** | ||
* @return `true` if known-to-fail unit tests can be muted on the CI server. | ||
*/ | ||
val testsCanBeMuted: Boolean | ||
get() = | ||
getBooleanProperty("tests.can.be.muted") | ||
|
||
} |
Oops, something went wrong.