Tests and refactoring for format_output_line