2017-04-17 09:20:41 +02:00
|
|
|
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._
|
2018-02-23 19:16:30 +01:00
|
|
|
import org.scalatest.FlatSpec
|
2017-12-15 17:23:39 +01:00
|
|
|
import sbt.io.IO
|
2016-11-30 16:04:27 +01:00
|
|
|
|
2018-02-23 19:16:30 +01:00
|
|
|
class FileInfoSpec extends FlatSpec {
|
2016-11-30 17:49:59 +01:00
|
|
|
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))
|
|
|
|
|
|
2016-12-01 15:38:40 +01:00
|
|
|
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)
|
|
|
|
|
}
|