-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,57 @@ | ||
package xerial.sbt | ||
|
||
import org.specs2.mutable.Specification | ||
import wvlet.airspec.AirSpec | ||
import xerial.sbt.pack.{DefaultVersionStringOrdering, VersionString} | ||
|
||
class VersionStringSpec extends Specification { | ||
import scala.math.Ordered.orderingToOrdered | ||
|
||
class VersionStringSpec extends AirSpec { | ||
implicit val versionStringOrdering = DefaultVersionStringOrdering | ||
|
||
"VersionString" should { | ||
"accept any string" in { | ||
test("VersionString") { | ||
test("accept any string") { | ||
VersionString("1.0") | ||
VersionString("1.0-alpha") | ||
VersionString("1") | ||
VersionString("-alpha") | ||
VersionString("1231892") | ||
VersionString("asd;.a2,.-") | ||
|
||
ok | ||
} | ||
|
||
"properly deconstruct arbitrary string" in { | ||
VersionString("1") === VersionString.fromNumbers(1 :: Nil, None) | ||
VersionString("1.2") === VersionString.fromNumbers(1 :: 2 :: Nil, None) | ||
VersionString("1.2.3") === VersionString.fromNumbers(1 :: 2 :: 3 :: Nil, None) | ||
VersionString("1.2.3.4") === VersionString.fromNumbers(1 :: 2 :: 3 :: 4 :: Nil, None) | ||
VersionString("1.2.3.4-alpha") === VersionString.fromNumbers(1 :: 2 :: 3 :: 4 :: Nil, Some("alpha")) | ||
VersionString("1.2.3.4-alpha-beta") === VersionString.fromNumbers(1 :: 2 :: 3 :: 4 :: Nil, Some("alpha-beta")) | ||
VersionString("foo") === VersionString(List.empty[String], Some("foo")) | ||
VersionString("foo.bar") === VersionString(List.empty[String], Some("foo.bar")) | ||
VersionString("foo.bar-alpha") === VersionString(List.empty[String], Some("foo.bar-alpha")) | ||
test("properly deconstruct arbitrary string") { | ||
VersionString("1") shouldBe VersionString.fromNumbers(1 :: Nil, None) | ||
VersionString("1.2") shouldBe VersionString.fromNumbers(1 :: 2 :: Nil, None) | ||
VersionString("1.2.3") shouldBe VersionString.fromNumbers(1 :: 2 :: 3 :: Nil, None) | ||
VersionString("1.2.3.4") shouldBe VersionString.fromNumbers(1 :: 2 :: 3 :: 4 :: Nil, None) | ||
VersionString("1.2.3.4-alpha") shouldBe VersionString.fromNumbers(1 :: 2 :: 3 :: 4 :: Nil, Some("alpha")) | ||
VersionString("1.2.3.4-alpha-beta") shouldBe VersionString.fromNumbers( | ||
1 :: 2 :: 3 :: 4 :: Nil, | ||
Some("alpha-beta") | ||
) | ||
VersionString("foo") shouldBe VersionString(List.empty[String], Some("foo")) | ||
VersionString("foo.bar") shouldBe VersionString(List.empty[String], Some("foo.bar")) | ||
VersionString("foo.bar-alpha") shouldBe VersionString(List.empty[String], Some("foo.bar-alpha")) | ||
} | ||
|
||
"properly sort" in { | ||
VersionString("1") must be_<(VersionString("1.2.3.4")) | ||
VersionString("2") must be_>(VersionString("1.2.3.4")) | ||
VersionString("1.2.2") must be_<(VersionString("1.2.3.4")) | ||
VersionString("1.2.4") must be_>(VersionString("1.2.3.4")) | ||
VersionString("1.2.3.4.5") must be_>(VersionString("1.2.3.4")) | ||
test("properly sort") { | ||
VersionString("1") < VersionString("1.2.3.4") shouldBe true | ||
VersionString("2") > VersionString("1.2.3.4") shouldBe true | ||
VersionString("1.2.2") < VersionString("1.2.3.4") shouldBe true | ||
VersionString("1.2.4") > VersionString("1.2.3.4") shouldBe true | ||
VersionString("1.2.3.4.5") > VersionString("1.2.3.4") shouldBe true | ||
|
||
VersionString("2.9.2") must be_<(VersionString("2.10.4")) | ||
VersionString("2.9.2") < VersionString("2.10.4") shouldBe true | ||
|
||
VersionString("1.2") must be_>(VersionString("1.2-alpha")) | ||
VersionString("1.2-beta") must be_>(VersionString("1.2-alpha")) | ||
VersionString("1.2") > VersionString("1.2-alpha") shouldBe true | ||
VersionString("1.2-beta") > VersionString("1.2-alpha") shouldBe true | ||
|
||
VersionString("apple") must be_<(VersionString("pie")) | ||
VersionString("apple") < VersionString("pie") shouldBe true | ||
} | ||
|
||
"preserve 0-padding in version strings" in { | ||
test("preserve 0-padding in version strings") { | ||
val v = VersionString("1.09") | ||
v.major mustEqual "1" | ||
v.minor mustEqual Some("09") | ||
v.major shouldBe "1" | ||
v.minor shouldBe Some("09") | ||
} | ||
} | ||
} |