{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeApplications #-} module HUnit.Credential where import qualified Control.Monad.Trans.State.Strict as S import qualified System.Random as Random import Protocol.Arith import Protocol.Credential import HUnit.Utils hunit :: TestTree hunit = testGroup "Credential" [ testGroup "randomCredential" [ testCase "WeakParams" $ S.evalState randomCredential (Random.mkStdGen 0) @?= Credential @WeakParams "RDfIgdmiCkU46pK" , testCase "BeleniosParams" $ S.evalState randomCredential (Random.mkStdGen 0) @?= Credential @BeleniosParams "RDfIgdmiCkU46pr" ] , testGroup "readCredential" [ testGroup "WeakParams" $ let (==>) inp (exp::Either CredentialError (Credential WeakParams)) = testCase (show inp) $ readCredential inp @?= exp in [ "" ==> Left CredentialError_Length , "RDfIgdmiCkU46_K" ==> Left (CredentialError_BadChar '_') , "RDfIgdmiCkU462" ==> Left CredentialError_Length , "RDfIgdmiCkU46pKE" ==> Left CredentialError_Length , "RDfIgdmiCkU46pJ" ==> Left CredentialError_Checksum , "RDfIgdmiCkU46pK" ==> Right (Credential "RDfIgdmiCkU46pK") ] , testGroup "BeleniosParams" $ let (==>) inp (exp::Either CredentialError (Credential BeleniosParams)) = testCase (show inp) $ readCredential inp @?= exp in [ "RDfIgdmiCkU46R" ==> Left CredentialError_Length , "RDfIgdmiCkU46pKR" ==> Left CredentialError_Length , "RDfIgdmiCkU46ps" ==> Left CredentialError_Checksum , "RDfIgdmiCkU46pr" ==> Right (Credential "RDfIgdmiCkU46pr") ] ] ]