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