Join GitHub today
lib: fix parsing of amounts with a whitespace digits separator #780
This PR addresses a problem which was found in issue #749. This PR does not address that issue.
The problem was that we fail to parse the following journal
failing with the following error
We fail to parse this next journal as well
It seems that the issue is caused by the use of a space as the digits separator and trailing whitespace after the amount. The current parser consumes the trailing whitespace as a separator and then expects at least another digit, which it does not find. This patch groups together the separator and the following digit group. With this patch, the above two journals parse successfully.
referenced this pull request
May 20, 2018
Thanks for the suggestions, I'll try to keep doctests in mind when making fixes. Testing is something that I'm looking to get more experience with.
Also, I'm not familliar with how our tests are organized. Are our doctests intended for developers or users, or both? If they are for users of the API, I feel like we should put this test in a functest rather than a doctest, since it tests against an improper implementation of
May 20, 2018
1 check passed
In general, use whichever kind of test works best for you, we don't have a firm policy. But it's a good point about doctests being part of the API documentation. hunit tests run fastest but are a chore to write, shell tests run pretty fast and are easy to write and understand, doctests are easy to write and provide useful documentation but alas run extremely slowly. Please feel free to add notes to https://github.com/simonmichael/hledger/wiki/Tests.
@awjchen , doctests are simple unit-tests for developers that helps to catch errors that propagates further. Especially useful for parsers. They also help to understand some corner cases of API.
In this particular case issue were isolated because of extra check