{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TupleSections #-} module Account.Test where import Data.Data () import Data.Function (($)) import qualified Data.List as List import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NonEmpty import Data.Maybe (Maybe(..)) import Data.Monoid ((<>)) import Test.Tasty import Test.Tasty.HUnit import Hcompta.Account tests :: TestTree tests = testGroup "Account" [ testGroup "account_foldr" $ let (==>) acct ex = testCase ("["<>List.intercalate "," (NonEmpty.toList acct) <>"]") $ List.reverse (account_foldr acct (:) []) @?= ex in [ ("A":|[]) ==> [ "A":|[] ] , ("A":|["B"]) ==> [ "A":|[], "A":|["B"] ] , ("A":|["B", "C"]) ==> [ "A":|[], "A":|["B"], "A":|["B", "C"] ] ] , testGroup "account_parent" $ let (==>) acct ex = testCase ("["<>List.intercalate "," (NonEmpty.toList acct) <>"]") $ account_parent acct @?= ex in [ ("A":|[]) ==> Nothing , ("A":|["B"]) ==> Just ("A":|[]) , ("A":|["B", "C"]) ==> Just ("A":|["B"]) ] ]