]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Account/Test.hs
Adapte hcompta-cli.
[comptalang.git] / lib / Hcompta / Account / Test.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 {-# LANGUAGE ScopedTypeVariables #-}
3 {-# LANGUAGE TupleSections #-}
4
5 module Account.Test where
6 import Data.Data ()
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 ((<>))
13 import Test.Tasty
14 import Test.Tasty.HUnit
15
16 import Hcompta.Account
17
18 tests :: TestTree
19 tests = testGroup "Account"
20 [ testGroup "account_foldr" $
21 let (==>) acct ex =
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"] ]
27 ]
28 , testGroup "account_parent" $
29 let (==>) acct ex =
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"])
35 ]
36 ]