printer: Add unit test of Format() producing unparsable output.

This commit is contained in:
Florian Forster 2018-03-20 12:09:03 +01:00 committed by Florian Forster
parent b1738d9053
commit a81aa7b5dd

View File

@ -147,3 +147,25 @@ func lineAt(text []byte, offs int) []byte {
}
return text[offs:i]
}
// TestFormatParsable ensures that the output of Format() is can be parsed again.
func TestFormatValidOutput(t *testing.T) {
cases := []string{
"#\x00",
"#\ue123t",
}
for _, c := range cases {
f, err := Format([]byte(c))
if err != nil {
// ignore these failures, not all inputs are valid HCL.
t.Logf("Format(%q) = %v", c, err)
continue
}
if _, err := parser.Parse(f); err != nil {
t.Errorf("Format(%q) = %q; Parse(%q) = %v", c, f, f, err)
continue
}
}
}