MCPcopy
hub / github.com/danielgtaylor/huma / TestConvertError

Function TestConvertError

yaml/yaml_test.go:343–381  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

341}
342
343func TestConvertError(t *testing.T) {
344 testCases := []struct {
345 name string
346 src string
347 err string
348 }{
349 {
350 name: "null",
351 src: "null",
352 err: fmt.Sprint(len("null\n")),
353 },
354 {
355 name: "large object key",
356 src: `{"` + strings.Repeat("test", 1200) + `":0}`,
357 err: fmt.Sprint(len("test") * 1200),
358 },
359 {
360 name: "large object value",
361 src: `{"x":"` + strings.Repeat("test", 1200) + `"}`,
362 err: fmt.Sprint(len("x: ") + len("test")*1200),
363 },
364 {
365 name: "large array",
366 src: "[" + strings.Repeat(`"test",`, 1000) + `"test"]`,
367 err: fmt.Sprint(len("- test\n")*(4*1024/len("- test\n")+1) - 1),
368 },
369 }
370 for _, tc := range testCases {
371 t.Run(tc.name, func(t *testing.T) {
372 err := json2yaml.Convert(errWriter{}, strings.NewReader(tc.src))
373 if err == nil {
374 t.Fatalf("should raise an error %q but got no error", tc.err)
375 }
376 if err.Error() != tc.err {
377 t.Fatalf("should raise an error %q but got error %q", tc.err, err)
378 }
379 })
380 }
381}
382
383func join(xs []string) string {
384 var sb strings.Builder

Callers

nothing calls this directly

Calls 2

RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…