From 9d33342ff3225ddd9da86d918719a7f2163a433f Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 10 Jun 2018 07:35:57 -0700 Subject: [PATCH] lib: start some parse error tests (#804) [ci skip] --- tests/journal/parse-errors.test | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/journal/parse-errors.test diff --git a/tests/journal/parse-errors.test b/tests/journal/parse-errors.test new file mode 100644 index 000000000..fce928f81 --- /dev/null +++ b/tests/journal/parse-errors.test @@ -0,0 +1,42 @@ +# Testing parse error messages for accuracy and usefulness. + +# 1. A journal with an incomplete date. +< +2018 + +$ hledger -f - print +>2 +hledger: -:1:5: +unexpected newline +expecting date separator or the rest of year or month + +>=1 + +# 2. A journal with an unbalanced transaction. +# When read from stdin, this example actually passes because hledger tries all readers +# and the timedot reader parses it (and shows two decimal places). +< +2018/1/1 + a 1 + +$ hledger -f - bal -N +> + 1.00 a + +# 3. If we force journal format, we get the expected error. +$ hledger -f journal:- bal -N +>2 /hledger: could not balance this transaction \(real postings are off by 1\)/ +>=1 + +# 4. A posting without two spaces between account and amount (forcing journal format). +< +2018/1/1 + (a) 1 + +# hledger doesn't detect this as an error directly, it parses account name "(a) 1" here. +$ hledger -f journal:- print -x +2018/01/01 + (a) 1 0 + +>= +