printer: Add unit test of Format() producing unparsable output.
This commit is contained in:
parent
b1738d9053
commit
a81aa7b5dd
@ -147,3 +147,25 @@ func lineAt(text []byte, offs int) []byte {
|
|||||||
}
|
}
|
||||||
return text[offs:i]
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user