TestTranslateYAMLError tests that cryptic goccy/go-yaml parser messages are translated to user-friendly descriptions, and that source context lines are left untouched.
(t *testing.T)
| 161 | // TestTranslateYAMLError tests that cryptic goccy/go-yaml parser messages are translated |
| 162 | // to user-friendly descriptions, and that source context lines are left untouched. |
| 163 | func TestTranslateYAMLError(t *testing.T) { |
| 164 | tests := []struct { |
| 165 | name string |
| 166 | input string |
| 167 | contains string // expected substring in translated output |
| 168 | excludes string // must NOT appear in the first (header) line |
| 169 | sourceContextCheck string // if non-empty, must appear in the source context (after first line) |
| 170 | }{ |
| 171 | { |
| 172 | name: "unexpected key name translated", |
| 173 | input: "[1:1] unexpected key name\n> 1 | engine claude\n ^", |
| 174 | contains: "missing ':' after key", |
| 175 | excludes: "unexpected key name", |
| 176 | }, |
| 177 | { |
| 178 | name: "mapping value not allowed translated", |
| 179 | input: "[1:6] mapping value is not allowed in this context\n> 1 | key: value: extra\n ^", |
| 180 | contains: "unexpected ':'", |
| 181 | excludes: "mapping value is not allowed in this context", |
| 182 | }, |
| 183 | { |
| 184 | name: "mapping value not found translated", |
| 185 | input: "[3:1] yaml: mapping value not found\n> 3 | engine copiilot\n ^", |
| 186 | contains: "missing ':' after key", |
| 187 | excludes: "mapping value not found", |
| 188 | }, |
| 189 | { |
| 190 | name: "string used where mapping expected translated", |
| 191 | input: "[1:1] string was used where mapping is expected\n> 1 | name value\n ^", |
| 192 | contains: "expected a YAML mapping", |
| 193 | excludes: "string was used where mapping is expected", |
| 194 | }, |
| 195 | { |
| 196 | name: "tab character error translated", |
| 197 | input: "[1:7] tab character cannot use as a map key directly\n> 1 | \tengine: claude\n ^", |
| 198 | contains: "tab character in key", |
| 199 | excludes: "tab character cannot use as a map key directly", |
| 200 | }, |
| 201 | { |
| 202 | name: "unrecognized messages are returned unchanged", |
| 203 | input: "[2:1] mapping key \"name\" already defined at [1:1]\n> 2 | name: dup\n ^", |
| 204 | contains: "already defined", |
| 205 | }, |
| 206 | { |
| 207 | name: "empty string is returned unchanged", |
| 208 | input: "", |
| 209 | contains: "", |
| 210 | }, |
| 211 | { |
| 212 | name: "pattern in source context line is not replaced", |
| 213 | input: "[1:1] unexpected key name\n> 1 | unexpected key name: here\n ^", |
| 214 | // The header should be translated, but source context must remain untouched. |
| 215 | contains: "missing ':' after key", |
| 216 | sourceContextCheck: "unexpected key name: here", |
| 217 | }, |
| 218 | } |
| 219 | |
| 220 | for _, tt := range tests { |
nothing calls this directly
no test coverage detected