MCPcopy Create free account
hub / github.com/github/gh-aw / TestFormatYAMLErrorTranslation

Function TestFormatYAMLErrorTranslation

pkg/parser/yaml_error_test.go:305–349  ·  view source on GitHub ↗

TestFormatYAMLErrorTranslation verifies that FormatYAMLError applies translations to the underlying goccy/go-yaml error messages.

(t *testing.T)

Source from the content-addressed store, hash-verified

303// TestFormatYAMLErrorTranslation verifies that FormatYAMLError applies translations
304// to the underlying goccy/go-yaml error messages.
305func TestFormatYAMLErrorTranslation(t *testing.T) {
306 tests := []struct {
307 name string
308 yamlContent string
309 shouldContain string
310 shouldExclude string
311 }{
312 {
313 name: "missing colon translated",
314 yamlContent: "engine claude\nmodel: gpt-4",
315 shouldContain: "missing ':' after key",
316 shouldExclude: "unexpected key name",
317 },
318 {
319 name: "extra colon translated",
320 yamlContent: "key: value: extra",
321 shouldContain: "unexpected ':'",
322 shouldExclude: "mapping value is not allowed in this context",
323 },
324 {
325 name: "plain string translated",
326 yamlContent: "not a mapping",
327 shouldContain: "expected a YAML mapping",
328 shouldExclude: "string was used where mapping is expected",
329 },
330 }
331
332 for _, tt := range tests {
333 t.Run(tt.name, func(t *testing.T) {
334 var result map[string]any
335 err := yaml.Unmarshal([]byte(tt.yamlContent), &result)
336 if err == nil {
337 t.Skipf("Expected YAML parsing to fail for content: %q", tt.yamlContent)
338 return
339 }
340 formatted := FormatYAMLError(err, 1, tt.yamlContent)
341 assert.Contains(t, formatted, tt.shouldContain,
342 "FormatYAMLError should contain %q\nResult: %s", tt.shouldContain, formatted)
343 if tt.shouldExclude != "" {
344 assert.NotContains(t, formatted, tt.shouldExclude,
345 "FormatYAMLError should not contain %q\nResult: %s", tt.shouldExclude, formatted)
346 }
347 })
348 }
349}

Callers

nothing calls this directly

Calls 2

FormatYAMLErrorFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected