|
| 1 | +package format_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/aws-cloudformation/rain/cft/format" |
| 7 | + "github.com/aws-cloudformation/rain/cft/parse" |
| 8 | +) |
| 9 | + |
| 10 | +func TestCRLFComments(t *testing.T) { |
| 11 | + // Issue #479: Windows CRLF line endings cause extra blank lines between comments |
| 12 | + // Build input with CRLF line endings |
| 13 | + input := "AWSTemplateFormatVersion: 2010-09-09\r\n" + |
| 14 | + "\r\n" + |
| 15 | + "# Comment line 1\r\n" + |
| 16 | + "# Comment line 2\r\n" + |
| 17 | + "# Comment line 3\r\n" + |
| 18 | + "\r\n" + |
| 19 | + "Description: Hello World\r\n" |
| 20 | + |
| 21 | + // Same input with LF line endings for comparison |
| 22 | + inputLF := "AWSTemplateFormatVersion: 2010-09-09\n" + |
| 23 | + "\n" + |
| 24 | + "# Comment line 1\n" + |
| 25 | + "# Comment line 2\n" + |
| 26 | + "# Comment line 3\n" + |
| 27 | + "\n" + |
| 28 | + "Description: Hello World\n" |
| 29 | + |
| 30 | + tmplCRLF, err := parse.String(input) |
| 31 | + if err != nil { |
| 32 | + t.Fatalf("Failed to parse CRLF input: %v", err) |
| 33 | + } |
| 34 | + |
| 35 | + tmplLF, err := parse.String(inputLF) |
| 36 | + if err != nil { |
| 37 | + t.Fatalf("Failed to parse LF input: %v", err) |
| 38 | + } |
| 39 | + |
| 40 | + outputCRLF := format.String(tmplCRLF, format.Options{}) |
| 41 | + outputLF := format.String(tmplLF, format.Options{}) |
| 42 | + |
| 43 | + t.Logf("CRLF output:\n---\n%s\n---", outputCRLF) |
| 44 | + t.Logf("LF output:\n---\n%s\n---", outputLF) |
| 45 | + |
| 46 | + if outputCRLF != outputLF { |
| 47 | + t.Errorf("CRLF and LF outputs differ.\nCRLF output:\n%s\nLF output:\n%s", outputCRLF, outputLF) |
| 48 | + } |
| 49 | +} |
0 commit comments