refactor balance tests
This commit is contained in:
parent
f831064644
commit
9d47496d37
203
Tests.hs
203
Tests.hs
@ -26,13 +26,12 @@ runtests args = do
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- tests
|
-- tests
|
||||||
|
|
||||||
tests =
|
tests = [TestList []
|
||||||
[TestList []
|
,misc_tests
|
||||||
,misc_tests
|
,balancereportacctnames_tests
|
||||||
,balancereportacctnames_tests
|
,balancecommand_tests
|
||||||
,balancecommand_tests
|
,registercommand_tests
|
||||||
,registercommand_tests
|
]
|
||||||
]
|
|
||||||
|
|
||||||
misc_tests = TestList [
|
misc_tests = TestList [
|
||||||
"show dollars" ~: show (dollars 1) ~?= "$1.00"
|
"show dollars" ~: show (dollars 1) ~?= "$1.00"
|
||||||
@ -120,127 +119,103 @@ balancereportacctnames_tests = TestList
|
|||||||
assertequal e (balancereportacctnames l (opt=="-s") pats t)
|
assertequal e (balancereportacctnames l (opt=="-s") pats t)
|
||||||
|
|
||||||
balancecommand_tests = TestList [
|
balancecommand_tests = TestList [
|
||||||
"simple balance report" ~: do
|
"simple balance report" ~:
|
||||||
l <- ledgerfromfile [] "sample.ledger"
|
([], []) `gives`
|
||||||
assertequal (
|
(" $-1 assets\n" ++
|
||||||
" $-1 assets\n" ++
|
" $2 expenses\n" ++
|
||||||
" $2 expenses\n" ++
|
" $-2 income\n" ++
|
||||||
" $-2 income\n" ++
|
" $1 liabilities\n" ++
|
||||||
" $1 liabilities\n" ++
|
"")
|
||||||
"")
|
|
||||||
(showBalanceReport [] [] l)
|
|
||||||
,
|
,
|
||||||
"balance report with --subtotal" ~: do
|
"balance report with --subtotal" ~:
|
||||||
l <- ledgerfromfile [] "sample.ledger"
|
([SubTotal], []) `gives`
|
||||||
assertequal (
|
(" $-1 assets\n" ++
|
||||||
" $-1 assets\n" ++
|
" $-2 cash\n" ++
|
||||||
" $-2 cash\n" ++
|
" $1 saving\n" ++
|
||||||
" $1 saving\n" ++
|
" $2 expenses\n" ++
|
||||||
" $2 expenses\n" ++
|
" $1 food\n" ++
|
||||||
" $1 food\n" ++
|
" $1 supplies\n" ++
|
||||||
" $1 supplies\n" ++
|
" $-2 income\n" ++
|
||||||
" $-2 income\n" ++
|
" $-1 gifts\n" ++
|
||||||
" $-1 gifts\n" ++
|
" $-1 salary\n" ++
|
||||||
" $-1 salary\n" ++
|
" $1 liabilities:debts\n" ++
|
||||||
" $1 liabilities:debts\n" ++
|
"")
|
||||||
"")
|
|
||||||
(showBalanceReport [SubTotal] [] l)
|
|
||||||
,
|
,
|
||||||
"balance report with account pattern o" ~: do
|
"balance report with account pattern o" ~:
|
||||||
l <- ledgerfromfile ["o"] "sample.ledger"
|
([], ["o"]) `gives`
|
||||||
assertequal (
|
(" $1 expenses:food\n" ++
|
||||||
" $1 expenses:food\n" ++
|
" $-2 income\n" ++
|
||||||
" $-2 income\n" ++
|
"--------------------\n" ++
|
||||||
"--------------------\n" ++
|
" $-1\n" ++
|
||||||
" $-1\n" ++
|
"")
|
||||||
"")
|
|
||||||
(showBalanceReport [] ["o"] l)
|
|
||||||
,
|
,
|
||||||
"balance report with account pattern o and --subtotal" ~: do
|
"balance report with account pattern o and --subtotal" ~:
|
||||||
l <- ledgerfromfile ["o"] "sample.ledger"
|
([SubTotal], ["o"]) `gives`
|
||||||
assertequal (
|
(" $1 expenses:food\n" ++
|
||||||
" $1 expenses:food\n" ++
|
" $-2 income\n" ++
|
||||||
" $-2 income\n" ++
|
" $-1 gifts\n" ++
|
||||||
" $-1 gifts\n" ++
|
" $-1 salary\n" ++
|
||||||
" $-1 salary\n" ++
|
"--------------------\n" ++
|
||||||
"--------------------\n" ++
|
" $-1\n" ++
|
||||||
" $-1\n" ++
|
"")
|
||||||
"")
|
|
||||||
(showBalanceReport [SubTotal] ["o"] l)
|
|
||||||
,
|
,
|
||||||
"balance report with account pattern a" ~: do
|
"balance report with account pattern a" ~:
|
||||||
l <- ledgerfromfile ["a"] "sample.ledger"
|
([], ["a"]) `gives`
|
||||||
assertequal (
|
(" $-1 assets\n" ++
|
||||||
" $-1 assets\n" ++
|
" $-2 cash\n" ++
|
||||||
" $-2 cash\n" ++
|
" $1 saving\n" ++
|
||||||
" $1 saving\n" ++
|
" $-1 income:salary\n" ++
|
||||||
" $-1 income:salary\n" ++
|
" $1 liabilities\n" ++
|
||||||
" $1 liabilities\n" ++
|
"--------------------\n" ++
|
||||||
"--------------------\n" ++
|
" $-1\n" ++
|
||||||
" $-1\n" ++
|
"")
|
||||||
"")
|
|
||||||
(showBalanceReport [] ["a"] l)
|
|
||||||
,
|
,
|
||||||
"balance report with account pattern e" ~: do
|
"balance report with account pattern e" ~:
|
||||||
l <- ledgerfromfile ["e"] "sample.ledger"
|
([], ["e"]) `gives`
|
||||||
assertequal (
|
(" $-1 assets\n" ++
|
||||||
" $-1 assets\n" ++
|
" $2 expenses\n" ++
|
||||||
" $2 expenses\n" ++
|
" $1 supplies\n" ++
|
||||||
" $1 supplies\n" ++
|
" $-2 income\n" ++
|
||||||
" $-2 income\n" ++
|
" $1 liabilities:debts\n" ++
|
||||||
" $1 liabilities:debts\n" ++
|
"")
|
||||||
"")
|
|
||||||
(showBalanceReport [] ["e"] l)
|
|
||||||
,
|
,
|
||||||
"balance report with unmatched parent of two matched subaccounts" ~:
|
"balance report with unmatched parent of two matched subaccounts" ~:
|
||||||
do
|
([], ["cash","saving"]) `gives`
|
||||||
l <- ledgerfromfile ["cash","saving"] "sample.ledger"
|
(" $-2 assets:cash\n" ++
|
||||||
assertequal (
|
" $1 assets:saving\n" ++
|
||||||
" $-2 assets:cash\n" ++
|
"--------------------\n" ++
|
||||||
" $1 assets:saving\n" ++
|
" $-1\n" ++
|
||||||
"--------------------\n" ++
|
"")
|
||||||
" $-1\n" ++
|
|
||||||
"")
|
|
||||||
(showBalanceReport [] ["cash","saving"] l)
|
|
||||||
,
|
,
|
||||||
"balance report with multi-part account name" ~:
|
"balance report with multi-part account name" ~:
|
||||||
do
|
([], ["expenses:food"]) `gives`
|
||||||
let pats = ["expenses:food"]
|
(" $1 expenses:food\n" ++
|
||||||
l <- ledgerfromfile pats "sample.ledger"
|
"--------------------\n" ++
|
||||||
assertequal (
|
" $1\n" ++
|
||||||
" $1 expenses:food\n" ++
|
"")
|
||||||
"--------------------\n" ++
|
|
||||||
" $1\n" ++
|
|
||||||
"")
|
|
||||||
$ showBalanceReport [] pats l
|
|
||||||
,
|
,
|
||||||
"balance report with negative account pattern" ~: do
|
"balance report with negative account pattern" ~:
|
||||||
l <- ledgerfromfile ["-assets"] "sample.ledger"
|
([], ["-assets"]) `gives`
|
||||||
assertequal (
|
(" $2 expenses\n" ++
|
||||||
" $2 expenses\n" ++
|
" $-2 income\n" ++
|
||||||
" $-2 income\n" ++
|
" $1 liabilities\n" ++
|
||||||
" $1 liabilities\n" ++
|
"--------------------\n" ++
|
||||||
"--------------------\n" ++
|
" $1\n" ++
|
||||||
" $1\n" ++
|
"")
|
||||||
"")
|
|
||||||
(showBalanceReport [] ["-assets"] l)
|
|
||||||
,
|
,
|
||||||
"balance report negative account pattern always matches full name" ~:
|
"balance report negative account pattern always matches full name" ~:
|
||||||
do
|
([], ["-e"]) `gives` ""
|
||||||
l <- ledgerfromfile ["-e"] "sample.ledger"
|
|
||||||
assertequal "" $ showBalanceReport [] ["-e"] l
|
|
||||||
,
|
,
|
||||||
"balance report negative patterns affect totals" ~:
|
"balance report negative patterns affect totals" ~:
|
||||||
do
|
([], ["expenses","-food"]) `gives`
|
||||||
let pats = ["expenses","-food"]
|
(" $1 expenses\n" ++
|
||||||
l <- ledgerfromfile pats "sample.ledger"
|
"--------------------\n" ++
|
||||||
assertequal (
|
" $1\n" ++
|
||||||
" $1 expenses\n" ++
|
"")
|
||||||
"--------------------\n" ++
|
] where
|
||||||
" $1\n" ++
|
gives (opts,pats) e = do
|
||||||
"")
|
l <- ledgerfromfile pats "sample.ledger"
|
||||||
$ showBalanceReport [] pats l
|
assertequal e (showBalanceReport opts pats l)
|
||||||
]
|
|
||||||
|
|
||||||
registercommand_tests = TestList [
|
registercommand_tests = TestList [
|
||||||
"register report" ~:
|
"register report" ~:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user