Fix JSON Unicode decoding and YAML float validation

This commit is contained in:
2026-11-28 23:25:12 +00:00
parent 9cc9f6f777
commit 9f7744bda8
4 changed files with 128 additions and 4 deletions

View File

@@ -46,3 +46,31 @@ func TestJSONSyntax(t *testing.T) {
t.Fatalf("expected JSON syntax failure, got %q", &stderr)
}
}
func TestDocumentDecoding(t *testing.T) {
for _, test := range []struct {
file string
body string
code int
}{
{"escaped.json", `{"schema_version":"maximumdirect.campaign.v1","id":"weather","name":"Weather \ud83c\udf27"}`, 0},
{"malformed-float.yml", "schema_version: maximumdirect.campaign.v1\nid: weather\nreading: !!float e3\n", 1},
} {
t.Run(test.file, func(t *testing.T) {
file := filepath.Join(t.TempDir(), test.file)
if err := os.WriteFile(file, []byte(test.body), 0600); err != nil {
t.Fatal(err)
}
var stdout, stderr bytes.Buffer
if code := run([]string{"-root", "../..", file}, &stdout, &stderr); code != test.code {
t.Fatalf("want exit %d, got %d: stdout=%q stderr=%q", test.code, code, &stdout, &stderr)
}
if test.code == 0 && !strings.Contains(stdout.String(), "valid (maximumdirect.campaign.v1)") {
t.Fatalf("missing success report: %q", &stdout)
}
if test.code != 0 && !strings.Contains(stderr.String(), "decode:") {
t.Fatalf("missing decoding failure: %q", &stderr)
}
})
}
}