Merge pull request #117 from smarter/add-constant

Add constant CrossVersion
This commit is contained in:
Dale Wijnand 2017-06-27 15:52:59 +01:00 committed by GitHub
commit 8782c40a22
3 changed files with 26 additions and 0 deletions

View File

@ -150,6 +150,18 @@
{ "name": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" }
]
},
{
"name": "Constant",
"namespace": "sbt.librarymanagement",
"target": "Scala",
"doc": [
"Cross-versions a module using the string `value`."
],
"type": "record",
"fields": [
{ "name": "value", "type": "String", "default": "\"\"", "since": "0.0.2" }
]
},
{
"name": "Patch",
"namespace": "sbt.librarymanagement",

View File

@ -24,6 +24,9 @@ abstract class CrossVersionFunctions {
/** Cross-versions a module with the binary version (typically the binary Scala version). */
def binary: CrossVersion = Binary()
/** Cross-versions a module with a constant string (typically the binary Scala version). */
def constant(value: String): CrossVersion = Constant(value)
/**
* Cross-versions a module with the result of prepending `prefix` and appending `suffix` to the binary version
* (typically the binary Scala version). See also [[sbt.librarymanagement.Binary]].
@ -58,6 +61,7 @@ abstract class CrossVersionFunctions {
cross match {
case _: Disabled => None
case b: Binary => append(b.prefix + binaryVersion + b.suffix)
case c: Constant => append(c.value)
case _: Patch => append(patchFun(fullVersion))
case f: Full => append(f.prefix + fullVersion + f.suffix)
}

View File

@ -230,6 +230,13 @@ class CrossVersionTest extends UnitSpec {
patchVersion("2.11.8-RC1-bin-extra") shouldBe Some("artefact_2.11.8-RC1")
}
private def constantVersion(value: String) =
CrossVersion(CrossVersion.constant(value), "dummy1", "dummy2") map (fn => fn("artefact"))
"CrossVersion.constant" should "add a constant to the version" in {
constantVersion("duck") shouldBe Some("artefact_duck")
}
"Disabled" should "have structural equality" in {
Disabled() shouldBe Disabled()
}
@ -239,4 +246,7 @@ class CrossVersionTest extends UnitSpec {
"CrossVersion.binary" should "have structural equality" in {
CrossVersion.binary shouldBe CrossVersion.binary
}
"CrossVersion.constant" should "have structural equality" in {
CrossVersion.constant("duck") shouldBe CrossVersion.constant("duck")
}
}