diff --git a/tests/test_hook_ledger_entry.py b/tests/test_hook_ledger_entry.py index e2883324181f15b5468f79141bc6b8842daf7343..4b07ae8ece0f7da9e653de468933159017e66691 100644 --- a/tests/test_hook_ledger_entry.py +++ b/tests/test_hook_ledger_entry.py @@ -92,6 +92,38 @@ def test_complex_template(): " ;Entity: T-T", ] +def test_variable_whitespace_cleaned(): + # There are two critical parts of this to avoid making malformed Ledger + # entries: + # * Ensure newlines become non-newline whitespace so we don't write + # malformed lines. + # * Collapse multiple spaces into one so variables in account names + # can't make malformed account lines by having a premature split + # between the account name and amount. + render_vars = template_vars('W\t\tS', '125.50', other_vars={ + 'entity': 'W\fS', + 'program': 'Spectrum\r\nDefense', + 'txid': 'ABC\v\tDEF', + }) + lines = render_lines( + render_vars, 'Complex', + date_fmt='%Y-%m-%d', + signed_currencies=['USD'], + ) + assert lines == [ + "", + "2015-03-14 W S", + " ;Tag: Value", + " ;TransactionID: ABC DEF", + " Accrued:Accounts Receivable $125.50", + " ;Entity: Supplier", + " Income:Donations:Spectrum Defense $-119.85", + " ;Program: Spectrum Defense", + " ;Entity: W S", + " Income:Donations:General $-5.65", + " ;Entity: W S", + ] + def test_balancing(): lines = render_lines(template_vars('FF', '1.01'), 'FiftyFifty') assert lines == [