This is subjective, but simplifies things as we'll be adding more than two postings. Free-form entry templates will allow custom orderings in future.
95 lines
3.6 KiB
Plaintext
95 lines
3.6 KiB
Plaintext
# These tests read CSV from stdin for convenience, so to ensure we get the CSV reader's
|
|
# error, the csv: prefix is used.
|
|
#
|
|
# The final cleanup command is chained with && so as not to mask hledger's exit code,
|
|
# but this means a temp file is left behind whenever hledger fails. What TODO ?
|
|
|
|
# 1. read CSV to hledger journal format
|
|
printf 'fields date, description, amount\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\n' >t.$$.csv.rules; printf '10/2009/09,Flubber Co,50\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
>>>
|
|
2009/09/10 Flubber Co
|
|
assets:myacct $50
|
|
income:unknown $-50
|
|
|
|
>>>2
|
|
>>>=0
|
|
|
|
# 2. reading CSV with in-field and out-field
|
|
printf 'account1 Assets:MyAccount\ndate %%1\ndate-format %%d/%%Y/%%m\ndescription %%2\namount-in %%3\namount-out %%4\ncurrency $\n' >t.$$.csv.rules ; hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
<<<
|
|
10/2009/09,Flubber Co,50,
|
|
11/2009/09,Flubber Co,,50
|
|
>>>
|
|
2009/09/10 Flubber Co
|
|
Assets:MyAccount $50
|
|
income:unknown $-50
|
|
|
|
2009/09/11 Flubber Co
|
|
Assets:MyAccount $-50
|
|
expenses:unknown $50
|
|
|
|
>>>2
|
|
>>>=0
|
|
|
|
# 3. handle conditions assigning multiple fields
|
|
printf 'fields date, description, amount\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\nif Flubber\n account2 acct\n comment cmt' >t.$$.csv.rules; printf '10/2009/09,Flubber Co,50\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
>>>
|
|
2009/09/10 Flubber Co ; cmt
|
|
assets:myacct $50
|
|
acct $-50
|
|
|
|
>>>2
|
|
>>>=0
|
|
|
|
# 4. read CSV with balance field
|
|
printf 'fields date, description, amount, balance\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\n' >t.$$.csv.rules; printf '10/2009/09,Flubber Co,50,123\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
>>>
|
|
2009/09/10 Flubber Co
|
|
assets:myacct $50 = $123
|
|
income:unknown $-50
|
|
|
|
>>>2
|
|
>>>=0
|
|
|
|
# 5. read CSV with empty balance field
|
|
printf 'fields date, description, amount, balance\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\n' >t.$$.csv.rules; printf '10/2009/09,Flubber Co,50,123\n11/2009/09,Blubber Co,60,\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
>>>
|
|
2009/09/10 Flubber Co
|
|
assets:myacct $50 = $123
|
|
income:unknown $-50
|
|
|
|
2009/09/11 Blubber Co
|
|
assets:myacct $60
|
|
income:unknown $-60
|
|
|
|
>>>2
|
|
>>>=0
|
|
|
|
# 6. read CSV with only whitespace in balance field
|
|
printf 'fields date, description, amount, balance\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\n' >t.$$.csv.rules; printf '10/2009/09,Flubber Co,50,123\n11/2009/09,Blubber Co,60, \n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
>>>
|
|
2009/09/10 Flubber Co
|
|
assets:myacct $50 = $123
|
|
income:unknown $-50
|
|
|
|
2009/09/11 Blubber Co
|
|
assets:myacct $60
|
|
income:unknown $-60
|
|
|
|
>>>2
|
|
>>>=0
|
|
|
|
# 7. read CSV with rule double-negating column
|
|
printf 'skip 1\n\ncurrency $\n\nfields date, payee, payment\n\namount -%%payment\naccount1 liabilities:bank\naccount2 expense:other' >t.$$.csv.rules; printf 'date,payee,amount\n2009/10/9,Flubber Co,50\n2009/11/09,Merchant Credit,-60\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
>>>
|
|
2009/10/09
|
|
liabilities:bank $-50
|
|
expense:other $50
|
|
|
|
2009/11/09
|
|
liabilities:bank $60
|
|
expense:other $-60
|
|
|
|
>>>2
|
|
>>>=0
|