mirror of https://github.com/sbt/sbt.git
72 lines
2.5 KiB
Scala
72 lines
2.5 KiB
Scala
package sbt.librarymanagement
|
|
|
|
import java.net.URL
|
|
import java.io.File
|
|
import sbt.serialization._
|
|
import sbt.internal.util.UnitSpec
|
|
|
|
class DMSerializationSpec extends UnitSpec {
|
|
"CrossVersion.full" should "roundtrip" in {
|
|
roundtripStr(CrossVersion.full: CrossVersion)
|
|
}
|
|
"CrossVersion.binary" should "roundtrip" in {
|
|
roundtripStr(CrossVersion.binary: CrossVersion)
|
|
}
|
|
"CrossVersion.Disabled" should "roundtrip" in {
|
|
roundtrip(CrossVersion.Disabled: CrossVersion)
|
|
}
|
|
"""Artifact("foo")""" should "roundtrip" in {
|
|
roundtrip(Artifact("foo"))
|
|
}
|
|
"""Artifact("foo", "sources")""" should "roundtrip" in {
|
|
roundtrip(Artifact("foo", "sources"))
|
|
}
|
|
"""Artifact.pom("foo")""" should "roundtrip" in {
|
|
roundtrip(Artifact.pom("foo"))
|
|
}
|
|
"""Artifact("foo", url("http://example.com/"))""" should "roundtrip" in {
|
|
roundtrip(Artifact("foo", new URL("http://example.com/")))
|
|
}
|
|
"""Artifact("foo").extra(("key", "value"))""" should "roundtrip" in {
|
|
roundtrip(Artifact("foo").extra(("key", "value")))
|
|
}
|
|
"""ModuleID("org", "name", "1.0")""" should "roundtrip" in {
|
|
roundtrip(ModuleID("org", "name", "1.0"))
|
|
}
|
|
"""ModuleReport(ModuleID("org", "name", "1.0"), Nil, Nil)""" should "roundtrip" in {
|
|
roundtripStr(ModuleReport(ModuleID("org", "name", "1.0"), Nil, Nil))
|
|
}
|
|
"Organization artifact report" should "roundtrip" in {
|
|
roundtripStr(organizationArtifactReportExample)
|
|
}
|
|
"Configuration report" should "roundtrip" in {
|
|
roundtripStr(configurationReportExample)
|
|
}
|
|
"Update report" should "roundtrip" in {
|
|
roundtripStr(updateReportExample)
|
|
}
|
|
|
|
lazy val updateReportExample =
|
|
new UpdateReport(new File("./foo"), Vector(configurationReportExample),
|
|
new UpdateStats(0, 0, 0, false), Map(new File("./foo") -> 0))
|
|
lazy val configurationReportExample =
|
|
new ConfigurationReport("compile", Vector(moduleReportExample),
|
|
Vector(organizationArtifactReportExample), Nil)
|
|
lazy val organizationArtifactReportExample =
|
|
new OrganizationArtifactReport("org", "name", Vector(moduleReportExample))
|
|
lazy val moduleReportExample =
|
|
ModuleReport(ModuleID("org", "name", "1.0"), Nil, Nil)
|
|
|
|
def roundtrip[A: Pickler: Unpickler](a: A): Unit =
|
|
roundtripBuilder(a) { _ shouldBe _ }
|
|
def roundtripStr[A: Pickler: Unpickler](a: A): Unit =
|
|
roundtripBuilder(a) { _.toString shouldBe _.toString }
|
|
def roundtripBuilder[A: Pickler: Unpickler](a: A)(f: (A, A) => Unit): Unit =
|
|
{
|
|
val json = toJsonString(a)
|
|
println(json)
|
|
val obj = fromJsonString[A](json).get
|
|
f(a, obj)
|
|
}
|
|
}
|