1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE ScopedTypeVariables #-}
3 {-# LANGUAGE TupleSections #-}
5 module Account.Test where
7 import Data.Function (($))
8 import qualified Data.List as List
9 import Data.List.NonEmpty (NonEmpty(..))
10 import qualified Data.List.NonEmpty as NonEmpty
11 import Data.Maybe (Maybe(..))
12 import Data.Monoid ((<>))
14 import Test.Tasty.HUnit
16 import Hcompta.Account
19 tests = testGroup "Account"
20 [ testGroup "account_foldr" $
22 testCase ("["<>List.intercalate "," (NonEmpty.toList acct) <>"]") $
23 List.reverse (account_foldr acct (:) []) @?= ex in
24 [ ("A":|[]) ==> [ "A":|[] ]
25 , ("A":|["B"]) ==> [ "A":|[], "A":|["B"] ]
26 , ("A":|["B", "C"]) ==> [ "A":|[], "A":|["B"], "A":|["B", "C"] ]
28 , testGroup "account_parent" $
30 testCase ("["<>List.intercalate "," (NonEmpty.toList acct) <>"]") $
31 account_parent acct @?= ex in
32 [ ("A":|[]) ==> Nothing
33 , ("A":|["B"]) ==> Just ("A":|[])
34 , ("A":|["B", "C"]) ==> Just ("A":|["B"])