Skip to content

Commit 4fcbbbf

Browse files
chore(deps): update weapon-regex to 2.0.0 (#2026)
1 parent 842728e commit 4fcbbbf

15 files changed

Lines changed: 37 additions & 66 deletions

File tree

.scalafix.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
rules = [
2+
OrganizeImports
3+
]
14
OrganizeImports {
25
coalesceToWildcardImportThreshold = 5
36
groupedImports = Merge

modules/api/src/main/scala/stryker4s/log/Logger.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package stryker4s.log
22

3-
import stryker4s.log.Level.*
43
import fansi.Str
4+
import stryker4s.log.Level.*
55

66
trait Logger {
77

modules/commandRunner/src/main/scala/stryker4s/log/Slf4jLogger.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package stryker4s.log
22

3-
import org.slf4j.simple.SimpleLoggerFactory
43
import org.slf4j.Logger as Slf4jInternalLogger
4+
import org.slf4j.simple.SimpleLoggerFactory
55

66
class Slf4jLogger() extends Logger {
77
private val slf4jLogger: Slf4jInternalLogger = new SimpleLoggerFactory().getLogger("Stryker4s")

modules/core/src/main/scala/stryker4s/extension/TreeExtensions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import cats.Eval
44
import cats.data.{Chain, OptionT}
55
import cats.syntax.all.*
66
import mutationtesting.Location
7-
import weaponregex.model.Location as RegexLocation
87

98
import scala.annotation.tailrec
109
import scala.meta.*
@@ -160,11 +159,12 @@ object TreeExtensions {
160159
end = mutationtesting.Position(line = pos.endLine + 1, column = pos.endColumn + 1)
161160
)
162161
}
163-
implicit final class RegexLocationExtension(val pos: RegexLocation) extends AnyVal {
164162

165-
/** Map a `weaponregex.model.Location` to a `mutationtesting.Location`
163+
implicit final class LocationExtension(val pos: Location) extends AnyVal {
164+
165+
/** Adds an offset to a `mutationtesting.Location`
166166
*/
167-
def toLocation(offset: Location, stringValue: Lit.String): Location = {
167+
def withOffset(offset: Location, stringValue: Lit.String): Location = {
168168
val stringOffset = if (stringValue.text.startsWith("\"\"\"")) 3 else 1
169169
Location(
170170
start = mutationtesting

modules/core/src/main/scala/stryker4s/files/fileIO.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package stryker4s.files
22

33
import cats.effect.IO
4-
import fs2.io.file.{Files, Path}
54
import fs2.*
5+
import fs2.io.file.{Files, Path}
66

77
import java.io.IOException
88

modules/core/src/main/scala/stryker4s/model/Mutant.scala

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package stryker4s.model
22

3-
import cats.Show
43
import cats.syntax.all.*
54
import mutationtesting.{Location, MutantResult, MutantStatus}
65
import stryker4s.extension.TreeExtensions.PositionExtension
@@ -49,13 +48,7 @@ final case class MutantMetadata(
4948
mutatorName: String,
5049
location: Location,
5150
description: Option[String]
52-
) {
53-
def showLocation: String = {
54-
import MutantMetadata.locationShow
55-
56-
location.show
57-
}
58-
}
51+
)
5952

6053
object MutantMetadata {
6154
def apply(
@@ -67,7 +60,4 @@ object MutantMetadata {
6760
): MutantMetadata =
6861
MutantMetadata(original, replacement, mutatorName, position.toLocation, description)
6962

70-
implicit def locationShow: Show[Location] = Show.show(location =>
71-
s"${location.start.line}:${location.start.column} to ${location.end.line}:${location.end.column}"
72-
)
7363
}

modules/core/src/main/scala/stryker4s/mutants/findmutants/MutantMatcher.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package stryker4s.mutants.findmutants
22

33
import cats.data.NonEmptyVector
44
import cats.syntax.all.*
5+
import mutationtesting.cats.*
56
import stryker4s.config.{Config, ExcludedMutation}
67
import stryker4s.extension.PartialFunctionOps.*
78
import stryker4s.extension.TreeExtensions.{IsEqualExtension, PositionExtension, TransformOnceExtension}
@@ -11,6 +12,7 @@ import stryker4s.mutation.*
1112

1213
import scala.annotation.tailrec
1314
import scala.meta.*
15+
import scala.meta.prettyprinters.XtensionReprint
1416

1517
import MutantMatcher.MutationMatcher
1618

@@ -164,15 +166,15 @@ class MutantMatcherImpl()(implicit config: Config) extends MutantMatcher {
164166
}
165167
.getOrElse(
166168
throw new RuntimeException(
167-
s"Could not transform '$original' in ${placeableTree.tree} (${metadata.showLocation})"
169+
show"Could not transform '${original.text}' in ${placeableTree.tree.text} (${metadata.location})"
168170
)
169171
)
170172

171173
mutatedTopStatement match {
172174
case t: Term => MutatedCode(t, metadata)
173175
case t =>
174176
throw new RuntimeException(
175-
s"Could not transform '$original' in ${placeableTree.tree} (${metadata.showLocation}). Expected a Term, but was a ${t.getClass().getSimpleName}"
177+
show"Could not transform '${original.text}' in ${placeableTree.tree.text} (${metadata.location}). Expected a Term, but was a ${t.getClass().getSimpleName}"
176178
)
177179
}
178180

modules/core/src/main/scala/stryker4s/mutation/RegexMutator.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package stryker4s.mutation
22

3-
import cats.data.NonEmptyVector
3+
import cats.data.{NonEmptySet, NonEmptyVector}
44
import cats.syntax.all.*
55
import mutationtesting.Location
6-
import stryker4s.extension.TreeExtensions.{PositionExtension, RegexLocationExtension}
6+
import stryker4s.extension.TreeExtensions.{LocationExtension, PositionExtension}
77
import stryker4s.model.{MutantMetadata, MutatedCode, NoRegexMutationsFound, RegexParseError}
88
import stryker4s.mutants.tree.IgnoredMutation
99

@@ -83,7 +83,7 @@ case object PatternConstructor {
8383
object RegexMutations {
8484
def apply(lit: Lit.String): Either[IgnoredMutation, NonEmptyVector[RegularExpression]] = {
8585
weaponregex.WeaponRegeX
86-
.mutate(lit.value, mutationLevels = Seq(1))
86+
.mutate(lit.value, mutationLevels = NonEmptySet.one(1).some)
8787
.leftMap(e => (ignoredMutationMetadata(lit), RegexParseError(lit.value, e)))
8888
.map(_.toVector)
8989
.flatMap(
@@ -93,7 +93,7 @@ object RegexMutations {
9393
_.map(r =>
9494
RegularExpression(
9595
pattern = r.pattern,
96-
location = r.location.toLocation(offset = lit.pos.toLocation, lit),
96+
location = r.location.withOffset(offset = lit.pos.toLocation, lit),
9797
replacement = r.replacement,
9898
description = r.description
9999
)

modules/core/src/test/scala/stryker4s/extension/TreeExtensionsTest.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import cats.syntax.option.*
44
import mutationtesting.{Location, Position}
55
import stryker4s.extension.TreeExtensions.*
66
import stryker4s.testkit.Stryker4sSuite
7-
import weaponregex.model as wrx
87

98
import scala.collection.mutable.ListBuffer
109
import scala.meta.*
@@ -228,17 +227,17 @@ class TreeExtensionsTest extends Stryker4sSuite {
228227
}
229228
}
230229

231-
describe("toLocation") {
232-
val wrxLocation = wrx.Location(wrx.Position(1, 2), wrx.Position(3, 4))
230+
describe("withOffset") {
231+
val wrxLocation = Location(Position(1, 2), Position(3, 4))
233232
val offset = Location(Position(5, 6), Position(7, 8))
234-
test("should map a weaponregex.Location to a mutationtesting.Location") {
235-
val result = wrxLocation.toLocation(offset, Lit.String("foo")) // single double-quote string "foo"
233+
test("uses correct offset for regular string") {
234+
val result = wrxLocation.withOffset(offset, Lit.String("foo")) // single double-quote string "foo"
236235

237236
assertEquals(result, mutationtesting.Location(mutationtesting.Position(6, 9), mutationtesting.Position(8, 11)))
238237
}
239238

240239
test("uses correct offset for triple double-quote strings") {
241-
val result = wrxLocation.toLocation(
240+
val result = wrxLocation.withOffset(
242241
offset,
243242
"\"\"\"foo\"\"\"".parse[Term].get.asInstanceOf[Lit.String]
244243
) // triple double-quote string """foo"""

modules/core/src/test/scala/stryker4s/model/MutantMetadataTest.scala

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)