Functional Weave
Code in TypeScript

finance.ledger.journal-validate@1.0.0

vectors.json

10,391 bytes · view raw

[
  {"name": "a balanced sale: debtor against sales and VAT", "args": [[{"account": "1200", "debit": {"minor": 12000, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 10000, "currency": "GBP"}}, {"account": "2200", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 2000, "currency": "GBP"}}], "GBP"], "expect": {"valid": true, "debitTotal": {"minor": 12000, "currency": "GBP"}, "creditTotal": {"minor": 12000, "currency": "GBP"}, "difference": {"minor": 0, "currency": "GBP"}, "problems": []}},
  {"name": "a penny out is unbalanced, and the difference says by how much", "args": [[{"account": "1200", "debit": {"minor": 10000, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 9999, "currency": "GBP"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 10000, "currency": "GBP"}, "creditTotal": {"minor": 9999, "currency": "GBP"}, "difference": {"minor": 1, "currency": "GBP"}, "problems": [{"line": null, "code": "unbalanced", "message": "debits do not equal credits"}]}},
  {"name": "credits exceeding debits give a negative difference", "args": [[{"account": "1200", "debit": {"minor": 9000, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 10000, "currency": "GBP"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 9000, "currency": "GBP"}, "creditTotal": {"minor": 10000, "currency": "GBP"}, "difference": {"minor": -1000, "currency": "GBP"}, "problems": [{"line": null, "code": "unbalanced", "message": "debits do not equal credits"}]}},
  {"name": "an empty journal is not valid", "args": [[], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 0, "currency": "GBP"}, "creditTotal": {"minor": 0, "currency": "GBP"}, "difference": {"minor": 0, "currency": "GBP"}, "problems": [{"line": null, "code": "empty", "message": "the journal has no lines"}]}},
  {"name": "a single line cannot balance", "args": [[{"account": "7000", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 100, "currency": "GBP"}, "creditTotal": {"minor": 0, "currency": "GBP"}, "difference": {"minor": 100, "currency": "GBP"}, "problems": [{"line": null, "code": "unbalanced", "message": "debits do not equal credits"}]}},
  {"name": "a zero line is reported even when the journal balances", "args": [[{"account": "1200", "debit": {"minor": 500, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 500, "currency": "GBP"}}, {"account": "5000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 500, "currency": "GBP"}, "creditTotal": {"minor": 500, "currency": "GBP"}, "difference": {"minor": 0, "currency": "GBP"}, "problems": [{"line": 3, "code": "zero-line", "message": "line 3: debit and credit are both zero"}]}},
  {"name": "a line with both a debit and a credit is reported, and counted", "args": [[{"account": "1200", "debit": {"minor": 500, "currency": "GBP"}, "credit": {"minor": 500, "currency": "GBP"}}, {"account": "6000", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 100, "currency": "GBP"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 600, "currency": "GBP"}, "creditTotal": {"minor": 600, "currency": "GBP"}, "difference": {"minor": 0, "currency": "GBP"}, "problems": [{"line": 1, "code": "both-sides", "message": "line 1: has both a debit and a credit"}]}},
  {"name": "a negative debit is reported and left out of the totals", "args": [[{"account": "1200", "debit": {"minor": 1000, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 1000, "currency": "GBP"}}, {"account": "5000", "debit": {"minor": -500, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 1000, "currency": "GBP"}, "creditTotal": {"minor": 1000, "currency": "GBP"}, "difference": {"minor": 0, "currency": "GBP"}, "problems": [{"line": 3, "code": "negative-amount", "message": "line 3: debit and credit must not be negative"}]}},
  {"name": "a line in another currency is reported and left out, which unbalances the rest", "args": [[{"account": "1200", "debit": {"minor": 1000, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "EUR"}, "credit": {"minor": 1000, "currency": "EUR"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 1000, "currency": "GBP"}, "creditTotal": {"minor": 0, "currency": "GBP"}, "difference": {"minor": 1000, "currency": "GBP"}, "problems": [{"line": 2, "code": "currency-mismatch", "message": "line 2: amount is in EUR, not the journal currency GBP"}, {"line": null, "code": "unbalanced", "message": "debits do not equal credits"}]}},
  {"name": "the credit side's currency is checked too", "args": [[{"account": "1200", "debit": {"minor": 1000, "currency": "GBP"}, "credit": {"minor": 0, "currency": "USD"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 1000, "currency": "GBP"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 0, "currency": "GBP"}, "creditTotal": {"minor": 1000, "currency": "GBP"}, "difference": {"minor": -1000, "currency": "GBP"}, "problems": [{"line": 1, "code": "currency-mismatch", "message": "line 1: amount is in USD, not the journal currency GBP"}, {"line": null, "code": "unbalanced", "message": "debits do not equal credits"}]}},
  {"name": "well-formed account codes: groups joined by - . or /", "args": [[{"account": "1200-01", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "SALES.UK", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "6100/2", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "a1", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 300, "currency": "GBP"}}], "GBP"], "expect": {"valid": true, "debitTotal": {"minor": 300, "currency": "GBP"}, "creditTotal": {"minor": 300, "currency": "GBP"}, "difference": {"minor": 0, "currency": "GBP"}, "problems": []}},
  {"name": "malformed account codes are each reported but still counted", "args": [[{"account": "4 000", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "-4000", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000-", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "40--00", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "123456789012345678901", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 600, "currency": "GBP"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 600, "currency": "GBP"}, "creditTotal": {"minor": 600, "currency": "GBP"}, "difference": {"minor": 0, "currency": "GBP"}, "problems": [{"line": 1, "code": "invalid-account", "message": "line 1: account \"4 000\" is not a valid account code"}, {"line": 2, "code": "invalid-account", "message": "line 2: account \"\" is not a valid account code"}, {"line": 3, "code": "invalid-account", "message": "line 3: account \"-4000\" is not a valid account code"}, {"line": 4, "code": "invalid-account", "message": "line 4: account \"4000-\" is not a valid account code"}, {"line": 5, "code": "invalid-account", "message": "line 5: account \"40--00\" is not a valid account code"}, {"line": 6, "code": "invalid-account", "message": "line 6: account \"123456789012345678901\" is not a valid account code"}]}},
  {"name": "a twenty-character code is the longest allowed", "args": [[{"account": "12345678901234567890", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 100, "currency": "GBP"}}], "GBP"], "expect": {"valid": true, "debitTotal": {"minor": 100, "currency": "GBP"}, "creditTotal": {"minor": 100, "currency": "GBP"}, "difference": {"minor": 0, "currency": "GBP"}, "problems": []}},
  {"name": "one line can have two problems", "args": [[{"account": "40 00", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "1200", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}, {"account": "4000", "debit": {"minor": 0, "currency": "GBP"}, "credit": {"minor": 100, "currency": "GBP"}}], "GBP"], "expect": {"valid": false, "debitTotal": {"minor": 100, "currency": "GBP"}, "creditTotal": {"minor": 100, "currency": "GBP"}, "difference": {"minor": 0, "currency": "GBP"}, "problems": [{"line": 1, "code": "invalid-account", "message": "line 1: account \"40 00\" is not a valid account code"}, {"line": 1, "code": "zero-line", "message": "line 1: debit and credit are both zero"}]}},
  {"name": "a yen journal", "args": [[{"account": "1200", "debit": {"minor": 150000, "currency": "JPY"}, "credit": {"minor": 0, "currency": "JPY"}}, {"account": "4000", "debit": {"minor": 0, "currency": "JPY"}, "credit": {"minor": 150000, "currency": "JPY"}}], "JPY"], "expect": {"valid": true, "debitTotal": {"minor": 150000, "currency": "JPY"}, "creditTotal": {"minor": 150000, "currency": "JPY"}, "difference": {"minor": 0, "currency": "JPY"}, "problems": []}},
  {"name": "the journal currency must be an ISO code", "args": [[{"account": "1200", "debit": {"minor": 100, "currency": "GBP"}, "credit": {"minor": 0, "currency": "GBP"}}], "gbp"], "expectError": "ISO 4217"}
]