Add lots more parsing tests, with corresponding fixes and refactoring.