tests: minor edits for conciseness
Fix handling of EOF whitespace.

New behavior:
1. If file ends with no whitespace, it appends a single newline at the end of file.
2. If file ends with whitespace, it replaces all trailing whitespace with a single newline.

Closes #353.