mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
refactor
This commit is contained in:
parent
993972549a
commit
eedf0b211a
72
Tests.hs
72
Tests.hs
@ -656,78 +656,6 @@ tests = TestList [
|
||||
,"showMixedAmount" ~: do
|
||||
showMixedAmount (Mixed []) ~?= "0"
|
||||
|
||||
,"showTransaction" ~: do
|
||||
assertEqual "show a balanced transaction, eliding last amount"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries $47.18"
|
||||
," assets:checking"
|
||||
,""
|
||||
])
|
||||
(let t = Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting (Just t)
|
||||
,Posting False "assets:checking" (Mixed [dollars (-47.18)]) "" RegularPosting (Just t)
|
||||
] ""
|
||||
in showTransaction t)
|
||||
assertEqual "show a balanced transaction, no eliding"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries $47.18"
|
||||
," assets:checking $-47.18"
|
||||
,""
|
||||
])
|
||||
(let t = Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting (Just t)
|
||||
,Posting False "assets:checking" (Mixed [dollars (-47.18)]) "" RegularPosting (Just t)
|
||||
] ""
|
||||
in showTransactionUnelided t)
|
||||
-- document some cases that arise in debug/testing:
|
||||
assertEqual "show an unbalanced transaction, should not elide"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries $47.18"
|
||||
," assets:checking $-47.19"
|
||||
,""
|
||||
])
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting Nothing
|
||||
,Posting False "assets:checking" (Mixed [dollars (-47.19)]) "" RegularPosting Nothing
|
||||
] ""))
|
||||
assertEqual "show an unbalanced transaction with one posting, should not elide"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries $47.18"
|
||||
,""
|
||||
])
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting Nothing
|
||||
] ""))
|
||||
assertEqual "show a transaction with one posting and a missing amount"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries "
|
||||
,""
|
||||
])
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" missingamt "" RegularPosting Nothing
|
||||
] ""))
|
||||
|
||||
assertEqual "show a transaction with a priced commodityless amount"
|
||||
(unlines
|
||||
["2010/01/01 x"
|
||||
," a 1 @ $2"
|
||||
," b "
|
||||
,""
|
||||
])
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction (parsedate "2010/01/01") Nothing False "" "x" ""
|
||||
[Posting False "a" (Mixed [Amount unknown 1 (Just $ Mixed [Amount dollar{precision=0} 2 Nothing])]) "" RegularPosting Nothing
|
||||
,Posting False "b" missingamt "" RegularPosting Nothing
|
||||
] ""))
|
||||
|
||||
,"someamount" ~: do
|
||||
let -- | compare a parse result with a MixedAmount, showing the debug representation for clarity
|
||||
assertMixedAmountParse parseresult mixedamount =
|
||||
|
@ -47,7 +47,7 @@ tests_Ledger = TestList
|
||||
-- ,Ledger.Commodity.tests_Commodity
|
||||
Ledger.Dates.tests_Dates
|
||||
-- ,Ledger.IO.tests_IO
|
||||
-- ,Ledger.Transaction.tests_Transaction
|
||||
,Ledger.Transaction.tests_Transaction
|
||||
-- ,Ledger.Ledger.tests_Ledger
|
||||
-- ,Ledger.Parse.tests_Parse
|
||||
-- ,Ledger.Journal.tests_Journal
|
||||
|
@ -12,6 +12,7 @@ import Ledger.Types
|
||||
import Ledger.Dates
|
||||
import Ledger.Posting
|
||||
import Ledger.Amount
|
||||
import Ledger.Commodity (dollars, dollar, unknown)
|
||||
|
||||
|
||||
instance Show Transaction where show = showTransactionUnelided
|
||||
@ -140,3 +141,86 @@ txnTieKnot t@Transaction{tpostings=ps} = t{tpostings=map (settxn t) ps}
|
||||
settxn :: Transaction -> Posting -> Posting
|
||||
settxn t p = p{ptransaction=Just t}
|
||||
|
||||
tests_Transaction = TestList [
|
||||
"showTransaction" ~: do
|
||||
assertEqual "show a balanced transaction, eliding last amount"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries $47.18"
|
||||
," assets:checking"
|
||||
,""
|
||||
])
|
||||
(let t = Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting (Just t)
|
||||
,Posting False "assets:checking" (Mixed [dollars (-47.18)]) "" RegularPosting (Just t)
|
||||
] ""
|
||||
in showTransaction t)
|
||||
|
||||
,"showTransaction" ~: do
|
||||
assertEqual "show a balanced transaction, no eliding"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries $47.18"
|
||||
," assets:checking $-47.18"
|
||||
,""
|
||||
])
|
||||
(let t = Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting (Just t)
|
||||
,Posting False "assets:checking" (Mixed [dollars (-47.18)]) "" RegularPosting (Just t)
|
||||
] ""
|
||||
in showTransactionUnelided t)
|
||||
|
||||
-- document some cases that arise in debug/testing:
|
||||
,"showTransaction" ~: do
|
||||
assertEqual "show an unbalanced transaction, should not elide"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries $47.18"
|
||||
," assets:checking $-47.19"
|
||||
,""
|
||||
])
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting Nothing
|
||||
,Posting False "assets:checking" (Mixed [dollars (-47.19)]) "" RegularPosting Nothing
|
||||
] ""))
|
||||
|
||||
,"showTransaction" ~: do
|
||||
assertEqual "show an unbalanced transaction with one posting, should not elide"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries $47.18"
|
||||
,""
|
||||
])
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" (Mixed [dollars 47.18]) "" RegularPosting Nothing
|
||||
] ""))
|
||||
|
||||
,"showTransaction" ~: do
|
||||
assertEqual "show a transaction with one posting and a missing amount"
|
||||
(unlines
|
||||
["2007/01/28 coopportunity"
|
||||
," expenses:food:groceries "
|
||||
,""
|
||||
])
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction (parsedate "2007/01/28") Nothing False "" "coopportunity" ""
|
||||
[Posting False "expenses:food:groceries" missingamt "" RegularPosting Nothing
|
||||
] ""))
|
||||
|
||||
,"showTransaction" ~: do
|
||||
assertEqual "show a transaction with a priced commodityless amount"
|
||||
(unlines
|
||||
["2010/01/01 x"
|
||||
," a 1 @ $2"
|
||||
," b "
|
||||
,""
|
||||
])
|
||||
(showTransaction
|
||||
(txnTieKnot $ Transaction (parsedate "2010/01/01") Nothing False "" "x" ""
|
||||
[Posting False "a" (Mixed [Amount unknown 1 (Just $ Mixed [Amount dollar{precision=0} 2 Nothing])]) "" RegularPosting Nothing
|
||||
,Posting False "b" missingamt "" RegularPosting Nothing
|
||||
] ""))
|
||||
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user