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
|
2019-06-07 00:37:36 +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
|
2019-10-12 02:00:19 +03:00
|
|
|
assets:myacct $50
|
|
|
|
expense:unknown
|
2010-12-21 20:57:06 +03:00
|
|
|
|
2019-06-07 00:37:36 +03: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
|
2019-06-07 00:37:36 +03:00
|
|
|
<
|
2018-09-07 20:12:13 +03:00
|
|
|
10/2009/09,Flubber Co🎅,50,
|
|
|
|
11/2009/09,Flubber Co🎅,,50
|
2019-06-07 00:37:36 +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
|
2018-09-07 20:12:13 +03:00
|
|
|
2009/09/10 Flubber Co🎅
|
2017-06-05 07:26:18 +03:00
|
|
|
Assets:MyAccount $50
|
2019-10-12 02:00:19 +03:00
|
|
|
expense:unknown
|
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
|
2019-10-12 02:00:19 +03:00
|
|
|
income:unknown
|
2012-03-26 02:12:52 +04:00
|
|
|
|
2019-06-07 00:37:36 +03:00
|
|
|
>=0
|
2018-09-07 20:12:13 +03:00
|
|
|
|
2017-06-13 19:54:16 +03:00
|
|
|
# 3. handle conditions assigning multiple fields
|
2019-06-07 00:37:36 +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
|
2019-06-12 16:01:17 +03:00
|
|
|
2009/09/10 Flubber Co ; cmt
|
2017-06-05 07:26:18 +03:00
|
|
|
assets:myacct $50
|
2019-10-12 02:00:19 +03:00
|
|
|
acct
|
2013-06-19 11:29:45 +04:00
|
|
|
|
2019-06-07 00:37:36 +03:00
|
|
|
>=0
|
2016-10-09 04:20:26 +03:00
|
|
|
|
2017-06-13 19:54:16 +03:00
|
|
|
# 4. read CSV with balance field
|
2019-06-07 00:37:36 +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
|
2019-10-12 02:00:19 +03:00
|
|
|
assets:myacct $50 = $123
|
|
|
|
expense:unknown
|
2017-04-15 00:52:03 +03:00
|
|
|
|
2019-06-07 00:37:36 +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
|
2019-06-07 00:37:36 +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\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
|
2019-10-12 02:00:19 +03:00
|
|
|
assets:myacct $50 = $123
|
|
|
|
expense:unknown
|
2017-04-15 00:52:03 +03:00
|
|
|
|
2017-04-18 19:07:30 +03:00
|
|
|
2009/09/11 Blubber Co
|
2019-10-12 02:00:19 +03:00
|
|
|
assets:myacct $60
|
|
|
|
expense:unknown
|
2017-04-18 19:07:30 +03:00
|
|
|
|
2019-06-07 00:37:36 +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
|
2019-06-07 00:37:36 +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\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
|
2019-10-12 02:00:19 +03:00
|
|
|
assets:myacct $50 = $123
|
|
|
|
expense:unknown
|
2017-04-18 19:07:30 +03:00
|
|
|
|
|
|
|
2009/09/11 Blubber Co
|
2019-10-12 02:00:19 +03:00
|
|
|
assets:myacct $60
|
|
|
|
expense:unknown
|
2017-04-18 19:07:30 +03:00
|
|
|
|
2019-06-07 00:37:36 +03:00
|
|
|
>=0
|
2017-06-13 19:54:16 +03:00
|
|
|
|
|
|
|
# 7. read CSV with rule double-negating column
|
2019-06-07 00:37:36 +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
|
2019-10-12 02:00:19 +03:00
|
|
|
expense:other
|
2017-05-14 03:34:33 +03:00
|
|
|
|
|
|
|
2009/11/09
|
2017-06-05 07:26:18 +03:00
|
|
|
liabilities:bank $60
|
2019-10-12 02:00:19 +03:00
|
|
|
expense:other
|
2017-05-14 03:34:33 +03:00
|
|
|
|
2019-06-07 00:37:36 +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)
|
2019-06-07 00:37:36 +03:00
|
|
|
<
|
2018-09-07 20:12:13 +03:00
|
|
|
10/2009/09;Flubber Co🎅;50;
|
|
|
|
11/2009/09;Flubber Co🎅;;50
|
2019-06-07 00:37:36 +03:00
|
|
|
$ 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
|
|
|
2009/09/10 Flubber Co🎅
|
|
|
|
Assets:MyAccount $50
|
2019-10-12 02:00:19 +03:00
|
|
|
expense:unknown
|
2018-09-07 20:12:13 +03:00
|
|
|
|
|
|
|
2009/09/11 Flubber Co🎅
|
|
|
|
Assets:MyAccount $-50
|
2019-10-12 02:00:19 +03:00
|
|
|
income:unknown
|
2018-09-07 20:12:13 +03:00
|
|
|
|
2019-06-07 00:37:36 +03:00
|
|
|
>=0
|
2018-09-07 23:43:05 +03:00
|
|
|
|
2019-03-16 00:18:44 +03:00
|
|
|
# 9. read CSV with balance2 field
|
2019-06-07 00:37:36 +03:00
|
|
|
$ 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
|
2019-03-16 00:18:44 +03:00
|
|
|
2009/09/10 Flubber Co
|
2019-10-12 02:00:19 +03:00
|
|
|
assets:myacct $50
|
|
|
|
expense:unknown = $123
|
2019-03-16 00:18:44 +03:00
|
|
|
|
2019-06-07 00:37:36 +03:00
|
|
|
>=0
|
2019-03-16 00:18:44 +03:00
|
|
|
|
|
|
|
# 10. read CSV with balance1 and balance2 fields
|
2019-06-07 00:37:36 +03:00
|
|
|
$ 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
|
2019-03-16 00:18:44 +03:00
|
|
|
2009/09/10 Flubber Co
|
2019-10-12 02:00:19 +03:00
|
|
|
assets:myacct $50 = $321
|
|
|
|
expense:unknown = $123
|
2019-03-16 00:18:44 +03:00
|
|
|
|
2019-06-07 00:37:36 +03:00
|
|
|
>=0
|
2019-03-16 00:18:44 +03:00
|
|
|
|
|
|
|
|
2019-10-12 01:56:40 +03:00
|
|
|
# 11. More than two postings
|
|
|
|
$ printf 'fields date, description, amount, balance1, balance2, amount3,comment3\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\naccount3 expenses:tax\n' >t.$$.csv.rules; printf '10/2009/09,Flubber Co,50,321,123,0.234,VAT\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
|
|
2009/09/10 Flubber Co
|
|
|
|
assets:myacct $50 = $321
|
|
|
|
expense:unknown = $123
|
|
|
|
expenses:tax $0.234 ; VAT
|
|
|
|
|
|
|
|
>=0
|
|
|
|
|
|
|
|
# 12. More than two postings and different currencies
|
|
|
|
$ printf 'fields date, description, amount, balance1, balance2, currency3, amount3,comment3\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\naccount3 expenses:tax\n' >t.$$.csv.rules; printf '10/2009/09,Flubber Co,50,321,123,£,0.234,VAT\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
|
|
2009/09/10 Flubber Co
|
|
|
|
assets:myacct $50 = $321
|
|
|
|
expense:unknown = $123
|
|
|
|
expenses:tax £0.234 ; VAT
|
|
|
|
|
|
|
|
>=0
|
|
|
|
|
2019-10-12 02:06:16 +03:00
|
|
|
# 13. reading CSV with in-field and out-field, where one could be zero
|
|
|
|
<
|
|
|
|
10/2009/09,Flubber Co🎅,50,0
|
|
|
|
11/2009/09,Flubber Co🎅,0.00,50
|
|
|
|
$ 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
|
|
|
|
2009/09/10 Flubber Co🎅
|
|
|
|
Assets:MyAccount $50
|
|
|
|
expense:unknown
|
|
|
|
|
|
|
|
2009/09/11 Flubber Co🎅
|
|
|
|
Assets:MyAccount $-50
|
|
|
|
income:unknown
|
|
|
|
|
|
|
|
>=0
|
2019-10-12 01:56:40 +03:00
|
|
|
|
2019-10-12 02:49:42 +03:00
|
|
|
# 14. multiline descriptions
|
|
|
|
$ printf 'fields date, description, amount\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\n' >t.$$.csv.rules; printf '10/2009/09,"Flubber Co\nCo\nCo",50\n' | hledger -f csv:- --rules-file t.$$.csv.rules print && rm -rf t.$$.csv.rules
|
|
|
|
2009/09/10 Flubber Co Co Co
|
|
|
|
assets:myacct $50
|
|
|
|
expense:unknown
|
|
|
|
|
|
|
|
>=0
|
|
|
|
|
2019-10-12 02:55:25 +03:00
|
|
|
# 15. recursive interpolation
|
|
|
|
$ printf 'fields account1, date, description, amount\ndate-format %%d/%%Y/%%m\ncurrency $\nif Flubber\n account1 assets:%%account1\n amount (%%amount)' >t.$$.csv.rules; printf 'myacct,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
|
|
|
|
|
|
|
|
>=0
|
|
|
|
|
2019-06-07 00:37:36 +03:00
|
|
|
# . TODO: without --separator gives obscure error
|
2018-09-07 23:43:05 +03:00
|
|
|
# |
|
|
|
|
# 1 | 10/2009/09;Flubber Co🎅;50;
|
|
|
|
# | ^^^^^^^^^^
|
|
|
|
# well-formed but invalid date: 10/2009/9
|
2019-06-07 00:37:36 +03:00
|
|
|
# <
|
2018-09-07 23:43:05 +03:00
|
|
|
# 10/2009/09;Flubber Co🎅;50;
|
|
|
|
# 11/2009/09;Flubber Co🎅;;50
|
2019-06-07 00:37:36 +03:00
|
|
|
# $ 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.$$
|
2018-09-07 23:43:05 +03:00
|
|
|
# 2009/09/10 Flubber Co🎅
|
|
|
|
# Assets:MyAccount $50
|
|
|
|
# income:unknown $-50
|
|
|
|
#
|
|
|
|
# 2009/09/11 Flubber Co🎅
|
|
|
|
# Assets:MyAccount $-50
|
|
|
|
# expenses:unknown $50
|
|
|
|
#
|
2019-06-07 00:37:36 +03:00
|
|
|
# >=0
|
2018-09-07 23:43:05 +03:00
|
|
|
|
2019-06-07 00:37:36 +03:00
|
|
|
# . reading TSV (tab-separated) TODO user error (CSV record ["10/2009/09\tFlubber Co\127877\t50\t"] has less than two fields)
|
|
|
|
# <
|
2018-09-07 23:43:05 +03:00
|
|
|
# 10/2009/09 Flubber Co🎅 50
|
|
|
|
# 11/2009/09 Flubber Co🎅 50
|
2019-06-07 00:37:36 +03:00
|
|
|
# $ 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.$$
|
2018-09-07 23:43:05 +03:00
|
|
|
# 2009/09/10 Flubber Co🎅
|
|
|
|
# Assets:MyAccount $50
|
|
|
|
# income:unknown $-50
|
|
|
|
#
|
|
|
|
# 2009/09/11 Flubber Co🎅
|
|
|
|
# Assets:MyAccount $-50
|
|
|
|
# expenses:unknown $50
|
|
|
|
#
|
2019-06-07 00:37:36 +03:00
|
|
|
# >=0
|