diff --git a/src/main/scala/com/timushev/sbt/updates/versions/Version.scala b/src/main/scala/com/timushev/sbt/updates/versions/Version.scala index 5796e482..95f62fac 100644 --- a/src/main/scala/com/timushev/sbt/updates/versions/Version.scala +++ b/src/main/scala/com/timushev/sbt/updates/versions/Version.scala @@ -84,17 +84,20 @@ object Version { } object VersionParser extends RegexParsers { - private val token = """[^-+.]+""".r - private val number = """\d{1,18}(?=[-+.]|$)""".r ^^ (_.toLong) - private val plusAsPatchValue = """\+""".r ^^ (_ => Long.MaxValue) + private val token = """[^-+.]+""".r + private val number = """\d{1,18}(?=[-+.]|$)""".r ^^ (_.toLong) + private val plusAsNumber = """\+""".r ^^ (_ => Long.MaxValue) + + private val numericPart: Parser[List[Long]] = + number ~ ("." ~> (plusAsNumber ^^ (List(_)) | numericPart)).? ^^ { + case h ~ Some(t) => h :: t + case h ~ None => List(h) + } - private val numericPart: Parser[List[Long]] = number ~ ("." ~> number) ~ ("." ~> (number | plusAsPatchValue)).* ^^ { - case h ~ m ~ t => h :: m :: t - } private val part: Parser[List[String]] = token ~ (("." | "-") ~> token).* ^^ { case h ~ t => h :: t } private val version: Parser[(List[Long], List[String], List[String])] = - numericPart ~ (("." | "-") ~> part).? ~ ("+" ~> part).? ^^ { case a ~ b ~ c => + "v".? ~> numericPart ~ (("." | "-") ~> part).? ~ ("+" ~> part).? ^^ { case a ~ b ~ c => (a, b.getOrElse(Nil), c.getOrElse(Nil)) } diff --git a/src/test/scala/com/timushev/sbt/updates/versions/VersionSpec.scala b/src/test/scala/com/timushev/sbt/updates/versions/VersionSpec.scala index bfc35dba..5e84cb58 100644 --- a/src/test/scala/com/timushev/sbt/updates/versions/VersionSpec.scala +++ b/src/test/scala/com/timushev/sbt/updates/versions/VersionSpec.scala @@ -31,11 +31,10 @@ class VersionSpec extends AnyFreeSpec with Matchers { b should equal("build" :: "10" :: Nil) case _ => fail("not a build version") } - Version("2.0.2+9-4e5b95f4-SNAPSHOT") match { // Sbt-Dynver style snapshot version case SnapshotVersion(r, p, b) => r should equal(2 :: 0 :: 2 :: Nil) - case _ => fail("not a snaphshot version") + case _ => fail("not a snapshot version") } } "should be ordered according to the semantic versioning spec" in { @@ -88,21 +87,6 @@ class VersionSpec extends AnyFreeSpec with Matchers { case other => fail(other.toString) } } - - "should reject versions like 1.+.+, 1.+.0, +.0.0" in { - VersionParser.parse("1.+.+") match { - case VersionParser.Failure(_, _) => - case other => fail(other.toString) - } - VersionParser.parse("1.+.0") match { - case VersionParser.Failure(_, _) => - case other => fail(other.toString) - } - VersionParser.parse("+.0.0") match { - case VersionParser.Failure(_, _) => - case other => fail(other.toString) - } - } "should parse versions like 1.0.3m" in { VersionParser.parse("1.0.3m") match { case VersionParser.Success((1 :: 0 :: Nil, "3m" :: Nil, Nil), _) => @@ -119,6 +103,12 @@ class VersionSpec extends AnyFreeSpec with Matchers { case other => fail(other.toString) } } + "should parse versions like v3-rev411-1.25.0" in { + VersionParser.parse("v3-rev411-1.25.0") match { + case VersionParser.Success((3 :: Nil, "rev411" :: "1" :: "25" :: "0" :: Nil, Nil), _) => + case other => fail(other.toString) + } + } } }