From bf64d5911f6026e3479f963f050b1ef203eeb231 Mon Sep 17 00:00:00 2001 From: Bram Date: Sun, 24 Dec 2023 11:17:43 +0100 Subject: [PATCH] Add Timestamp test --- src/Internal/Values/Vault.elm | 5 ++- tests/Test/Tools/Timestamp.elm | 57 +++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/Internal/Values/Vault.elm b/src/Internal/Values/Vault.elm index 72df622..af4383c 100644 --- a/src/Internal/Values/Vault.elm +++ b/src/Internal/Values/Vault.elm @@ -6,9 +6,8 @@ module Internal.Values.Vault exposing (Vault) -} -import Internal.Values.Envelope as Envelope - {-| This is the Vault type. -} -type alias Vault = () +type alias Vault = + () diff --git a/tests/Test/Tools/Timestamp.elm b/tests/Test/Tools/Timestamp.elm index e10a64e..d98cafb 100644 --- a/tests/Test/Tools/Timestamp.elm +++ b/tests/Test/Tools/Timestamp.elm @@ -1,7 +1,10 @@ module Test.Tools.Timestamp exposing (..) +import Expect import Fuzz exposing (Fuzzer) -import Internal.Tools.Timestamp exposing (Timestamp) +import Internal.Tools.Timestamp as Timestamp exposing (Timestamp) +import Json.Decode as D +import Json.Encode as E import Test exposing (..) import Time @@ -9,3 +12,55 @@ import Time fuzzer : Fuzzer Timestamp fuzzer = Fuzz.map Time.millisToPosix Fuzz.int + + +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 + ) + ] + ]