147 lines
		
	
	
		
			6.2 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			147 lines
		
	
	
		
			6.2 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
 | |
| 
 | |
| >=0
 | |
| 
 | |
| # 2. reading CSV with in-field and out-field
 | |
| <
 | |
| 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
 | |
| 
 | |
| 2009/09/11 Flubber Co🎅
 | |
|     Assets:MyAccount            $-50
 | |
|     expenses:unknown             $50
 | |
| 
 | |
| >=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
 | |
| 
 | |
| >=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
 | |
| 
 | |
| >=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
 | |
| 
 | |
| >=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
 | |
| 
 | |
| >=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
 | |
| 
 | |
| >=0
 | |
| 
 | |
| # 8. reading with custom separator: SSV (semicolon-separated)
 | |
| <
 | |
| 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
 | |
| 
 | |
| 2009/09/11 Flubber Co🎅
 | |
|     Assets:MyAccount            $-50
 | |
|     expenses:unknown             $50
 | |
| 
 | |
| >=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
 | |
| 2009/09/10 Flubber Co
 | |
|     assets:myacct              $50
 | |
|     income:unknown            $-50 = $123
 | |
| 
 | |
| >=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
 | |
| 
 | |
| >=0
 | |
| 
 | |
| 
 | |
| # . TODO: without --separator gives obscure error
 | |
| #   |
 | |
| # 1 | 10/2009/09;Flubber Co🎅;50;
 | |
| #   | ^^^^^^^^^^
 | |
| # well-formed but invalid date: 10/2009/9
 | |
| # <
 | |
| # 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
 | |
| #
 | |
| # 2009/09/11 Flubber Co🎅
 | |
| #     Assets:MyAccount            $-50
 | |
| #     expenses:unknown             $50
 | |
| #
 | |
| # >=0
 | |
| 
 | |
| # . 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
 | |
| #
 | |
| # 2009/09/11 Flubber Co🎅
 | |
| #     Assets:MyAccount            $-50
 | |
| #     expenses:unknown             $50
 | |
| #
 | |
| # >=0
 |