sbt/util-cache/src/test/scala/FileInfoSpec.scala

26 lines
847 B
Scala
Raw Normal View History

package sbt.util
2016-11-30 16:04:27 +01:00
2017-07-14 21:56:06 +02:00
import sjsonnew.shaded.scalajson.ast.unsafe._
2016-11-30 16:04:27 +01:00
import sjsonnew._, support.scalajson.unsafe._
import org.scalatest.FlatSpec
import sbt.io.IO
2016-11-30 16:04:27 +01:00
class FileInfoSpec extends FlatSpec {
val file = new java.io.File(".").getAbsoluteFile
2017-12-22 00:03:11 +01:00
val fileInfo: ModifiedFileInfo = FileModified(file, IO.getModifiedTimeOrZero(file))
2016-11-30 16:04:27 +01:00
val filesInfo = FilesInfo(Set(fileInfo))
it should "round trip" in assertRoundTrip(filesInfo)
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)
}