Fix #404 with to_s

Before trying to check for a trailing newline, and add a test