@@ -28,6 +28,15 @@ object BuiltInRules extends CommandHelpers {
28
28
DirectivesPreprocessingUtils .usingDirectiveWithReqsHandlers
29
29
.flatMap(_.keys)
30
30
31
+ private lazy val directiveTestPrefix = " test."
32
+ extension (strictDirective : StrictDirective ) {
33
+ private def hasTestPrefix : Boolean = strictDirective.key.startsWith(directiveTestPrefix)
34
+ private def existsTestEquivalent : Boolean =
35
+ ! strictDirective.hasTestPrefix &&
36
+ usingDirectivesWithTestPrefixKeysGrouped
37
+ .exists(_.nameAliases.contains(directiveTestPrefix + strictDirective.key))
38
+ }
39
+
31
40
private val newLine : String = System .lineSeparator()
32
41
33
42
def runRules (
@@ -114,7 +123,13 @@ object BuiltInRules extends CommandHelpers {
114
123
115
124
val allDirectives = for {
116
125
directivesWithTestPrefix <- transformedTestDirectives.map(_.withTestPrefix)
117
- directive <- directivesWithTestPrefix ++ testDirectivesFromMain
126
+ directivesWithNoTestPrefixEquivalents <-
127
+ transformedTestDirectives.map {
128
+ _.noTestPrefixAvailable
129
+ .filter(_.existsTestEquivalent)
130
+ }
131
+ directive <-
132
+ directivesWithTestPrefix ++ directivesWithNoTestPrefixEquivalents ++ testDirectivesFromMain
118
133
} yield directive
119
134
120
135
createFormattedLinesAndAppend(allDirectives, projectFileContents, isTest = true )
@@ -139,7 +154,12 @@ object BuiltInRules extends CommandHelpers {
139
154
.foreach(d => removeDirectivesFrom(d.position))
140
155
directivesFromWritableTestInputs
141
156
.filterNot(ttd => isProjectFile(ttd.positions))
142
- .foreach(ttd => removeDirectivesFrom(ttd.positions, toKeep = ttd.noTestPrefixAvailable))
157
+ .foreach(ttd =>
158
+ removeDirectivesFrom(
159
+ position = ttd.positions,
160
+ toKeep = ttd.noTestPrefixAvailable.filterNot(_.existsTestEquivalent)
161
+ )
162
+ )
143
163
}
144
164
145
165
private def getProjectSources (inputs : Inputs , logger : Logger )(using
@@ -262,18 +282,15 @@ object BuiltInRules extends CommandHelpers {
262
282
extractedFromSingleElement <- extractedDirectives
263
283
directives = extractedFromSingleElement.directives
264
284
} yield {
265
- val (withTestEquivalent, noTestEquivalent) = directives.partition { directive =>
266
- usingDirectivesWithTestPrefixKeysGrouped.exists(
267
- _.nameAliases.contains(" test." + directive.key)
268
- )
269
- }
270
-
285
+ val (withInitialTestPrefix, noInitialTestPrefix) = directives.partition(_.hasTestPrefix)
286
+ val (withTestEquivalent, noTestEquivalent) =
287
+ noInitialTestPrefix.partition(_.existsTestEquivalent)
271
288
val transformedToTestEquivalents = withTestEquivalent.map {
272
289
case StrictDirective (key, values, _) => StrictDirective (" test." + key, values)
273
290
}
274
291
275
292
TransformedTestDirectives (
276
- withTestPrefix = transformedToTestEquivalents,
293
+ withTestPrefix = transformedToTestEquivalents ++ withInitialTestPrefix ,
277
294
noTestPrefixAvailable = noTestEquivalent,
278
295
positions = extractedFromSingleElement.position
279
296
)
@@ -328,7 +345,9 @@ object BuiltInRules extends CommandHelpers {
328
345
StrictDirective (key, directives.flatMap(_.values))
329
346
}
330
347
// group by key prefixes to create splits between groups
331
- .groupBy(dir => (if (isTest) dir.key.stripPrefix(" test." ) else dir.key).takeWhile(_ != '.' ))
348
+ .groupBy(dir =>
349
+ (if (isTest) dir.key.stripPrefix(directiveTestPrefix) else dir.key).takeWhile(_ != '.' )
350
+ )
332
351
.map { (_, directives) =>
333
352
directives.flatMap(_.explodeToStringsWithColLimit()).toSeq.sorted
334
353
}
0 commit comments