hledger/tests/csv/read.test
Simon Michael 21d9945ba9 tests: make functional tests use "hledger" again
Using "hledgerdev" was a hack to help ensure that tests used a fresh
developer build by default. Now they specify "hledger" again, which fits
better with stack. It's up to the tester to make sure the desired
executable is first in PATH or specified with -w. (Note a couple of
tests currently don't obey -w and will always run "hledger", see addons.test).
2015-07-12 12:29:53 -07:00

47 lines
1.8 KiB
Plaintext

# 1. read CSV to hledger journal format
rm -rf t.rules$$; printf 'fields date, description, amount\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\n' >t.rules$$; echo '10/2009/09,Flubber Co,50' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$
>>>
2009/09/10 Flubber Co
income:unknown $-50
assets:myacct $50
>>>2 /using conversion rules file.*t.rules/
>>>=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' >$$.rules ; hledger -f- print --rules-file $$.rules; rm -rf $$.rules
<<<
10/2009/09,Flubber Co,50,
11/2009/09,Flubber Co,,50
>>>
2009/09/10 Flubber Co
income:unknown $-50
Assets:MyAccount $50
2009/09/11 Flubber Co
expenses:unknown $50
Assets:MyAccount $-50
>>>2 /using conversion rules file.*[0-9]+\.rules/
>>>=0
# 3. report rules parse error
# rm -rf t.rules$$; printf 'date-fiel 0\ndate-format %%d/%%Y/%%m\ndescription-field 1\namount-field 2\ncurrency $\nbase-account assets:myacct\n' >t.rules$$; echo '10/2009/09,Flubber Co,50' | hledger convert --rules-file t.rules$$; rm -rf t.rules$$
# >>>
# 2009/09/10 Flubber Co
# income:unknown $-50
# assets:myacct $50
# >>>2 /using conversion rules file.*t.rules/
# >>>=0
# 4. handle conditions assigning multiple fields
rm -rf t.rules$$; printf 'fields date, description, amount\ndate-format %%d/%%Y/%%m\ncurrency $\naccount1 assets:myacct\nif Flubber\n account2 acct\n comment cmt' >t.rules$$; echo '10/2009/09,Flubber Co,50' | hledger -f- print --rules-file t.rules$$; rm -rf t.rules$$
>>>
2009/09/10 Flubber Co ; cmt
acct $-50
assets:myacct $50
>>>2 /using conversion rules file.*t.rules/
>>>=0