Fix trailing newline handling and typo on test code.