Skip to content

Commit 47796a2

Browse files
committed
Minimize test case
1 parent bdeda6f commit 47796a2

File tree

3 files changed

+15
-36
lines changed

3 files changed

+15
-36
lines changed

modules/core/src/main/scala/org/scalasteward/core/edit/EditAlg.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ final class EditAlg[F[_]](implicit
106106
repoDir <- workspaceAlg.repoDir(data.repo)
107107
replacementsByPath = updateReplacements.groupBy(_.position.path).toList
108108
_ <- replacementsByPath.traverse { case (path, replacements) =>
109-
fileAlg.editFile(repoDir / path, Substring.Replacement.applyAll(replacements.toSet))
109+
fileAlg.editFile(repoDir / path, Substring.Replacement.applyAll(replacements))
110110
}
111111
_ <- reformatChangedFiles(data)
112112
msgTemplate = data.config.commits.messageOrDefault

modules/core/src/main/scala/org/scalasteward/core/edit/update/data/Substring.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ object Substring {
4141
final case class Replacement(position: Position, replacement: String)
4242

4343
object Replacement {
44-
def applyAll(replacements: Set[Replacement])(source: String): String = {
44+
def applyAll(replacements: List[Replacement])(source: String): String = {
4545
var start = 0
4646
val sb = new java.lang.StringBuilder(source.length)
47-
replacements.toSeq.sortBy(_.position.start).foreach { r =>
47+
replacements.distinctBy(_.position.start).sortBy(_.position.start).foreach { r =>
4848
val before = source.substring(start, r.position.start)
4949
start = r.position.start + r.position.value.length
5050
sb.append(before).append(r.replacement)

modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package org.scalasteward.core.edit
22

3-
import cats.data.NonEmptyList
43
import cats.effect.unsafe.implicits.global
54
import munit.FunSuite
65
import org.scalasteward.core.TestInstances.dummyRepoCache
76
import org.scalasteward.core.TestSyntax._
8-
import org.scalasteward.core.data.{CrossDependency, GroupId, Repo, RepoData, Update, Version}
7+
import org.scalasteward.core.data.{Repo, RepoData, Update}
98
import org.scalasteward.core.mock.MockContext.context._
109
import org.scalasteward.core.mock.MockState
1110
import org.scalasteward.core.repoconfig.RepoConfig
@@ -432,6 +431,17 @@ class RewriteTest extends FunSuite {
432431
runApplyUpdate(update, original, expected)
433432
}
434433

434+
// https://github.com/scala-steward-org/scala-steward/pull/3016
435+
test("artifact change with multiple artifactId cross names") {
436+
val update = ("com.pauldijou".g % Nel.of(
437+
("jwt-core", "jwt-core_2.12").a,
438+
("jwt-core", "jwt-core_2.13").a
439+
) % "5.0.0" %> "9.2.0").single.copy(newerGroupId = Some("com.github.jwt-scala".g))
440+
val original = Map("build.sbt" -> """ "com.pauldijou" %% "jwt-core" % "5.0.0" """)
441+
val expected = Map("build.sbt" -> """ "com.github.jwt-scala" %% "jwt-core" % "9.2.0" """)
442+
runApplyUpdate(update, original, expected)
443+
}
444+
435445
// https://github.com/scala-steward-org/scala-steward/pull/566
436446
test("prevent exception: named capturing group is missing trailing '}'") {
437447
val update =
@@ -932,37 +942,6 @@ class RewriteTest extends FunSuite {
932942
runApplyUpdate(update, original, expected)
933943
}
934944

935-
test("duplicate updates should be successful") {
936-
val dependency = "com.pauldijou".g % "jwt-play-json".a % "5.0.0"
937-
938-
val artifactId = Update.ForArtifactId(
939-
CrossDependency(dependency),
940-
newerVersions = NonEmptyList.of(Version("9.2.0")),
941-
newerGroupId = Some(GroupId("com.github.jwt-scala")),
942-
newerArtifactId = Some("jwt-play-json")
943-
)
944-
val duplicatedUpdates = Update.ForGroupId(NonEmptyList.of(artifactId, artifactId))
945-
val buildSbtContent =
946-
"""
947-
| lazy val root = (project in file("."))
948-
| .settings(
949-
| scalafmtOnCompile := true,
950-
| scalaVersion := scala213,
951-
| libraryDependencies ++= Seq(
952-
| "com.pauldijou" %% "jwt-play-json" % "5.0.0", // JWT parsing
953-
| "org.scalatestplus" %% "mockito-3-4" % "3.2.10.0" % Test
954-
| ),
955-
| crossScalaVersions := supportedScalaVersions
956-
| )
957-
|""".stripMargin
958-
val original = Map("build.sbt" -> buildSbtContent)
959-
val expectedSbtContent = buildSbtContent
960-
.replaceAll("com.pauldijou", "com.github.jwt-scala")
961-
.replaceAll("5.0.0", "9.2.0")
962-
val expected = Map("build.sbt" -> expectedSbtContent)
963-
runApplyUpdate(duplicatedUpdates, original, expected)
964-
}
965-
966945
private def runApplyUpdate(
967946
update: Update.Single,
968947
files: Map[String, String],

0 commit comments

Comments
 (0)