2023-12-24 01:16:52 +00:00
|
|
|
module Test.Tools.Timestamp exposing (..)
|
2023-12-22 22:44:46 +00:00
|
|
|
|
2023-12-24 10:17:43 +00:00
|
|
|
import Expect
|
2023-12-22 22:44:46 +00:00
|
|
|
import Fuzz exposing (Fuzzer)
|
2023-12-24 10:17:43 +00:00
|
|
|
import Internal.Tools.Timestamp as Timestamp exposing (Timestamp)
|
|
|
|
import Json.Decode as D
|
|
|
|
import Json.Encode as E
|
2023-12-22 22:44:46 +00:00
|
|
|
import Test exposing (..)
|
|
|
|
import Time
|
|
|
|
|
|
|
|
|
|
|
|
fuzzer : Fuzzer Timestamp
|
|
|
|
fuzzer =
|
|
|
|
Fuzz.map Time.millisToPosix Fuzz.int
|
2023-12-24 10:17:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
suite : Test
|
|
|
|
suite =
|
|
|
|
describe "Timestamp"
|
|
|
|
[ describe "JSON"
|
|
|
|
[ fuzz2 fuzzer
|
|
|
|
Fuzz.int
|
|
|
|
"JSON encode -> JSON decode"
|
|
|
|
(\time indent ->
|
|
|
|
time
|
|
|
|
|> Timestamp.encode
|
|
|
|
|> E.encode indent
|
|
|
|
|> D.decodeString Timestamp.decoder
|
|
|
|
|> Expect.equal (Ok time)
|
|
|
|
)
|
|
|
|
, fuzz fuzzer
|
|
|
|
"JSON decode -> millis"
|
|
|
|
(\time ->
|
|
|
|
time
|
|
|
|
|> Timestamp.encode
|
|
|
|
|> D.decodeValue D.int
|
|
|
|
|> Expect.equal (Ok <| Time.posixToMillis time)
|
|
|
|
)
|
|
|
|
, fuzz Fuzz.int
|
|
|
|
"JSON decode -> time"
|
|
|
|
(\n ->
|
|
|
|
n
|
|
|
|
|> E.int
|
|
|
|
|> D.decodeValue Timestamp.decoder
|
|
|
|
|> Expect.equal (Ok <| Time.millisToPosix n)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
, describe "Identity"
|
|
|
|
[ fuzz fuzzer
|
|
|
|
"Posix -> int -> Posix"
|
|
|
|
(\time ->
|
|
|
|
time
|
|
|
|
|> Time.posixToMillis
|
|
|
|
|> Time.millisToPosix
|
|
|
|
|> Expect.equal time
|
|
|
|
)
|
|
|
|
, fuzz Fuzz.int
|
|
|
|
"int -> Posix -> int"
|
|
|
|
(\n ->
|
|
|
|
n
|
|
|
|
|> Time.millisToPosix
|
|
|
|
|> Time.posixToMillis
|
|
|
|
|> Expect.equal n
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|