add four (failing) tests for balance report
This commit is contained in:
parent
220417ce48
commit
77b7de1b5f
@ -105,14 +105,15 @@ import Ledger.Amount
|
|||||||
import Ledger.AccountName
|
import Ledger.AccountName
|
||||||
import Ledger.Ledger
|
import Ledger.Ledger
|
||||||
import Options
|
import Options
|
||||||
|
import Utils
|
||||||
|
|
||||||
|
|
||||||
balancecommandtests = TestList [
|
|
||||||
]
|
|
||||||
|
|
||||||
-- | Print a balance report.
|
-- | Print a balance report.
|
||||||
printbalance :: [Opt] -> [String] -> Ledger -> IO ()
|
printbalance :: [Opt] -> [String] -> Ledger -> IO ()
|
||||||
printbalance opts args l = putStr $ showLedgerAccountBalances l depth
|
printbalance opts args l = putStr $ balancereport opts args l
|
||||||
|
|
||||||
|
balancereport :: [Opt] -> [String] -> Ledger -> String
|
||||||
|
balancereport opts args l = showLedgerAccountBalances l depth
|
||||||
where
|
where
|
||||||
showsubs = (ShowSubs `elem` opts)
|
showsubs = (ShowSubs `elem` opts)
|
||||||
pats = parseAccountDescriptionArgs args
|
pats = parseAccountDescriptionArgs args
|
||||||
|
|||||||
66
Tests.hs
66
Tests.hs
@ -4,6 +4,8 @@ import qualified Data.Map as Map
|
|||||||
import Text.ParserCombinators.Parsec
|
import Text.ParserCombinators.Parsec
|
||||||
import Test.HUnit
|
import Test.HUnit
|
||||||
import Ledger
|
import Ledger
|
||||||
|
import Utils
|
||||||
|
import Options
|
||||||
import BalanceCommand
|
import BalanceCommand
|
||||||
import PrintCommand
|
import PrintCommand
|
||||||
import RegisterCommand
|
import RegisterCommand
|
||||||
@ -34,12 +36,13 @@ alltests = concattests [
|
|||||||
where
|
where
|
||||||
concattests = foldr (\(TestList as) (TestList bs) -> TestList (as ++ bs)) (TestList [])
|
concattests = foldr (\(TestList as) (TestList bs) -> TestList (as ++ bs)) (TestList [])
|
||||||
|
|
||||||
tests = TestList [
|
tests =
|
||||||
|
TestList
|
||||||
|
[
|
||||||
show (dollars 1) ~?= "$1.00"
|
show (dollars 1) ~?= "$1.00"
|
||||||
,show (hours 1) ~?= "h1.00" -- should be 1.0h
|
,show (hours 1) ~?= "h1.00" -- should be 1.0h
|
||||||
|
|
||||||
,"precision subtleties" ~: do
|
,"amount precision" ~: do
|
||||||
let a1 = Amount (getcurrency "$") 1.23 1
|
let a1 = Amount (getcurrency "$") 1.23 1
|
||||||
let a2 = Amount (getcurrency "$") (-1.23) 2
|
let a2 = Amount (getcurrency "$") (-1.23) 2
|
||||||
let a3 = Amount (getcurrency "$") (-1.23) 3
|
let a3 = Amount (getcurrency "$") (-1.23) 3
|
||||||
@ -91,6 +94,63 @@ tests = TestList [
|
|||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
balancecommandtests =
|
||||||
|
TestList
|
||||||
|
[
|
||||||
|
"simple balance report" ~: do
|
||||||
|
l <- ledgerfromfile "sample.ledger"
|
||||||
|
assertequal
|
||||||
|
" $-1 assets\n\
|
||||||
|
\ $2 expenses\n\
|
||||||
|
\ $-2 income\n\
|
||||||
|
\ $1 liabilities\n\
|
||||||
|
\" --"
|
||||||
|
(balancereport [] [] l)
|
||||||
|
,
|
||||||
|
|
||||||
|
"balance report with showsubs" ~: do
|
||||||
|
l <- ledgerfromfile "sample.ledger"
|
||||||
|
assertequal
|
||||||
|
" $-1 assets\n\
|
||||||
|
\ $-2 cash\n\
|
||||||
|
\ $1 saving\n\
|
||||||
|
\ $2 expenses\n\
|
||||||
|
\ $1 food\n\
|
||||||
|
\ $1 supplies\n\
|
||||||
|
\ $-2 income\n\
|
||||||
|
\ $-1 gifts\n\
|
||||||
|
\ $-1 salary\n\
|
||||||
|
\ $1 liabilities:debts\n\
|
||||||
|
\" --"
|
||||||
|
(balancereport [ShowSubs] [] l)
|
||||||
|
,
|
||||||
|
|
||||||
|
"balance report with account pattern" ~: do
|
||||||
|
rl <- rawledgerfromfile "sample.ledger"
|
||||||
|
let l = cacheLedger (mkRegex "o") $ filterRawLedgerEntries "" "" wildcard rl
|
||||||
|
assertequal
|
||||||
|
" $1 expenses:food\n\
|
||||||
|
\ $-2 income\n\
|
||||||
|
\--------------------\n\
|
||||||
|
\ $-1\n\
|
||||||
|
\" --"
|
||||||
|
(balancereport [] ["o"] l)
|
||||||
|
,
|
||||||
|
|
||||||
|
"balance report with account pattern and showsubs" ~: do
|
||||||
|
rl <- rawledgerfromfile "sample.ledger"
|
||||||
|
let l = cacheLedger (mkRegex "o") $ filterRawLedgerEntries "" "" wildcard rl
|
||||||
|
assertequal
|
||||||
|
" $1 expenses:food\n\
|
||||||
|
\ $-2 income\n\
|
||||||
|
\ $-1 gifts\n\
|
||||||
|
\ $-1 salary\n\
|
||||||
|
\--------------------\n\
|
||||||
|
\ $-1\n\
|
||||||
|
\" --"
|
||||||
|
(balancereport [ShowSubs] ["o"] l)
|
||||||
|
]
|
||||||
|
|
||||||
-- | Assert a parsed thing equals some expected thing, or print a parse error.
|
-- | Assert a parsed thing equals some expected thing, or print a parse error.
|
||||||
assertparseequal :: (Show a, Eq a) => a -> (Either ParseError a) -> Assertion
|
assertparseequal :: (Show a, Eq a) => a -> (Either ParseError a) -> Assertion
|
||||||
assertparseequal expected parsed = either printParseError (assertequal expected) parsed
|
assertparseequal expected parsed = either printParseError (assertequal expected) parsed
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user