Compare commits

...

3 Commits

Author SHA1 Message Date
Bram 4905b7341d Complete documentation 2023-12-24 11:36:34 +01:00
Bram fa642b46d6 Refactor test suite 2023-12-24 11:30:50 +01:00
Bram bf64d5911f Add Timestamp test 2023-12-24 11:17:43 +01:00
9 changed files with 125 additions and 58 deletions

View File

@ -6,6 +6,7 @@
"version": "2.0.0", "version": "2.0.0",
"exposed-modules": [ "exposed-modules": [
"Matrix", "Matrix",
"Matrix.Event",
"Matrix.Settings", "Matrix.Settings",
"Internal.Config.Default", "Internal.Config.Default",
"Internal.Config.Leaks", "Internal.Config.Leaks",
@ -18,6 +19,7 @@
"Internal.Tools.VersionControl", "Internal.Tools.VersionControl",
"Internal.Values.Context", "Internal.Values.Context",
"Internal.Values.Envelope", "Internal.Values.Envelope",
"Internal.Values.Event",
"Internal.Values.Settings", "Internal.Values.Settings",
"Internal.Values.Vault", "Internal.Values.Vault",
"Types" "Types"

View File

@ -67,6 +67,8 @@ age event =
Maybe.andThen (\(UnsignedData data) -> data.age) event.unsigned Maybe.andThen (\(UnsignedData data) -> data.age) event.unsigned
{-| Decode an Event from a JSON value.
-}
decoder : D.Decoder Event decoder : D.Decoder Event
decoder = decoder =
D.map8 Event D.map8 Event

View File

@ -6,9 +6,8 @@ module Internal.Values.Vault exposing (Vault)
-} -}
import Internal.Values.Envelope as Envelope
{-| This is the Vault type. {-| This is the Vault type.
-} -}
type alias Vault = () type alias Vault =
()

View File

@ -0,0 +1,35 @@
module Test.Matrix.Settings exposing (..)
import Expect
import Fuzz
import Matrix.Settings
import Test exposing (..)
import Test.Types as TestTypes
settings : Test
settings =
describe "Exposed Matrix.Settings"
[ describe "Set values"
[ fuzz2 TestTypes.vault
Fuzz.string
"Set device name"
(\vault name ->
vault
|> Matrix.Settings.setDeviceName name
|> Matrix.Settings.getDeviceName
|> Expect.equal name
)
, fuzz2 TestTypes.vault
Fuzz.int
"Set sync time"
(\vault sync ->
vault
|> Matrix.Settings.setSyncTime sync
|> Matrix.Settings.getSyncTime
|> Expect.equal sync
)
]
-- , describe "Read values" []
]

View File

@ -1,4 +1,4 @@
module Iddict exposing (..) module Test.Tools.Iddict exposing (..)
import Expect import Expect
import Fuzz exposing (Fuzzer) import Fuzz exposing (Fuzzer)

View File

@ -1,7 +1,10 @@
module Test.Tools.Timestamp exposing (..) module Test.Tools.Timestamp exposing (..)
import Expect
import Fuzz exposing (Fuzzer) 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 Test exposing (..)
import Time import Time
@ -9,3 +12,55 @@ import Time
fuzzer : Fuzzer Timestamp fuzzer : Fuzzer Timestamp
fuzzer = fuzzer =
Fuzz.map Time.millisToPosix Fuzz.int 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
)
]
]

17
tests/Test/Types.elm Normal file
View File

@ -0,0 +1,17 @@
module Test.Types exposing (..)
import Fuzz exposing (Fuzzer)
import Test.Values.Envelope as TestEnvelope
import Test.Values.Event as TestEvent
import Test.Values.Vault as TestVault
import Types exposing (..)
event : Fuzzer Event
event =
Fuzz.map Event (TestEnvelope.fuzzer TestEvent.fuzzer)
vault : Fuzzer Vault
vault =
Fuzz.map Vault (TestEnvelope.fuzzer TestVault.vault)

View File

@ -0,0 +1,10 @@
module Test.Values.Vault exposing (..)
import Fuzz exposing (Fuzzer)
import Internal.Values.Vault exposing (Vault)
import Test exposing (..)
vault : Fuzzer Vault
vault =
Fuzz.unit

View File

@ -1,53 +0,0 @@
module Vault exposing (..)
import Expect
import Fuzz exposing (Fuzzer)
import Internal.Config.Default as Default
import Internal.Values.Envelope as Envelope
import Matrix
import Matrix.Settings
import Test exposing (..)
import Types
fuzzer : Fuzzer Matrix.Vault
fuzzer =
Fuzz.constant <| Types.Vault <| Envelope.init ()
settings : Test
settings =
describe "Edit settings"
[ fuzz fuzzer
"Default device name"
(\vault ->
vault
|> Matrix.Settings.getDeviceName
|> Expect.equal Default.deviceName
)
, fuzz2 fuzzer
Fuzz.string
"Set device name"
(\vault name ->
vault
|> Matrix.Settings.setDeviceName name
|> Matrix.Settings.getDeviceName
|> Expect.equal name
)
, fuzz fuzzer
"Default sync time"
(\vault ->
vault
|> Matrix.Settings.getSyncTime
|> Expect.equal Default.syncTime
)
, fuzz2 fuzzer
Fuzz.int
"Set sync time"
(\vault sync ->
vault
|> Matrix.Settings.setSyncTime sync
|> Matrix.Settings.getSyncTime
|> Expect.equal sync
)
]