2019-12-08 02:14:42 +01:00
|
|
|
/*
|
|
|
|
|
* sbt
|
2023-06-20 13:42:07 +02:00
|
|
|
* Copyright 2023, Scala center
|
|
|
|
|
* Copyright 2011 - 2022, Lightbend, Inc.
|
2019-12-08 02:14:42 +01:00
|
|
|
* Copyright 2008 - 2010, Mark Harrah
|
|
|
|
|
* Licensed under Apache License 2.0 (see LICENSE)
|
|
|
|
|
*/
|
|
|
|
|
|
2017-04-17 09:20:41 +02:00
|
|
|
package sbt.util
|
2016-11-30 16:04:27 +01:00
|
|
|
|
2025-01-02 03:16:32 +01:00
|
|
|
import sjsonnew.shaded.scalajson.ast.unsafe.*
|
|
|
|
|
import sjsonnew.*, support.scalajson.unsafe.*
|
2021-11-14 14:00:10 +01:00
|
|
|
import org.scalatest.flatspec.AnyFlatSpec
|
2017-12-15 17:23:39 +01:00
|
|
|
import sbt.io.IO
|
2016-11-30 16:04:27 +01:00
|
|
|
|
2021-11-14 14:00:10 +01:00
|
|
|
class FileInfoSpec extends AnyFlatSpec {
|
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)
|
|
|
|
|
}
|