Skip to content
Permalink
Browse files

;csv: update shelltests format

  • Loading branch information...
simonmichael committed Jun 6, 2019
1 parent 289891c commit abf455c10f0ada4026d6bf77537fdf82b1181fe8
Showing with 30 additions and 55 deletions.
  1. +30 −55 tests/csv/csv-read.test
@@ -5,21 +5,18 @@
# 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
>>>
$ 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
>=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
>>>
$ 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
income:unknown $-50
@@ -28,33 +25,26 @@
Assets:MyAccount $-50
expenses:unknown $50

>>>2
>>>=0

>=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
>>>
$ 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
>=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
>>>
$ 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
>=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
>>>
$ 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
@@ -63,12 +53,10 @@
assets:myacct $60
income:unknown $-60

>>>2
>>>=0
>=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
>>>
$ 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
@@ -77,12 +65,10 @@
assets:myacct $60
income:unknown $-60

>>>2
>>>=0
>=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
>>>
$ 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
@@ -91,15 +77,13 @@
liabilities:bank $60
expense:other $-60

>>>2
>>>=0
>=0

# 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.$$
<<<
<
10/2009/09;Flubber Co🎅;50;
11/2009/09;Flubber Co🎅;;50
>>>
$ 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.$$
2009/09/10 Flubber Co🎅
Assets:MyAccount $50
income:unknown $-50
@@ -108,40 +92,34 @@
Assets:MyAccount $-50
expenses:unknown $50

>>>2
>>>=0
>=0

# 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
>>>
$ 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
>=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
>>>
$ 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
>=0


# 9. TODO: without --separator gives obscure error
# . 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
# >>>
# $ 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.$$
# 2009/09/10 Flubber Co🎅
# Assets:MyAccount $50
# income:unknown $-50
@@ -150,15 +128,13 @@
# Assets:MyAccount $-50
# expenses:unknown $50
#
# >>>2
# >>>=0
# >=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.$$
# <<<
# . reading TSV (tab-separated) TODO user error (CSV record ["10/2009/09\tFlubber Co\127877\t50\t"] has less than two fields)
# <
# 10/2009/09 Flubber Co🎅 50
# 11/2009/09 Flubber Co🎅 50
# >>>
# $ 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.$$
# 2009/09/10 Flubber Co🎅
# Assets:MyAccount $50
# income:unknown $-50
@@ -167,5 +143,4 @@
# Assets:MyAccount $-50
# expenses:unknown $50
#
# >>>2
# >>>=0
# >=0

0 comments on commit abf455c

Please sign in to comment.
You can’t perform that action at this time.