2017-06-14 18:54:32 +03:00
|
|
|
# These tests read CSV from stdin for convenience, so to ensure we get the CSV reader's
|
|
|
|
# error, the csv: prefix is used.
|
2017-07-06 16:10:54 +03:00
|
|
|
#
|
|
|
|
# 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 ?
|
2017-06-14 18:33:40 +03:00
|
|
|
|
2012-03-26 02:12:52 +04:00
|
|
|
# 1. read CSV to hledger journal format
|
2017-06-14 18:54:32 +03:00
|
|
|
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
|
2010-12-21 20:57:06 +03:00
|
|
|
>>>
|
|
|
|
2009/09/10 Flubber Co
|
2017-06-05 07:26:18 +03:00
|
|
|
assets:myacct $50
|
2017-08-15 18:16:49 +03:00
|
|
|
income:unknown $-50
|
2010-12-21 20:57:06 +03:00
|
|
|
|
2017-07-06 16:10:54 +03:00
|
|
|
>>>2
|
2011-08-15 02:15:39 +04:00
|
|
|
>>>=0
|
2012-01-30 21:18:32 +04:00
|
|
|
|
2012-03-26 02:12:52 +04:00
|
|
|
# 2. reading CSV with in-field and out-field
|
2017-06-14 18:54:32 +03:00
|
|
|
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
|
2012-03-26 02:12:52 +04:00
|
|
|
<<<
|
2018-09-07 20:12:13 +03:00
|
|
|
10/2009/09,Flubber Co🎅,50,
|
|
|
|
11/2009/09,Flubber Co🎅,,50
|
2012-03-26 02:12:52 +04:00
|
|
|
>>>
|
2018-09-07 20:12:13 +03:00
|
|
|
2009/09/10 Flubber Co🎅
|
2017-06-05 07:26:18 +03:00
|
|
|
Assets:MyAccount $50
|
2017-08-15 18:16:49 +03:00
|
|
|
income:unknown $-50
|
2012-03-26 02:12:52 +04:00
|
|
|
|
2018-09-07 20:12:13 +03:00
|
|
|
2009/09/11 Flubber Co🎅
|
2017-06-05 07:26:18 +03:00
|
|
|
Assets:MyAccount $-50
|
2017-08-15 18:16:49 +03:00
|
|
|
expenses:unknown $50
|
2012-03-26 02:12:52 +04:00
|
|
|
|
2017-07-06 16:10:54 +03:00
|
|
|
>>>2
|
2012-03-26 02:12:52 +04:00
|
|
|
>>>=0
|
|
|
|
|
2018-09-07 20:12:13 +03:00
|
|
|
|
2017-06-13 19:54:16 +03:00
|
|
|
# 3. handle conditions assigning multiple fields
|
2017-06-14 18:54:32 +03:00
|
|
|
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
|
2013-06-19 11:29:45 +04:00
|
|
|
>>>
|
2013-09-10 21:32:49 +04:00
|
|
|
2009/09/10 Flubber Co ; cmt
|
2017-06-05 07:26:18 +03:00
|
|
|
assets:myacct $50
|
2017-08-15 18:16:49 +03:00
|
|
|
acct $-50
|
2013-06-19 11:29:45 +04:00
|
|
|
|
2017-07-06 16:10:54 +03:00
|
|
|
>>>2
|
2013-06-19 11:29:45 +04:00
|
|
|
>>>=0
|
2016-10-09 04:20:26 +03:00
|
|
|
|
2017-06-13 19:54:16 +03:00
|
|
|
# 4. read CSV with balance field
|
2017-06-14 18:54:32 +03:00
|
|
|
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
|
2017-04-15 00:52:03 +03:00
|
|
|
>>>
|
|
|
|
2009/09/10 Flubber Co
|
2017-06-05 07:26:18 +03:00
|
|
|
assets:myacct $50 = $123
|
2017-08-15 18:16:49 +03:00
|
|
|
income:unknown $-50
|
2017-04-15 00:52:03 +03:00
|
|
|
|
2017-07-06 16:10:54 +03:00
|
|
|
>>>2
|
2017-04-15 00:52:03 +03:00
|
|
|
>>>=0
|
2017-06-13 19:54:16 +03:00
|
|
|
|
2017-06-14 18:54:32 +03:00
|
|
|
# 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
|
2017-04-18 19:07:30 +03:00
|
|
|
>>>
|
|
|
|
2009/09/10 Flubber Co
|
2017-06-05 07:26:18 +03:00
|
|
|
assets:myacct $50 = $123
|
2017-08-15 18:16:49 +03:00
|
|
|
income:unknown $-50
|
2017-04-15 00:52:03 +03:00
|
|
|
|
2017-04-18 19:07:30 +03:00
|
|
|
2009/09/11 Blubber Co
|
2017-06-05 07:26:18 +03:00
|
|
|
assets:myacct $60
|
2017-08-15 18:16:49 +03:00
|
|
|
income:unknown $-60
|
2017-04-18 19:07:30 +03:00
|
|
|
|
2017-07-06 16:10:54 +03:00
|
|
|
>>>2
|
2017-04-18 19:07:30 +03:00
|
|
|
>>>=0
|
2017-06-13 19:54:16 +03:00
|
|
|
|
2017-06-14 18:54:32 +03:00
|
|
|
# 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
|
2017-04-18 19:07:30 +03:00
|
|
|
>>>
|
|
|
|
2009/09/10 Flubber Co
|
2017-06-05 07:26:18 +03:00
|
|
|
assets:myacct $50 = $123
|
2017-08-15 18:16:49 +03:00
|
|
|
income:unknown $-50
|
2017-04-18 19:07:30 +03:00
|
|
|
|
|
|
|
2009/09/11 Blubber Co
|
2017-06-05 07:26:18 +03:00
|
|
|
assets:myacct $60
|
2017-08-15 18:16:49 +03:00
|
|
|
income:unknown $-60
|
2017-04-18 19:07:30 +03:00
|
|
|
|
2017-07-06 16:10:54 +03:00
|
|
|
>>>2
|
2017-04-18 19:07:30 +03:00
|
|
|
>>>=0
|
2017-06-13 19:54:16 +03:00
|
|
|
|
|
|
|
# 7. read CSV with rule double-negating column
|
2017-06-14 18:54:32 +03:00
|
|
|
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
|
2017-05-14 03:34:33 +03:00
|
|
|
>>>
|
|
|
|
2009/10/09
|
2017-06-05 07:26:18 +03:00
|
|
|
liabilities:bank $-50
|
2017-08-15 18:16:49 +03:00
|
|
|
expense:other $50
|
2017-05-14 03:34:33 +03:00
|
|
|
|
|
|
|
2009/11/09
|
2017-06-05 07:26:18 +03:00
|
|
|
liabilities:bank $60
|
2017-08-15 18:16:49 +03:00
|
|
|
expense:other $-60
|
2017-05-14 03:34:33 +03:00
|
|
|
|
2017-07-06 16:10:54 +03:00
|
|
|
>>>2
|
2017-05-14 03:34:33 +03:00
|
|
|
>>>=0
|
2018-09-07 20:12:13 +03:00
|
|
|
|
2018-09-07 23:42:44 +03:00
|
|
|
# 8. reading with custom separator: SSV (semicolon-separated)
|
|
|
|
printf 'account1 Assets:MyAccount\ndate %%1\ndate-format %%d/%%Y/%%m\ndescription %%2\namount-in %%3\namount-out %%4\ncurrency $\n' >rules.$$ ; hledger --separator ';' -f csv:- --rules-file rules.$$ print && rm -rf rules.$$
|
2018-09-07 20:12:13 +03:00
|
|
|
<<<
|
|
|
|
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
|
2018-09-07 23:43:05 +03:00
|
|
|
>>>=0
|
|
|
|
|
2019-03-16 00:18:44 +03:00
|
|
|
# 9. read CSV with balance2 field
|
|
|
|
printf 'fields date, description, amount, balance2\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
|
|
|
|
income:unknown $-50 = $123
|
|
|
|
|
|
|
|
>>>2
|
|
|
|
>>>=0
|
|
|
|
|
|
|
|
# 10. read CSV with balance1 and balance2 fields
|
|
|
|
printf 'fields date, description, amount, balance1, balance2\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\n' >t.$$.csv.rules; printf '10/2009/09,Flubber Co,50,321,123\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
|
|
>>>
|
|
|
|
2009/09/10 Flubber Co
|
|
|
|
assets:myacct $50 = $321
|
|
|
|
income:unknown $-50 = $123
|
|
|
|
|
|
|
|
>>>2
|
|
|
|
>>>=0
|
|
|
|
|
|
|
|
|
2018-09-07 23:43:05 +03:00
|
|
|
# 9. TODO: without --separator gives obscure error
|
|
|
|
# |
|
|
|
|
# 1 | 10/2009/09;Flubber Co🎅;50;
|
|
|
|
# | ^^^^^^^^^^
|
|
|
|
# well-formed but invalid date: 10/2009/9
|
|
|
|
# printf 'account1 Assets:MyAccount\ndate %%1\ndate-format %%d/%%Y/%%m\ndescription %%2\namount-in %%3\namount-out %%4\ncurrency $\n' >rules.$$ ; hledger -f csv:- --rules-file rules.$$ print && rm -rf 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
|
|
|
|
|
|
|
|
# 10. reading TSV (tab-separated) TODO user error (CSV record ["10/2009/09\tFlubber Co\127877\t50\t"] has less than two fields)
|
|
|
|
# printf 'account1 Assets:MyAccount\ndate %%1\ndate-format %%d/%%Y/%%m\ndescription %%2\namount-in %%3\namount-out %%4\ncurrency $\n' >rules.$$ ; hledger --separator "\t" -f csv:- --rules-file rules.$$ print && rm -rf 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
|