Repository: scala-steward-org/scala-steward (scala)

Issue:
Order[Version] is not transitive
One build of https://github.com/scala-steward-org/scala-steward/pull/1614 failed with:
```
failing seed for order.transitivity is jrEI318o6GIPatr-KDWf_A1_sf9ndnP7IRRq2mNh1ZD=
[info] - Order[Version].order.transitivity *** FAILED ***
[info]   GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
[info]    (VersionTest.scala:18)
[info]     Falsified after 1 successful property evaluations.
[info]     Location: (VersionTest.scala:18)
[info]     Occurred when passed generated values (
[info]       arg0 = Version(),
[info]       arg1 = Version(0),
[info]       arg2 = Version(D+)
[info]     )
[info]     Label of failing property:
[info]       Expected: true
[info]   Received: false
```
I assume the build will succeed once it is restarted.

Pull request:
This fixes the broken transitivity of `Order[Version]` noticed in #1615 by removing cases in `Order[Component]`. It is concerning that that there are no test cases that were sensitive to the removed code. We should double-check if it is OK to remove that code or if we can write tests that are sensitive to that code.

Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/data/Version.scala b/modules/core/src/main/scala/org/scalasteward/core/data/Version.scala
index 311f09c08b..019bde681e 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/data/Version.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/data/Version.scala
@@ -121,7 +121,6 @@ object Version {
   object Component {
     final case class Numeric(value: String, startIndex: Int) extends Component {
       def toBigInt: BigInt = BigInt(value)
-      def isZero: Boolean = toBigInt === BigInt(0)
     }
     final case class Alpha(value: String, startIndex: Int) extends Component {
       def isPreReleaseIdent: Boolean = order < 0
@@ -200,8 +199,6 @@ object Version {
     implicit val componentOrder: Order[Component] =
       Order.from[Component] {
         case (n1: Numeric, n2: Numeric) => n1.toBigInt.compare(n2.toBigInt)
-        case (n: Numeric, a: Alpha)     => if (a.isPreReleaseIdent || !n.isZero) 1 else -1
-        case (a: Alpha, n: Numeric)     => if (a.isPreReleaseIdent || !n.isZero) -1 else 1
         case (_: Numeric, _)            => 1
         case (_, _: Numeric)            => -1
 


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/data/VersionTest.scala b/modules/core/src/test/scala/org/scalasteward/core/data/VersionTest.scala
index a67424dfa2..90b5151e04 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/data/VersionTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/data/VersionTest.scala
@@ -17,10 +17,16 @@ class VersionTest
     with ScalaCheckPropertyChecks {
   checkAll("Order[Version]", OrderTests[Version].order)
 
+  test("issue 1615: broken transitivity") {
+    val res = OrderTests[Version].laws.transitivity(Version(""), Version("0"), Version("X"))
+    res.lhs shouldBe res.rhs
+  }
+
   test("pairwise 1") {
     val versions = List(
       "0.1",
       "0-20170604",
+      "1.0e",
       "1.0.0-SNAP8",
       "1.0.0-M2",
       "1.0.0",
@@ -91,6 +97,7 @@ class VersionTest
 
   test("similar ordering as Coursier") {
     List(
+      ("1.0e", "1.0.0-SNAP8"),
       ("1.0.1e", "1.0.1"),
       ("42.2.9.jre7", "42.2.9"),
       ("42.2.9.jre7", "42.2.9.jre8"),