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

Function TestFormatYAMLErrorAdjustment

pkg/parser/yaml_error_test.go:100–159  ·  view source on GitHub ↗

TestFormatYAMLErrorAdjustment specifically tests line number adjustment

(t *testing.T)

Source from the content-addressed store, hash-verified

98
99// TestFormatYAMLErrorAdjustment specifically tests line number adjustment
100func TestFormatYAMLErrorAdjustment(t *testing.T) {
101 yamlContent := "name: test\nname: duplicate"
102
103 tests := []struct {
104 offset int
105 expectedFirstLine string
106 expectedSecondLine string
107 expectedDefinedAt string
108 }{
109 {
110 offset: 1,
111 expectedFirstLine: " 1 |",
112 expectedSecondLine: "> 2 |",
113 expectedDefinedAt: "already defined at [1:1]",
114 },
115 {
116 offset: 5,
117 expectedFirstLine: " 5 |",
118 expectedSecondLine: "> 6 |",
119 expectedDefinedAt: "already defined at [5:1]",
120 },
121 {
122 offset: 10,
123 expectedFirstLine: " 10 |",
124 expectedSecondLine: "> 11 |",
125 expectedDefinedAt: "already defined at [10:1]",
126 },
127 }
128
129 for _, tt := range tests {
130 t.Run(fmt.Sprintf("offset_%d", tt.offset), func(t *testing.T) {
131 var result map[string]any
132 err := yaml.Unmarshal([]byte(yamlContent), &result)
133
134 if err == nil {
135 t.Errorf("Expected YAML parsing to fail")
136 return
137 }
138
139 formatted := FormatYAMLError(err, tt.offset, yamlContent)
140
141 // Check first line number
142 if !strings.Contains(formatted, tt.expectedFirstLine) {
143 t.Errorf("Expected first line number format '%s', got:\n%s", tt.expectedFirstLine, formatted)
144 }
145
146 // Check second line number
147 if !strings.Contains(formatted, tt.expectedSecondLine) {
148 t.Errorf("Expected second line number format '%s', got:\n%s", tt.expectedSecondLine, formatted)
149 }
150
151 // Check "already defined at" reference
152 if !strings.Contains(formatted, tt.expectedDefinedAt) {
153 t.Errorf("Expected 'already defined at' reference '%s', got:\n%s", tt.expectedDefinedAt, formatted)
154 }
155
156 t.Logf("Formatted error (offset %d):\n%s", tt.offset, formatted)
157 })

Callers

nothing calls this directly

Calls 3

FormatYAMLErrorFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected