Compare commits

..

No commits in common. "978d6c6315c2a23084aab9e63d55cebc18472e85" and "ca0a7b41df3e26685f357a1d107454021d71a2a8" have entirely different histories.

3 changed files with 93 additions and 270 deletions

View File

@ -1,143 +0,0 @@
module Context exposing (..)
import Expect
import Fuzz exposing (Fuzzer)
import Internal.Config.Leaks as Leaks
import Internal.Values.Context as Context exposing (Context)
import Json.Decode as D
import Json.Encode as E
import Test exposing (..)
fuzzer : Fuzzer Context
fuzzer =
let
maybeString : Fuzzer (Maybe String)
maybeString =
Fuzz.maybe Fuzz.string
in
Fuzz.map7 Context
maybeString
maybeString
maybeString
maybeString
maybeString
maybeString
(Fuzz.maybe <| Fuzz.list Fuzz.string)
{-| If a leak is spotted, make sure to change the leaking value and then test
with the same seed to ensure it is not a (tiny) coincidence and a leak is in
fact coming through.
-}
leaks : Test
leaks =
describe "No leaks allowed"
[ fuzz2 fuzzer
Fuzz.string
"Access token"
(\context value ->
context
|> Context.apiFormat
|> Context.setAccessToken value
|> Context.getAccessToken
|> Expect.notEqual Leaks.accessToken
)
, fuzz2 fuzzer
Fuzz.string
"Base URL"
(\context value ->
context
|> Context.apiFormat
|> Context.setBaseUrl value
|> Context.getBaseUrl
|> Expect.notEqual Leaks.baseUrl
)
, fuzz2 fuzzer
Fuzz.string
"Transaction"
(\context value ->
context
|> Context.apiFormat
|> Context.setTransaction value
|> Context.getTransaction
|> Expect.notEqual Leaks.transaction
)
, fuzz2 fuzzer
(Fuzz.list Fuzz.string)
"Versions"
(\context value ->
context
|> Context.apiFormat
|> Context.setVersions value
|> Context.getVersions
|> Expect.notEqual Leaks.versions
)
]
apiContext : Test
apiContext =
describe "Verify writing info"
[ fuzz2 fuzzer
Fuzz.string
"Access token"
(\context value ->
context
|> Context.apiFormat
|> Context.setAccessToken value
|> Context.getAccessToken
|> Expect.equal value
)
, fuzz2 fuzzer
Fuzz.string
"Base URL"
(\context value ->
context
|> Context.apiFormat
|> Context.setBaseUrl value
|> Context.getBaseUrl
|> Expect.equal value
)
, fuzz2 fuzzer
Fuzz.string
"Transaction"
(\context value ->
context
|> Context.apiFormat
|> Context.setTransaction value
|> Context.getTransaction
|> Expect.equal value
)
, fuzz2 fuzzer
(Fuzz.list Fuzz.string)
"Versions"
(\context value ->
context
|> Context.apiFormat
|> Context.setVersions value
|> Context.getVersions
|> Expect.equal value
)
]
json : Test
json =
describe "JSON encode + JSON decode"
[ test "Empty is {}"
(Context.init
|> Context.encode
|> E.encode 0
|> Expect.equal "{}"
|> always
)
, fuzz fuzzer
"JSON recode"
(\context ->
context
|> Context.encode
|> D.decodeValue Context.decoder
|> Expect.equal (Ok context)
)
]

View File

@ -4,8 +4,9 @@ import Expect
import Fuzz exposing (Fuzzer) import Fuzz exposing (Fuzzer)
import Internal.Tools.Iddict as Iddict exposing (Iddict) import Internal.Tools.Iddict as Iddict exposing (Iddict)
import Json.Decode as D import Json.Decode as D
import Json.Encode as E
import Test exposing (..) import Test exposing (..)
import Json.Encode as E
import Internal.Tools.Iddict as Iddict
fuzzer : Fuzzer a -> Fuzzer (Iddict a) fuzzer : Fuzzer a -> Fuzzer (Iddict a)
@ -93,7 +94,6 @@ empty =
) )
] ]
singleton : Test singleton : Test
singleton = singleton =
let let
@ -106,100 +106,86 @@ singleton =
) )
Fuzz.int Fuzz.int
in in
describe "singleton" describe "singleton"
[ fuzz singleFuzzer [ fuzz singleFuzzer "not isEmpty"
"not isEmpty" (\single ->
(\single -> single
single |> Iddict.isEmpty
|> Iddict.isEmpty |> Expect.equal False
|> Expect.equal False )
) , fuzz Fuzz.int "singleton == insert empty"
, fuzz Fuzz.int (\i ->
"singleton == insert empty" Iddict.empty
(\i -> |> Iddict.insert i
Iddict.empty |> Expect.equal (Iddict.singleton i)
|> Iddict.insert i )
|> Expect.equal (Iddict.singleton i) , fuzz Fuzz.int "First item is key 0"
) (\i ->
, fuzz Fuzz.int Iddict.singleton i
"First item is key 0" |> Tuple.first
(\i -> |> Expect.equal 0
Iddict.singleton i )
|> Tuple.first , fuzz singleFuzzer "Key 0 is member"
|> Expect.equal 0 (\single ->
) single
, fuzz singleFuzzer |> Iddict.member 0
"Key 0 is member" |> Expect.equal True
(\single -> )
single , fuzz Fuzz.int "Key 0 get returns Just value"
|> Iddict.member 0 (\i ->
|> Expect.equal True Iddict.singleton i
) |> Tuple.second
, fuzz Fuzz.int |> Iddict.get 0
"Key 0 get returns Just value" |> Expect.equal (Just i)
(\i -> )
Iddict.singleton i , fuzz singleFuzzer "Size == 1"
|> Tuple.second (\single ->
|> Iddict.get 0 single
|> Expect.equal (Just i) |> Iddict.size
) |> Expect.equal 1
, fuzz singleFuzzer )
"Size == 1" , fuzz Fuzz.int "Only key 0"
(\single -> (\i ->
single Iddict.singleton i
|> Iddict.size |> Tuple.second
|> Expect.equal 1 |> Iddict.keys
) |> Expect.equal [ 0 ]
, fuzz Fuzz.int )
"Only key 0" , fuzz Fuzz.int "Only value value"
(\i -> (\i ->
Iddict.singleton i Iddict.singleton i
|> Tuple.second |> Tuple.second
|> Iddict.keys |> Iddict.values
|> Expect.equal [ 0 ] |> Expect.equal [ i ]
) )
, fuzz Fuzz.int , fuzz singleFuzzer "JSON encode -> decode -> singleton"
"Only value value" (\single ->
(\i -> single
Iddict.singleton i |> Iddict.encode E.int
|> Tuple.second |> D.decodeValue (Iddict.decoder D.int)
|> Iddict.values |> Expect.equal (Ok single)
|> Expect.equal [ i ] )
) , fuzz Fuzz.int "JSON encode"
, fuzz singleFuzzer (\i ->
"JSON encode -> decode -> singleton" Iddict.singleton i
(\single -> |> Tuple.second
single |> Iddict.encode E.int
|> Iddict.encode E.int |> E.encode 0
|> D.decodeValue (Iddict.decoder D.int) |> Expect.equal ("{\"cursor\":1,\"dict\":{\"0\":" ++ (String.fromInt i) ++ "}}")
|> Expect.equal (Ok single) )
) , fuzz Fuzz.int "JSON decode"
, fuzz Fuzz.int (\i ->
"JSON encode" ("{\"cursor\":1,\"dict\":{\"0\":" ++ (String.fromInt i) ++ "}}")
(\i -> |> D.decodeString (Iddict.decoder D.int)
Iddict.singleton i |> Tuple.pair 0
|> Tuple.second |> Expect.equal (Iddict.singleton i |> Tuple.mapSecond Ok)
|> Iddict.encode E.int )
|> E.encode 0 ]
|> Expect.equal ("{\"cursor\":1,\"dict\":{\"0\":" ++ String.fromInt i ++ "}}")
)
, fuzz Fuzz.int
"JSON decode"
(\i ->
("{\"cursor\":1,\"dict\":{\"0\":" ++ String.fromInt i ++ "}}")
|> D.decodeString (Iddict.decoder D.int)
|> Tuple.pair 0
|> Expect.equal (Iddict.singleton i |> Tuple.mapSecond Ok)
)
]
insert : Test insert : Test
insert = insert =
describe "insert" describe "insert"
[ fuzz2 (fuzzer Fuzz.int) [ fuzz2 (fuzzer Fuzz.int) Fuzz.int "Add something"
Fuzz.int
"Add something"
(\d i -> (\d i ->
case Iddict.insert i d of case Iddict.insert i d of
( key, dict ) -> ( key, dict ) ->
@ -207,18 +193,14 @@ insert =
|> Iddict.get key |> Iddict.get key
|> Expect.equal (Just i) |> Expect.equal (Just i)
) )
, fuzz2 (fuzzer Fuzz.int) , fuzz2 (fuzzer Fuzz.int) Fuzz.int "Never isEmpty"
Fuzz.int
"Never isEmpty"
(\d i -> (\d i ->
Iddict.insert i d Iddict.insert i d
|> Tuple.second |> Tuple.second
|> Iddict.isEmpty |> Iddict.isEmpty
|> Expect.equal False |> Expect.equal False
) )
, fuzz2 (fuzzer Fuzz.int) , fuzz2 (fuzzer Fuzz.int) Fuzz.int "New key"
Fuzz.int
"New key"
(\d i -> (\d i ->
case Iddict.insert i d of case Iddict.insert i d of
( key, dict ) -> ( key, dict ) ->
@ -229,9 +211,7 @@ insert =
Expect.notEqual key newKey Expect.notEqual key newKey
) )
) )
, fuzz2 (fuzzer Fuzz.int) , fuzz2 (fuzzer Fuzz.int) Fuzz.int "New dict"
Fuzz.int
"New dict"
(\d i -> (\d i ->
case Iddict.insert i d of case Iddict.insert i d of
( key, dict ) -> ( key, dict ) ->
@ -242,9 +222,7 @@ insert =
Expect.notEqual dict newDict Expect.notEqual dict newDict
) )
) )
, fuzz2 (fuzzer Fuzz.int) , fuzz2 (fuzzer Fuzz.int) Fuzz.int "Inserted value is member"
Fuzz.int
"Inserted value is member"
(\d i -> (\d i ->
case Iddict.insert i d of case Iddict.insert i d of
( key, dict ) -> ( key, dict ) ->
@ -252,9 +230,7 @@ insert =
|> Iddict.member key |> Iddict.member key
|> Expect.equal True |> Expect.equal True
) )
, fuzz2 (fuzzer Fuzz.int) , fuzz2 (fuzzer Fuzz.int) Fuzz.int "Get inserted value"
Fuzz.int
"Get inserted value"
(\d i -> (\d i ->
case Iddict.insert i d of case Iddict.insert i d of
( key, dict ) -> ( key, dict ) ->
@ -262,14 +238,12 @@ insert =
|> Iddict.get key |> Iddict.get key
|> Expect.equal (Just i) |> Expect.equal (Just i)
) )
, fuzz2 (fuzzer Fuzz.int) , fuzz2 (fuzzer Fuzz.int) Fuzz.int "size = size + 1"
Fuzz.int
"size = size + 1"
(\d i -> (\d i ->
case Iddict.insert i d of case Iddict.insert i d of
( _, dict ) -> ( _, dict ) ->
Expect.equal Expect.equal
(Iddict.size dict) ( Iddict.size dict )
(Iddict.size d + 1) ( Iddict.size d + 1 )
) )
] ]

View File

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