1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE TypeApplications #-}
4 module HUnit.Credential where
6 import qualified Control.Monad.Trans.State.Strict as S
7 import qualified System.Random as Random
10 import Protocol.Credential
14 hunit = testGroup "Credential"
15 [ testGroup "randomCredential"
16 [ testCase "WeakParams" $
17 S.evalState randomCredential (Random.mkStdGen 0) @?=
18 Credential @WeakParams "RDfIgdmiCkU46pD"
19 , testCase "BeleniosParams" $
20 S.evalState randomCredential (Random.mkStdGen 0) @?=
21 Credential @BeleniosParams "RDfIgdmiCkU46pD"
23 , testGroup "readCredential"
24 [ testGroup "WeakParams" $
25 let (==>) inp (exp::Either CredentialError (Credential WeakParams)) =
26 testCase (show inp) $ readCredential inp @?= exp in
27 [ "" ==> Left CredentialError_Length
28 , "RDfIgdmiCkU46_K" ==> Left (CredentialError_BadChar '_')
29 , "RDfIgdmiCkU46f" ==> Left CredentialError_Length
30 , "RDfIgdmiCkU46pK7" ==> Left CredentialError_Length
31 , "RDfIgdmiCkU46pE" ==> Left CredentialError_Checksum
32 , "RDfIgdmiCkU46pD" ==> Right (Credential "RDfIgdmiCkU46pD")
34 , testGroup "BeleniosParams" $
35 let (==>) inp (exp::Either CredentialError (Credential BeleniosParams)) =
36 testCase (show inp) $ readCredential inp @?= exp in
37 [ "RDfIgdmiCkU46f" ==> Left CredentialError_Length
38 , "RDfIgdmiCkU46pK7" ==> Left CredentialError_Length
39 , "RDfIgdmiCkU46pE" ==> Left CredentialError_Checksum
40 , "RDfIgdmiCkU46pD" ==> Right (Credential "RDfIgdmiCkU46pD")