]> Git — Sourcephile - majurity.git/blob - hjugement-protocol/test/HUnit/Credential.hs
protocol: Fix Credential
[majurity.git] / hjugement-protocol / test / HUnit / Credential.hs
1 {-# LANGUAGE AllowAmbiguousTypes #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 {-# LANGUAGE TypeApplications #-}
4 module HUnit.Credential where
5
6 import qualified Control.Monad.Trans.State.Strict as S
7 import qualified System.Random as Random
8
9 import Protocol.Credential
10 import HUnit.Utils
11
12 hunit :: TestTree
13 hunit = testGroup "Credential"
14 [ testGroup "randomCredential"
15 [ testCase "0" $
16 S.evalState randomCredential (Random.mkStdGen 0) @?=
17 Credential "xLcs7ev6Jy6FHHE"
18 ]
19 , testGroup "readCredential" $
20 let (==>) inp exp =
21 testCase (show inp) $ readCredential inp @?= exp in
22 [ "" ==> Left CredentialError_Length
23 , "xLcs7ev6Jy6FH_E" ==> Left (CredentialError_BadChar '_')
24 , "xLcs7ev6Jy6FHIE" ==> Left (CredentialError_BadChar 'I')
25 , "xLcs7ev6Jy6FH0E" ==> Left (CredentialError_BadChar '0')
26 , "xLcs7ev6Jy6FHOE" ==> Left (CredentialError_BadChar 'O')
27 , "xLcs7ev6Jy6FHlE" ==> Left (CredentialError_BadChar 'l')
28 , "xLcs7ev6Jy6FH6" ==> Left CredentialError_Length
29 , "xLcs7ev6Jy6FHHy1" ==> Left CredentialError_Length
30 , "xLcs7ev6Jy6FHHF" ==> Left CredentialError_Checksum
31 , "xLcs7ev6Jy6FHHE" ==> Right (Credential "xLcs7ev6Jy6FHHE")
32 ]
33 ]