Skip to content

Commit 3dff888

Browse files
committed
squash! [tests] Add per-case directives support in the FormatterTestFactory
1 parent daaafad commit 3dff888

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

core/src/main/kotlin/org/jetbrains/ktfmt/format/FormattingOptions.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ data class FormattingOptions(
218218
this.debuggingPrintOpsAfterFormatting = debuggingPrintOpsAfterFormatting
219219
}
220220

221-
/** @see FormattingOptions.experimentalEngine */
222221
internal fun useExperimentalEngine(useExperimentalEngine: Boolean): Builder = apply {
223222
this.useExperimentalEngine = useExperimentalEngine
224223
}

core/src/test/kotlin/org/jetbrains/ktfmt/testutil/CaseConfig.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,25 @@ class CaseConfig(val options: FormattingOptions, val checkIdempotency: Boolean)
4242

4343
fun parse(code: String, origin: Path? = null): ParsedDirectives {
4444
val header = code.lines().takeWhile { it.startsWith("//") }
45+
var directivesEnded = false
4546
val parsedDirectives =
4647
header
4748
.mapIndexedNotNull { lineNumber, line ->
48-
val (name, value) =
49-
DIRECTIVE_REGEX.matchEntire(line)?.destructured ?: return@mapIndexedNotNull null
49+
val matchResult = DIRECTIVE_REGEX.matchEntire(line)
50+
if (matchResult == null) {
51+
directivesEnded = true
52+
return@mapIndexedNotNull null
53+
}
54+
val (name, value) = matchResult.destructured
5055
val directive =
5156
DIRECTIVES[name]
52-
?: error("$origin:${lineNumber + 1}: unknown directive '$name'. ")
57+
?: when {
58+
directivesEnded ->
59+
error(
60+
"$origin:${lineNumber + 1}: directive '$name' should be listed first in the file",
61+
)
62+
else -> error("$origin:${lineNumber + 1}: unknown directive '$name'")
63+
}
5364
directive to value
5465
}
5566
.toMap()

0 commit comments

Comments
 (0)