hledger/tests/journal/dates.test
Simon Michael 856c0b3042 lib: fix bracketed posting dates, parser cleanup (#304)
Bracketed posting dates were fragile; they worked only if you wrote full
10-character dates. Also some semantics were a bit unclear. Now they
should be robust, and have been documented more clearly. This is a
legacy undocumented Ledger syntax, but it improves compatibility and
might be preferable to the more verbose "date:" tags if you write
posting dates often (as I do).

Internally, bracketed posting dates are no longer considered to be tags.
Journal comment, tag, and posting date parsers have been reworked, all
with doctests. Also the journal parser types generally have been
tightened up and clarified, making it much easier to know how to combine
and run them. There's now

-- | A parser of strings with generic user state, monad and return type.
type StringParser u m a = ParsecT String u m a

-- | A string parser with journal-parsing state.
type JournalParser m a = StringParser JournalContext m a

-- | A journal parser that runs in IO and can throw an error mid-parse.
type ErroringJournalParser a = JournalParser (ExceptT String IO) a

and corresponding convenience functions (and short aliases) for running them.
2016-04-28 13:34:57 -07:00

45 lines
621 B
Plaintext

# invalid dates should be rejected
# 1. valid month and day, but flipped
hledger -f- print
<<<
2010/31/12 x
a 1
b
>>>2 /bad date/
>>>= 1
# 2. too-large day
hledger -f- print
<<<
2010/12/32 x
a 1
b
>>>2 /bad date/
>>>= 1
# 3. 29th feb on leap year should be ok
hledger -f- print
<<<
2000/2/29 x
a 1
b
>>>
2000/02/29 x
a 1
b -1
>>>= 0
# 4. 29th feb on non-leap year should fail
hledger -f- print
<<<
2001/2/29 x
a 1
b
>>>2 /bad date/
>>>= 1
# 5. dates must be followed by whitespace or newline
hledger -f- print
<<<
2015/9/6*
a 0
>>>2 /unexpected "*"/
>>>= 1