2016-11-30 16:04:27 +01:00
|
|
|
package sbt.internal.util
|
|
|
|
|
|
|
|
|
|
import scala.json.ast.unsafe._
|
|
|
|
|
import sjsonnew._, support.scalajson.unsafe._
|
|
|
|
|
|
|
|
|
|
class FileInfoSpec extends UnitSpec {
|
2016-11-30 17:49:59 +01:00
|
|
|
val file = new java.io.File(".").getAbsoluteFile
|
2016-11-30 16:04:27 +01:00
|
|
|
val fileInfo: ModifiedFileInfo = FileModified(file, file.lastModified())
|
|
|
|
|
val filesInfo = FilesInfo(Set(fileInfo))
|
|
|
|
|
|
2016-11-30 17:49:59 +01:00
|
|
|
it should "round trip" in assertRoundTrip(filesInfo)(FileInfo.lastModified.formats, FileInfo.lastModified.formats)
|
2016-11-30 16:04:27 +01:00
|
|
|
|
|
|
|
|
def assertRoundTrip[A: JsonWriter: JsonReader](x: A) = {
|
|
|
|
|
val jsonString: String = toJsonString(x)
|
|
|
|
|
val jValue: JValue = Parser.parseUnsafe(jsonString)
|
|
|
|
|
val y: A = Converter.fromJson[A](jValue).get
|
|
|
|
|
assert(x === y)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def assertJsonString[A: JsonWriter](x: A, s: String) = assert(toJsonString(x) === s)
|
|
|
|
|
|
|
|
|
|
def toJsonString[A: JsonWriter](x: A): String = CompactPrinter(Converter.toJson(x).get)
|
|
|
|
|
}
|