tests and bugfix for accountNameTreeFrom

This commit is contained in:
Simon Michael 2009-03-15 04:02:04 +00:00
parent 2dac5754c7
commit 80f20bdad8
2 changed files with 8 additions and 8 deletions

View File

@ -60,13 +60,6 @@ subAccountNamesFrom accts a = filter (`isSubAccountNameOf` a) accts
-- tree with boring accounts elided. This converts a list of
-- AccountName to a tree (later we will convert that to a tree of
-- 'Account'.)
accountNameTreeFrom_props =
[
accountNameTreeFrom ["a"] == Node "top" [Node "a" []],
accountNameTreeFrom ["a","b"] == Node "top" [Node "a" [], Node "b" []],
accountNameTreeFrom ["a","a:b"] == Node "top" [Node "a" [Node "a:b" []]],
accountNameTreeFrom ["a:b"] == Node "top" [Node "a" [Node "a:b" []]]
]
accountNameTreeFrom :: [AccountName] -> Tree AccountName
accountNameTreeFrom accts =
Node "top" (accountsFrom (topAccountNames accts))
@ -74,7 +67,7 @@ accountNameTreeFrom accts =
accountsFrom :: [AccountName] -> [Tree AccountName]
accountsFrom [] = []
accountsFrom as = [Node a (accountsFrom $ subs a) | a <- as]
subs = (subAccountNamesFrom accts)
subs = subAccountNamesFrom (expandAccountNames accts)
-- | Elide an account name to fit in the specified width.
-- From the ledger 2.6 news:

View File

@ -95,6 +95,13 @@ tests = [
"liabilities","liabilities:credit cards","liabilities:credit cards:discover"]
,
"accountNameTreeFrom" ~: do
accountNameTreeFrom ["a"] `is` Node "top" [Node "a" []]
accountNameTreeFrom ["a","b"] `is` Node "top" [Node "a" [], Node "b" []]
accountNameTreeFrom ["a","a:b"] `is` Node "top" [Node "a" [Node "a:b" []]]
accountNameTreeFrom ["a:b:c"] `is` Node "top" [Node "a" [Node "a:b" [Node "a:b:c" []]]]
,
"amount arithmetic" ~: do
let a1 = dollars 1.23
let a2 = Amount (comm "$") (-1.23) Nothing