parser: add tests and fix bugs