Debian Codegraph @

decode_test.go

raw symbols SCIP
1 package yaml_testscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/"
5 "contextscip-go gomod github.com/golang/go/src go1.21.0 context/"
6 "fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/"
7 "ioscip-go gomod github.com/golang/go/src go1.21.0 io/"
8 "logscip-go gomod github.com/golang/go/src go1.21.0 log/"
9 "mathscip-go gomod github.com/golang/go/src go1.21.0 math/"
10 "netscip-go gomod github.com/golang/go/src go1.21.0 net/"
11 "reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/"
12 "strconvscip-go gomod github.com/golang/go/src go1.21.0 strconv/"
13 "stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/"
14 "testingscip-go gomod github.com/golang/go/src go1.21.0 testing/"
15 "timescip-go gomod github.com/golang/go/src go1.21.0 time/"
16
17 "github.com/goccy/go-yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/"
18 "github.com/goccy/go-yaml/astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/"
19 "github.com/goccy/go-yaml/internal/errorsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/"
20 "github.com/goccy/go-yaml/parserscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/parser`/"
21 )
22
23 type Childscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child# struct {
24 Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#B. int
25 Cscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#C. int `yaml:"-"`
26 }
27
28 type TestStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestString# string
29
30 func TestDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
31 tests := []struct {
32 source string
33 value interface{}
34 eof bool
35 }{
36 {
37 source: "v: hi\n",
38 value: map[string]string{"v": "hi"},
39 },
40 {
41 source: "v: hi\n",
42 value: map[string]TestStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestString#{"v": "hi"},
43 },
44 {
45 source: "v: \"true\"\n",
46 value: map[string]string{"v": "true"},
47 },
48 {
49 source: "v: \"false\"\n",
50 value: map[string]string{"v": "false"},
51 },
52 {
53 source: "v: true\n",
54 value: map[string]interface{}{"v": true},
55 },
56 {
57 source: "v: true\n",
58 value: map[string]string{"v": "true"},
59 },
60 {
61 source: "v: 10\n",
62 value: map[string]string{"v": "10"},
63 },
64 {
65 source: "v: 10\n",
66 value: map[string]TestStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestString#{"v": "10"},
67 },
68 {
69 source: "v: -10\n",
70 value: map[string]string{"v": "-10"},
71 },
72 {
73 source: "v: 1.234\n",
74 value: map[string]string{"v": "1.234"},
75 },
76 {
77 source: "v: \" foo\"\n",
78 value: map[string]string{"v": " foo"},
79 },
80 {
81 source: "v: \"foo \"\n",
82 value: map[string]string{"v": "foo "},
83 },
84 {
85 source: "v: \" foo \"\n",
86 value: map[string]string{"v": " foo "},
87 },
88 {
89 source: "v: false\n",
90 value: map[string]bool{"v": false},
91 },
92 {
93 source: "v: 10\n",
94 value: map[string]int{"v": 10},
95 },
96 {
97 source: "v: 10",
98 value: map[string]interface{}{"v": 10},
99 },
100 {
101 source: "v: 0b10",
102 value: map[string]interface{}{"v": 2},
103 },
104 {
105 source: "v: -0b101010",
106 value: map[string]interface{}{"v": -42},
107 },
108 {
109 source: "v: -0b1000000000000000000000000000000000000000000000000000000000000000",
110 value: map[string]interface{}{"v": int64(-9223372036854775808)},
111 },
112 {
113 source: "v: 0xA",
114 value: map[string]interface{}{"v": 10},
115 },
116 {
117 source: "v: .1",
118 value: map[string]interface{}{"v": 0.1},
119 },
120 {
121 source: "v: -.1",
122 value: map[string]interface{}{"v": -0.1},
123 },
124 {
125 source: "v: -10\n",
126 value: map[string]int{"v": -10},
127 },
128 {
129 source: "v: 4294967296\n",
130 value: map[string]int64{"v": int64(4294967296)},
131 },
132 {
133 source: "v: 0.1\n",
134 value: map[string]interface{}{"v": 0.1},
135 },
136 {
137 source: "v: 0.99\n",
138 value: map[string]float32{"v": 0.99},
139 },
140 {
141 source: "v: -0.1\n",
142 value: map[string]float64{"v": -0.1},
143 },
144 {
145 source: "v: 6.8523e+5",
146 value: map[string]interface{}{"v": 6.8523e+5},
147 },
148 {
149 source: "v: 685.230_15e+03",
150 value: map[string]interface{}{"v": 685.23015e+03},
151 },
152 {
153 source: "v: 685_230.15",
154 value: map[string]interface{}{"v": 685230.15},
155 },
156 {
157 source: "v: 685_230.15",
158 value: map[string]float64{"v": 685230.15},
159 },
160 {
161 source: "v: 685230",
162 value: map[string]interface{}{"v": 685230},
163 },
164 {
165 source: "v: +685_230",
166 value: map[string]interface{}{"v": 685230},
167 },
168 {
169 source: "v: 02472256",
170 value: map[string]interface{}{"v": 685230},
171 },
172 {
173 source: "v: 0x_0A_74_AE",
174 value: map[string]interface{}{"v": 685230},
175 },
176 {
177 source: "v: 0b1010_0111_0100_1010_1110",
178 value: map[string]interface{}{"v": 685230},
179 },
180 {
181 source: "v: +685_230",
182 value: map[string]int{"v": 685230},
183 },
184
185 // Bools from spec
186 {
187 source: "v: True",
188 value: map[string]interface{}{"v": true},
189 },
190 {
191 source: "v: TRUE",
192 value: map[string]interface{}{"v": true},
193 },
194 {
195 source: "v: False",
196 value: map[string]interface{}{"v": false},
197 },
198 {
199 source: "v: FALSE",
200 value: map[string]interface{}{"v": false},
201 },
202 {
203 source: "v: y",
204 value: map[string]interface{}{"v": "y"}, // y or yes or Yes is string
205 },
206 {
207 source: "v: NO",
208 value: map[string]interface{}{"v": "NO"}, // no or No or NO is string
209 },
210 {
211 source: "v: on",
212 value: map[string]interface{}{"v": "on"}, // on is string
213 },
214
215 // Some cross type conversions
216 {
217 source: "v: 42",
218 value: map[string]uint{"v": 42},
219 },
220 {
221 source: "v: 4294967296",
222 value: map[string]uint64{"v": uint64(4294967296)},
223 },
224
225 // int
226 {
227 source: "v: 2147483647",
228 value: map[string]int{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxInt32scip-go gomod github.com/golang/go/src go1.21.0 math/MaxInt32.},
229 },
230 {
231 source: "v: -2147483648",
232 value: map[string]int{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MinInt32scip-go gomod github.com/golang/go/src go1.21.0 math/MinInt32.},
233 },
234
235 // int64
236 {
237 source: "v: 9223372036854775807",
238 value: map[string]int64{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxInt64.},
239 },
240 {
241 source: "v: 0b111111111111111111111111111111111111111111111111111111111111111",
242 value: map[string]int64{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxInt64.},
243 },
244 {
245 source: "v: -9223372036854775808",
246 value: map[string]int64{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MinInt64scip-go gomod github.com/golang/go/src go1.21.0 math/MinInt64.},
247 },
248 {
249 source: "v: -0b111111111111111111111111111111111111111111111111111111111111111",
250 value: map[string]int64{"v": -mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxInt64.},
251 },
252
253 // uint
254 {
255 source: "v: 0",
256 value: map[string]uint{"v": 0},
257 },
258 {
259 source: "v: 4294967295",
260 value: map[string]uint{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxUint32scip-go gomod github.com/golang/go/src go1.21.0 math/MaxUint32.},
261 },
262 {
263 source: "v: 1e3",
264 value: map[string]uint{"v": 1000},
265 },
266
267 // uint64
268 {
269 source: "v: 0",
270 value: map[string]uint{"v": 0},
271 },
272 {
273 source: "v: 18446744073709551615",
274 value: map[string]uint64{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxUint64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxUint64.},
275 },
276 {
277 source: "v: 0b1111111111111111111111111111111111111111111111111111111111111111",
278 value: map[string]uint64{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxUint64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxUint64.},
279 },
280 {
281 source: "v: 9223372036854775807",
282 value: map[string]uint64{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxInt64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxInt64.},
283 },
284 {
285 source: "v: 1e3",
286 value: map[string]uint64{"v": 1000},
287 },
288
289 // float32
290 {
291 source: "v: 3.40282346638528859811704183484516925440e+38",
292 value: map[string]float32{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxFloat32scip-go gomod github.com/golang/go/src go1.21.0 math/MaxFloat32.},
293 },
294 {
295 source: "v: 1.401298464324817070923729583289916131280e-45",
296 value: map[string]float32{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.SmallestNonzeroFloat32scip-go gomod github.com/golang/go/src go1.21.0 math/SmallestNonzeroFloat32.},
297 },
298 {
299 source: "v: 18446744073709551615",
300 value: map[string]float32{"v": float32(mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxUint64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxUint64.)},
301 },
302 {
303 source: "v: 18446744073709551616",
304 value: map[string]float32{"v": float32(mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxUint64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxUint64. + 1)},
305 },
306 {
307 source: "v: 1e-06",
308 value: map[string]float32{"v": 1e-6},
309 },
310
311 // float64
312 {
313 source: "v: 1.797693134862315708145274237317043567981e+308",
314 value: map[string]float64{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxFloat64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxFloat64.},
315 },
316 {
317 source: "v: 4.940656458412465441765687928682213723651e-324",
318 value: map[string]float64{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.SmallestNonzeroFloat64scip-go gomod github.com/golang/go/src go1.21.0 math/SmallestNonzeroFloat64.},
319 },
320 {
321 source: "v: 18446744073709551615",
322 value: map[string]float64{"v": float64(mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxUint64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxUint64.)},
323 },
324 {
325 source: "v: 18446744073709551616",
326 value: map[string]float64{"v": float64(mathscip-go gomod github.com/golang/go/src go1.21.0 math/.MaxUint64scip-go gomod github.com/golang/go/src go1.21.0 math/MaxUint64. + 1)},
327 },
328 {
329 source: "v: 1e-06",
330 value: map[string]float64{"v": 1e-06},
331 },
332
333 // Timestamps
334 {
335 // Date only.
336 source: "v: 2015-01-01\n",
337 value: map[string]timescip-go gomod github.com/golang/go/src go1.21.0 time/.Timescip-go gomod github.com/golang/go/src go1.21.0 time/Time#{"v": timescip-go gomod github.com/golang/go/src go1.21.0 time/.Datescip-go gomod github.com/golang/go/src go1.21.0 time/Date().(2015, 1, 1, 0, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.21.0 time/.UTCscip-go gomod github.com/golang/go/src go1.21.0 time/UTC.)},
338 },
339 {
340 // RFC3339
341 source: "v: 2015-02-24T18:19:39.12Z\n",
342 value: map[string]timescip-go gomod github.com/golang/go/src go1.21.0 time/.Timescip-go gomod github.com/golang/go/src go1.21.0 time/Time#{"v": timescip-go gomod github.com/golang/go/src go1.21.0 time/.Datescip-go gomod github.com/golang/go/src go1.21.0 time/Date().(2015, 2, 24, 18, 19, 39, .12e9, timescip-go gomod github.com/golang/go/src go1.21.0 time/.UTCscip-go gomod github.com/golang/go/src go1.21.0 time/UTC.)},
343 },
344 {
345 // RFC3339 with short dates.
346 source: "v: 2015-2-3T3:4:5Z",
347 value: map[string]timescip-go gomod github.com/golang/go/src go1.21.0 time/.Timescip-go gomod github.com/golang/go/src go1.21.0 time/Time#{"v": timescip-go gomod github.com/golang/go/src go1.21.0 time/.Datescip-go gomod github.com/golang/go/src go1.21.0 time/Date().(2015, 2, 3, 3, 4, 5, 0, timescip-go gomod github.com/golang/go/src go1.21.0 time/.UTCscip-go gomod github.com/golang/go/src go1.21.0 time/UTC.)},
348 },
349 {
350 // ISO8601 lower case t
351 source: "v: 2015-02-24t18:19:39Z\n",
352 value: map[string]timescip-go gomod github.com/golang/go/src go1.21.0 time/.Timescip-go gomod github.com/golang/go/src go1.21.0 time/Time#{"v": timescip-go gomod github.com/golang/go/src go1.21.0 time/.Datescip-go gomod github.com/golang/go/src go1.21.0 time/Date().(2015, 2, 24, 18, 19, 39, 0, timescip-go gomod github.com/golang/go/src go1.21.0 time/.UTCscip-go gomod github.com/golang/go/src go1.21.0 time/UTC.)},
353 },
354 {
355 // space separate, no time zone
356 source: "v: 2015-02-24 18:19:39\n",
357 value: map[string]timescip-go gomod github.com/golang/go/src go1.21.0 time/.Timescip-go gomod github.com/golang/go/src go1.21.0 time/Time#{"v": timescip-go gomod github.com/golang/go/src go1.21.0 time/.Datescip-go gomod github.com/golang/go/src go1.21.0 time/Date().(2015, 2, 24, 18, 19, 39, 0, timescip-go gomod github.com/golang/go/src go1.21.0 time/.UTCscip-go gomod github.com/golang/go/src go1.21.0 time/UTC.)},
358 },
359 {
360 source: "v: 60s\n",
361 value: map[string]timescip-go gomod github.com/golang/go/src go1.21.0 time/.Durationscip-go gomod github.com/golang/go/src go1.21.0 time/Duration#{"v": timescip-go gomod github.com/golang/go/src go1.21.0 time/.Minutescip-go gomod github.com/golang/go/src go1.21.0 time/Minute.},
362 },
363 {
364 source: "v: -0.5h\n",
365 value: map[string]timescip-go gomod github.com/golang/go/src go1.21.0 time/.Durationscip-go gomod github.com/golang/go/src go1.21.0 time/Duration#{"v": -30 * timescip-go gomod github.com/golang/go/src go1.21.0 time/.Minutescip-go gomod github.com/golang/go/src go1.21.0 time/Minute.},
366 },
367
368 // Single Quoted values.
369 {
370 source: `'1': '2'`,
371 value: map[interface{}]interface{}{"1": `2`},
372 },
373 {
374 source: `'1': '"2"'`,
375 value: map[interface{}]interface{}{"1": `"2"`},
376 },
377 {
378 source: `'1': ''''`,
379 value: map[interface{}]interface{}{"1": `'`},
380 },
381 {
382 source: `'1': '''2'''`,
383 value: map[interface{}]interface{}{"1": `'2'`},
384 },
385 {
386 source: `'1': 'B''z'`,
387 value: map[interface{}]interface{}{"1": `B'z`},
388 },
389 {
390 source: `'1': '\'`,
391 value: map[interface{}]interface{}{"1": `\`},
392 },
393 {
394 source: `'1': '\\'`,
395 value: map[interface{}]interface{}{"1": `\\`},
396 },
397 {
398 source: `'1': '\"2\"'`,
399 value: map[interface{}]interface{}{"1": `\"2\"`},
400 },
401 {
402 source: `'1': '\\"2\\"'`,
403 value: map[interface{}]interface{}{"1": `\\"2\\"`},
404 },
405 {
406 source: "'1': ' 1\n 2\n 3'",
407 value: map[interface{}]interface{}{"1": " 1 2 3"},
408 },
409 {
410 source: "'1': '\n 2\n 3'",
411 value: map[interface{}]interface{}{"1": " 2 3"},
412 },
413
414 // Double Quoted values.
415 {
416 source: `"1": "2"`,
417 value: map[interface{}]interface{}{"1": `2`},
418 },
419 {
420 source: `"1": "\"2\""`,
421 value: map[interface{}]interface{}{"1": `"2"`},
422 },
423 {
424 source: `"1": "\""`,
425 value: map[interface{}]interface{}{"1": `"`},
426 },
427 {
428 source: `"1": "X\"z"`,
429 value: map[interface{}]interface{}{"1": `X"z`},
430 },
431 {
432 source: `"1": "\\"`,
433 value: map[interface{}]interface{}{"1": `\`},
434 },
435 {
436 source: `"1": "\\\\"`,
437 value: map[interface{}]interface{}{"1": `\\`},
438 },
439 {
440 source: `"1": "\\\"2\\\""`,
441 value: map[interface{}]interface{}{"1": `\"2\"`},
442 },
443 {
444 source: "'1': \" 1\n 2\n 3\"",
445 value: map[interface{}]interface{}{"1": " 1 2 3"},
446 },
447 {
448 source: "'1': \"\n 2\n 3\"",
449 value: map[interface{}]interface{}{"1": " 2 3"},
450 },
451 {
452 source: `"1": "a\x2Fb"`,
453 value: map[interface{}]interface{}{"1": `a/b`},
454 },
455 {
456 source: `"1": "a\u002Fb"`,
457 value: map[interface{}]interface{}{"1": `a/b`},
458 },
459 {
460 source: `"1": "a\x2Fb\u002Fc\U0000002Fd"`,
461 value: map[interface{}]interface{}{"1": `a/b/c/d`},
462 },
463 {
464 source: "'1': \"2\\n3\"",
465 value: map[interface{}]interface{}{"1": "2\n3"},
466 },
467 {
468 source: "'1': \"2\\r\\n3\"",
469 value: map[interface{}]interface{}{"1": "2\r\n3"},
470 },
471 {
472 source: "'1': \"a\\\nb\\\nc\"",
473 value: map[interface{}]interface{}{"1": "abc"},
474 },
475 {
476 source: "'1': \"a\\\r\nb\\\r\nc\"",
477 value: map[interface{}]interface{}{"1": "abc"},
478 },
479 {
480 source: "'1': \"a\\\rb\\\rc\"",
481 value: map[interface{}]interface{}{"1": "abc"},
482 },
483
484 {
485 source: "a: -b_c",
486 value: map[string]interface{}{"a": "-b_c"},
487 },
488 {
489 source: "a: +b_c",
490 value: map[string]interface{}{"a": "+b_c"},
491 },
492 {
493 source: "a: 50cent_of_dollar",
494 value: map[string]interface{}{"a": "50cent_of_dollar"},
495 },
496
497 // Nulls
498 {
499 source: "null",
500 value: (*struct{})(nil),
501 },
502 {
503 source: "~",
504 value: (*struct{})(nil),
505 },
506 {
507 source: "v:",
508 value: map[string]interface{}{"v": nil},
509 },
510 {
511 source: "v: ~",
512 value: map[string]interface{}{"v": nil},
513 },
514 {
515 source: "~: null key",
516 value: map[interface{}]string{nil: "null key"},
517 },
518 {
519 source: "v:",
520 value: map[string]*bool{"v": nil},
521 },
522 {
523 source: "v: null",
524 value: map[string]*string{"v": nil},
525 },
526 {
527 source: "v: null",
528 value: map[string]string{"v": ""},
529 },
530 {
531 source: "v: null",
532 value: map[string]interface{}{"v": nil},
533 },
534 {
535 source: "v: Null",
536 value: map[string]interface{}{"v": nil},
537 },
538 {
539 source: "v: NULL",
540 value: map[string]interface{}{"v": nil},
541 },
542 {
543 source: "v: ~",
544 value: map[string]*string{"v": nil},
545 },
546 {
547 source: "v: ~",
548 value: map[string]string{"v": ""},
549 },
550
551 {
552 source: "v: .inf\n",
553 value: map[string]interface{}{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.Infscip-go gomod github.com/golang/go/src go1.21.0 math/Inf().(0)},
554 },
555 {
556 source: "v: .Inf\n",
557 value: map[string]interface{}{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.Infscip-go gomod github.com/golang/go/src go1.21.0 math/Inf().(0)},
558 },
559 {
560 source: "v: .INF\n",
561 value: map[string]interface{}{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.Infscip-go gomod github.com/golang/go/src go1.21.0 math/Inf().(0)},
562 },
563 {
564 source: "v: -.inf\n",
565 value: map[string]interface{}{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.Infscip-go gomod github.com/golang/go/src go1.21.0 math/Inf().(-1)},
566 },
567 {
568 source: "v: -.Inf\n",
569 value: map[string]interface{}{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.Infscip-go gomod github.com/golang/go/src go1.21.0 math/Inf().(-1)},
570 },
571 {
572 source: "v: -.INF\n",
573 value: map[string]interface{}{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.Infscip-go gomod github.com/golang/go/src go1.21.0 math/Inf().(-1)},
574 },
575 {
576 source: "v: .nan\n",
577 value: map[string]interface{}{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.NaNscip-go gomod github.com/golang/go/src go1.21.0 math/NaN().()},
578 },
579 {
580 source: "v: .NaN\n",
581 value: map[string]interface{}{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.NaNscip-go gomod github.com/golang/go/src go1.21.0 math/NaN().()},
582 },
583 {
584 source: "v: .NAN\n",
585 value: map[string]interface{}{"v": mathscip-go gomod github.com/golang/go/src go1.21.0 math/.NaNscip-go gomod github.com/golang/go/src go1.21.0 math/NaN().()},
586 },
587
588 // Explicit tags.
589 {
590 source: "v: !!float '1.1'",
591 value: map[string]interface{}{"v": 1.1},
592 },
593 {
594 source: "v: !!float 0",
595 value: map[string]interface{}{"v": float64(0)},
596 },
597 {
598 source: "v: !!float -1",
599 value: map[string]interface{}{"v": float64(-1)},
600 },
601 {
602 source: "v: !!null ''",
603 value: map[string]interface{}{"v": nil},
604 },
605 {
606 source: "v: !!timestamp \"2015-01-01\"",
607 value: map[string]timescip-go gomod github.com/golang/go/src go1.21.0 time/.Timescip-go gomod github.com/golang/go/src go1.21.0 time/Time#{"v": timescip-go gomod github.com/golang/go/src go1.21.0 time/.Datescip-go gomod github.com/golang/go/src go1.21.0 time/Date().(2015, 1, 1, 0, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.21.0 time/.UTCscip-go gomod github.com/golang/go/src go1.21.0 time/UTC.)},
608 },
609 {
610 source: "v: !!timestamp 2015-01-01",
611 value: map[string]timescip-go gomod github.com/golang/go/src go1.21.0 time/.Timescip-go gomod github.com/golang/go/src go1.21.0 time/Time#{"v": timescip-go gomod github.com/golang/go/src go1.21.0 time/.Datescip-go gomod github.com/golang/go/src go1.21.0 time/Date().(2015, 1, 1, 0, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.21.0 time/.UTCscip-go gomod github.com/golang/go/src go1.21.0 time/UTC.)},
612 },
613 {
614 source: "v: !!bool yes",
615 value: map[string]bool{"v": true},
616 },
617 {
618 source: "v: !!bool False",
619 value: map[string]bool{"v": false},
620 },
621 {
622 source: `
623 !!merge <<: { a: 1, b: 2 }
624 c: 3
625 `,
626 value: map[string]any{"a": 1, "b": 2, "c": 3},
627 },
628
629 // merge
630 {
631 source: `
632 a: &a
633 foo: 1
634 b: &b
635 bar: 2
636 merge:
637 <<: [*a, *b]
638 `,
639 value: map[string]map[string]any{
640 "a": {"foo": 1},
641 "b": {"bar": 2},
642 "merge": {"foo": 1, "bar": 2},
643 },
644 },
645 {
646 source: `
647 a: &a
648 foo: 1
649 b: &b
650 bar: 2
651 merge:
652 <<: [*a, *b]
653 `,
654 value: map[string]yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.MapSlicescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapSlice#{
655 "a": {{Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Key.: "foo", Valuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Value.: 1}},
656 "b": {{Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Key.: "bar", Valuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Value.: 2}},
657 "merge": {{Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Key.: "foo", Valuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Value.: 1}, {Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Key.: "bar", Valuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Value.: 2}},
658 },
659 },
660
661 // Flow sequence
662 {
663 source: "v: [A,B]",
664 value: map[string]interface{}{"v": []interface{}{"A", "B"}},
665 },
666 {
667 source: "v: [A,B,C,]",
668 value: map[string][]string{"v": {"A", "B", "C"}},
669 },
670 {
671 source: "v: [A,1,C]",
672 value: map[string][]string{"v": {"A", "1", "C"}},
673 },
674 {
675 source: "v: [A,1,C]",
676 value: map[string]interface{}{"v": []interface{}{"A", 1, "C"}},
677 },
678 {
679 source: "v: [a: b, c: d]",
680 value: map[string]any{"v": []any{
681 map[string]any{"a": "b"},
682 map[string]any{"c": "d"},
683 }},
684 },
685 {
686 source: "v: [{a: b}, {c: d, e: f}]",
687 value: map[string]any{"v": []any{
688 map[string]any{"a": "b"},
689 map[string]any{
690 "c": "d",
691 "e": "f",
692 },
693 }},
694 },
695
696 // Block sequence
697 {
698 source: "v:\n - A\n - B",
699 value: map[string]interface{}{"v": []interface{}{"A", "B"}},
700 },
701 {
702 source: "v:\n - A\n - B\n - C",
703 value: map[string][]string{"v": {"A", "B", "C"}},
704 },
705 {
706 source: "v:\n - A\n - 1\n - C",
707 value: map[string][]string{"v": {"A", "1", "C"}},
708 },
709 {
710 source: "v:\n - A\n - 1\n - C",
711 value: map[string]interface{}{"v": []interface{}{"A", 1, "C"}},
712 },
713
714 // Map inside interface with no type hints.
715 {
716 source: "a: {b: c}",
717 value: map[interface{}]interface{}{"a": map[interface{}]interface{}{"b": "c"}},
718 },
719
720 {
721 source: "v: \"\"\n",
722 value: map[string]string{"v": ""},
723 },
724 {
725 source: "v:\n- A\n- B\n",
726 value: map[string][]string{"v": {"A", "B"}},
727 },
728 {
729 source: "a: '-'\n",
730 value: map[string]string{"a": "-"},
731 },
732 {
733 source: "123\n",
734 value: 123,
735 },
736 {
737 source: "hello: world\n",
738 value: map[string]string{"hello": "world"},
739 },
740 {
741 source: "hello: world\r\n",
742 value: map[string]string{"hello": "world"},
743 },
744 {
745 source: "hello: world\rGo: Gopher",
746 value: map[string]string{"hello": "world", "Go": "Gopher"},
747 },
748
749 // Structs and type conversions.
750 {
751 source: "hello: world",
752 value: struct{ Hello string }{"world"},
753 },
754 {
755 source: "a: {b: c}",
756 value: struct{ A struct{ B string } }{struct{ B string }{"c"}},
757 },
758 {
759 source: "a: {b: c}",
760 value: struct{ A map[string]string }{map[string]string{"b": "c"}},
761 },
762 {
763 source: "a:",
764 value: struct{ A map[string]string }{},
765 },
766 {
767 source: "a: 1",
768 value: struct{ A int }{1},
769 },
770 {
771 source: "a: 1",
772 value: struct{ A float64 }{1},
773 },
774 {
775 source: "a: 1.0",
776 value: struct{ A int }{1},
777 },
778 {
779 source: "a: 1.0",
780 value: struct{ A uint }{1},
781 },
782 {
783 source: "a: [1, 2]",
784 value: struct{ A []int }{[]int{1, 2}},
785 },
786 {
787 source: "a: [1, 2]",
788 value: struct{ A [2]int }{[2]int{1, 2}},
789 },
790 {
791 source: "a: 1",
792 value: struct{ B int }{0},
793 },
794 {
795 source: "a: 1",
796 value: struct {
797 B int `yaml:"a"`
798 }{1},
799 },
800
801 {
802 source: "a: 1\n",
803 value: yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.MapItemscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#{Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Key.: "a", Valuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Value.: 1},
804 },
805 {
806 source: "a: 1\nb: 2\nc: 3\n",
807 value: yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.MapSlicescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapSlice#{
808 {Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Key.: "a", Valuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Value.: 1},
809 {Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Key.: "b", Valuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Value.: 2},
810 {Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Key.: "c", Valuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Value.: 3},
811 },
812 },
813 {
814 source: "v:\n- A\n- 1\n- B:\n - 2\n - 3\n",
815 value: map[string]interface{}{
816 "v": []interface{}{
817 "A",
818 1,
819 map[string][]int{
820 "B": {2, 3},
821 },
822 },
823 },
824 },
825 {
826 source: "a:\n b: c\n",
827 value: map[string]interface{}{
828 "a": map[string]string{
829 "b": "c",
830 },
831 },
832 },
833 {
834 source: "a: {x: 1}\n",
835 value: map[string]map[string]int{
836 "a": {
837 "x": 1,
838 },
839 },
840 },
841 {
842 source: "t2: 2018-01-09T10:40:47Z\nt4: 2098-01-09T10:40:47Z\n",
843 value: map[string]string{
844 "t2": "2018-01-09T10:40:47Z",
845 "t4": "2098-01-09T10:40:47Z",
846 },
847 },
848 {
849 source: "a: [1, 2]\n",
850 value: map[string][]int{
851 "a": {1, 2},
852 },
853 },
854 {
855 source: "a: {b: c, d: e}\n",
856 value: map[string]interface{}{
857 "a": map[string]string{
858 "b": "c",
859 "d": "e",
860 },
861 },
862 },
863 {
864 source: "a: 3s\n",
865 value: map[string]string{
866 "a": "3s",
867 },
868 },
869 {
870 source: "a: <foo>\n",
871 value: map[string]string{"a": "<foo>"},
872 },
873 {
874 source: "a: \"1:1\"\n",
875 value: map[string]string{"a": "1:1"},
876 },
877 {
878 source: "a: 1.2.3.4\n",
879 value: map[string]string{"a": "1.2.3.4"},
880 },
881 {
882 source: "a: 'b: c'\n",
883 value: map[string]string{"a": "b: c"},
884 },
885 {
886 source: "a: 'Hello #comment'\n",
887 value: map[string]string{"a": "Hello #comment"},
888 },
889 {
890 source: "a: 100.5\n",
891 value: map[string]interface{}{
892 "a": 100.5,
893 },
894 },
895 {
896 source: "a: \"\\0\"\n",
897 value: map[string]string{"a": "\x00"},
898 },
899 {
900 source: "b: 2\na: 1\nd: 4\nc: 3\nsub:\n e: 5\n",
901 value: map[string]interface{}{
902 "b": 2,
903 "a": 1,
904 "d": 4,
905 "c": 3,
906 "sub": map[string]int{
907 "e": 5,
908 },
909 },
910 },
911 {
912 source: " a : b \n",
913 value: map[string]string{"a": "b"},
914 },
915 {
916 source: "a: b # comment\nb: c\n",
917 value: map[string]string{
918 "a": "b",
919 "b": "c",
920 },
921 },
922 {
923 source: "---\na: b\n",
924 value: map[string]string{"a": "b"},
925 },
926 {
927 source: "a: b\n...\n",
928 value: map[string]string{"a": "b"},
929 },
930 {
931 source: "%YAML 1.2\n---\n",
932 value: (*struct{})(nil),
933 eof: true,
934 },
935 {
936 source: "---\n",
937 value: (*struct{})(nil),
938 eof: true,
939 },
940 {
941 source: "...",
942 value: (*struct{})(nil),
943 eof: true,
944 },
945 {
946 source: "v: go test ./...",
947 value: map[string]string{"v": "go test ./..."},
948 },
949 {
950 source: "v: echo ---",
951 value: map[string]string{"v": "echo ---"},
952 },
953 {
954 source: "v: |\n hello\n ...\n world\n",
955 value: map[string]string{"v": "hello\n...\nworld\n"},
956 },
957 {
958 source: "a: !!binary gIGC\n",
959 value: map[string]string{"a": "\x80\x81\x82"},
960 },
961 {
962 source: "a: !!binary |\n " + stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21.0 strings/Repeat().("kJCQ", 17) + "kJ\n CQ\n",
963 value: map[string]string{"a": stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21.0 strings/Repeat().("\x90", 54)},
964 },
965 {
966 source: "v:\n- A\n- |-\n B\n C\n",
967 value: map[string][]string{
968 "v": {
969 "A", "B\nC",
970 },
971 },
972 },
973 {
974 source: "v:\n- A\n- |-\n B\n C\n\n\n",
975 value: map[string][]string{
976 "v": {
977 "A", "B\nC",
978 },
979 },
980 },
981 {
982 source: "v:\n- A\n- >-\n B\n C\n",
983 value: map[string][]string{
984 "v": {
985 "A", "B C",
986 },
987 },
988 },
989 {
990 source: "v:\n- A\n- >-\n B\n C\n\n\n",
991 value: map[string][]string{
992 "v": {
993 "A", "B C",
994 },
995 },
996 },
997 {
998 source: "a: b\nc: d\n",
999 value: struct {
1000 A string
1001 C string `yaml:"c"`
1002 }{
1003 "b", "d",
1004 },
1005 },
1006 {
1007 source: "a: 1\nb: 2\n",
1008 value: struct {
1009 A int
1010 B int `yaml:"-"`
1011 }{
1012 1, 0,
1013 },
1014 },
1015 {
1016 source: "a: 1\nb: 2\n",
1017 value: struct {
1018 A int
1019 Childscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child# `yaml:",inline"`
1020 }{
1021 1,
1022 Childscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#{
1023 Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#B.: 2,
1024 Cscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#C.: 0,
1025 },
1026 },
1027 },
1028
1029 // Anchors and aliases.
1030 {
1031 source: "a: &x 1\nb: &y 2\nc: *x\nd: *y\n",
1032 value: struct{ A, B, C, D int }{1, 2, 1, 2},
1033 },
1034 {
1035 source: "a: &a {c: 1}\nb: *a\n",
1036 value: struct {
1037 A, B struct {
1038 C int
1039 }
1040 }{struct{ C int }{1}, struct{ C int }{1}},
1041 },
1042 {
1043 source: "a: &a [1, 2]\nb: *a\n",
1044 value: struct{ B []int }{[]int{1, 2}},
1045 },
1046 {
1047 source: "key1: &anchor\n subkey: *anchor\nkey2: *anchor\n",
1048 value: map[string]any{
1049 "key1": map[string]any{
1050 "subkey": nil,
1051 },
1052 "key2": map[string]any{
1053 "subkey": nil,
1054 },
1055 },
1056 },
1057 {
1058 source: `{a: &a c, *a : b}`,
1059 value: map[string]string{"a": "c", "c": "b"},
1060 },
1061 {
1062 source: "tags:\n- hello-world\na: foo",
1063 value: struct {
1064 Tags []string
1065 A string
1066 }{Tags: []string{"hello-world"}, A: "foo"},
1067 },
1068 {
1069 source: "",
1070 value: (*struct{})(nil),
1071 eof: true,
1072 },
1073 {
1074 source: "{}",
1075 value: struct{}{},
1076 },
1077 {
1078 source: "{a: , b: c}",
1079 value: map[string]any{"a": nil, "b": "c"},
1080 },
1081 {
1082 source: "v: /a/{b}",
1083 value: map[string]string{"v": "/a/{b}"},
1084 },
1085 {
1086 source: "v: 1[]{},!%?&*",
1087 value: map[string]string{"v": "1[]{},!%?&*"},
1088 },
1089 {
1090 source: "v: user's item",
1091 value: map[string]string{"v": "user's item"},
1092 },
1093 {
1094 source: "v: [1,[2,[3,[4,5],6],7],8]",
1095 value: map[string]interface{}{
1096 "v": []interface{}{
1097 1,
1098 []interface{}{
1099 2,
1100 []interface{}{
1101 3,
1102 []int{4, 5},
1103 6,
1104 },
1105 7,
1106 },
1107 8,
1108 },
1109 },
1110 },
1111 {
1112 source: "v: {a: {b: {c: {d: e},f: g},h: i},j: k}",
1113 value: map[string]interface{}{
1114 "v": map[string]interface{}{
1115 "a": map[string]interface{}{
1116 "b": map[string]interface{}{
1117 "c": map[string]string{
1118 "d": "e",
1119 },
1120 "f": "g",
1121 },
1122 "h": "i",
1123 },
1124 "j": "k",
1125 },
1126 },
1127 },
1128 {
1129 source: `---
1130 - a:
1131 b:
1132 - c: d
1133 `,
1134 value: []map[string]interface{}{
1135 {
1136 "a": map[string]interface{}{
1137 "b": nil,
1138 },
1139 },
1140 {
1141 "c": "d",
1142 },
1143 },
1144 },
1145 {
1146 source: `---
1147 a:
1148 b:
1149 c: d
1150 `,
1151 value: map[string]interface{}{
1152 "a": map[string]interface{}{
1153 "b": nil,
1154 },
1155 "c": "d",
1156 },
1157 },
1158 {
1159 source: `---
1160 a:
1161 b:
1162 c:
1163 `,
1164 value: map[string]interface{}{
1165 "a": nil,
1166 "b": nil,
1167 "c": nil,
1168 },
1169 },
1170 {
1171 source: `---
1172 a: go test ./...
1173 b:
1174 c:
1175 `,
1176 value: map[string]interface{}{
1177 "a": "go test ./...",
1178 "b": nil,
1179 "c": nil,
1180 },
1181 },
1182 {
1183 source: `---
1184 a: |
1185 hello
1186 ...
1187 world
1188 b:
1189 c:
1190 `,
1191 value: map[string]interface{}{
1192 "a": "hello\n...\nworld\n",
1193 "b": nil,
1194 "c": nil,
1195 },
1196 },
1197
1198 // Multi bytes
1199 {
1200 source: "v: あいうえお\nv2: かきくけこ",
1201 value: map[string]string{"v": "あいうえお", "v2": "かきくけこ"},
1202 },
1203 {
1204 source: `
1205 - "Fun with \\"
1206 - "\" \a \b \e \f"
1207 - "\n \r \t \v \0"
1208 - "\ \_ \N \L \P \
1209 \x41 \u0041 \U00000041"
1210 `,
1211 value: []string{"Fun with \\", "\" \u0007 \b \u001b \f", "\n \r \t \u000b \u0000", "\u0020 \u00a0 \u0085 \u2028 \u2029 A A A"},
1212 },
1213 {
1214 source: `"\ud83e\udd23"`,
1215 value: "🤣",
1216 },
1217 {
1218 source: `"\uD83D\uDE00\uD83D\uDE01"`,
1219 value: "😀😁",
1220 },
1221 {
1222 source: `"\uD83D\uDE00a\uD83D\uDE01"`,
1223 value: "😀a😁",
1224 },
1225 }
1226 for _, test := range tests {
1227 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(test.source, func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1228 buf := bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.NewBufferStringscip-go gomod github.com/golang/go/src go1.21.0 bytes/NewBufferString().(test.source)
1229 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(buf)
1230 typ := reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.21.0 reflect/ValueOf().(test.value).Typescip-go gomod github.com/golang/go/src go1.21.0 reflect/Value#Type().()
1231 value := reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.21.0 reflect/New().(typ)
1232 if err := dec.Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(value.Interfacescip-go gomod github.com/golang/go/src go1.21.0 reflect/Value#Interface().()); err != nil {
1233 if test.eof && err == ioscip-go gomod github.com/golang/go/src go1.21.0 io/.EOFscip-go gomod github.com/golang/go/src go1.21.0 io/EOF. {
1234 return
1235 }
1236 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%s: %+v", test.source, err)
1237 }
1238 if test.eof {
1239 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected EOF but got no error")
1240 }
1241 actual := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%+v", value.Elemscip-go gomod github.com/golang/go/src go1.21.0 reflect/Value#Elem().().Interfacescip-go gomod github.com/golang/go/src go1.21.0 reflect/Value#Interface().())
1242 expect := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%+v", test.value)
1243 if actual != expect {
1244 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to test [%s], actual=[%s], expect=[%s]", test.source, actual, expect)
1245 }
1246 })
1247 }
1248 }
1249
1250 func TestDecoder_Invalidscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_Invalid().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1251 tests := []struct {
1252 src string
1253 expect string
1254 }{
1255 {
1256 "*-0",
1257 `
1258 [1:2] could not find alias "-0"
1259 > 1 | *-0
1260 ^
1261 `,
1262 },
1263 }
1264 for _, test := range tests {
1265 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(test.src, func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1266 var v any
1267 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(test.src), &v)
1268 if err == nil {
1269 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("cannot catch decode error")
1270 }
1271 actual := "\n" + err.Error()
1272 if test.expect != actual {
1273 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected: [%s] but got [%s]", test.expect, actual)
1274 }
1275 })
1276 }
1277 }
1278
1279 func TestDecoder_ScientificNotationscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_ScientificNotation().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1280 tests := []struct {
1281 source string
1282 value interface{}
1283 }{
1284 {
1285 "v: 1e3",
1286 map[string]uint{"v": 1000},
1287 },
1288 {
1289 "v: 1e-3",
1290 map[string]uint{"v": 0},
1291 },
1292 {
1293 "v: 1e3",
1294 map[string]int{"v": 1000},
1295 },
1296 {
1297 "v: 1e-3",
1298 map[string]int{"v": 0},
1299 },
1300 {
1301 "v: 1e3",
1302 map[string]float32{"v": 1000},
1303 },
1304 {
1305 "v: 1.0e3",
1306 map[string]float64{"v": 1000},
1307 },
1308 {
1309 "v: 1e-3",
1310 map[string]float64{"v": 0.001},
1311 },
1312 {
1313 "v: 1.0e-3",
1314 map[string]float64{"v": 0.001},
1315 },
1316 {
1317 "v: 1.0e+3",
1318 map[string]float64{"v": 1000},
1319 },
1320 {
1321 "v: 1.0e+3",
1322 map[string]float64{"v": 1000},
1323 },
1324 }
1325 for _, test := range tests {
1326 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(test.source, func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1327 buf := bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.NewBufferStringscip-go gomod github.com/golang/go/src go1.21.0 bytes/NewBufferString().(test.source)
1328 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(buf)
1329 typ := reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.21.0 reflect/ValueOf().(test.value).Typescip-go gomod github.com/golang/go/src go1.21.0 reflect/Value#Type().()
1330 value := reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.Newscip-go gomod github.com/golang/go/src go1.21.0 reflect/New().(typ)
1331 if err := dec.Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(value.Interfacescip-go gomod github.com/golang/go/src go1.21.0 reflect/Value#Interface().()); err != nil {
1332 if err == ioscip-go gomod github.com/golang/go/src go1.21.0 io/.EOFscip-go gomod github.com/golang/go/src go1.21.0 io/EOF. {
1333 return
1334 }
1335 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%s: %+v", test.source, err)
1336 }
1337 actual := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%+v", value.Elemscip-go gomod github.com/golang/go/src go1.21.0 reflect/Value#Elem().().Interfacescip-go gomod github.com/golang/go/src go1.21.0 reflect/Value#Interface().())
1338 expect := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%+v", test.value)
1339 if actual != expect {
1340 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to test [%s], actual=[%s], expect=[%s]", test.source, actual, expect)
1341 }
1342 })
1343 }
1344 }
1345
1346 func TestDecoder_TypeConversionErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_TypeConversionError().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1347 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("type conversion for struct", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1348 type T struct {
1349 A int
1350 B uint
1351 C float32
1352 D bool
1353 }
1354 type U struct {
1355 *T `yaml:",inline"`
1356 }
1357 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("string to int", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1358 var v T
1359 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`a: str`), &v)
1360 if err == nil {
1361 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1362 }
1363 msg := "cannot unmarshal string into Go struct field T.A of type int"
1364 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1365 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1366 }
1367 })
1368 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("string to uint", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1369 var v T
1370 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`b: str`), &v)
1371 if err == nil {
1372 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1373 }
1374 msg := "cannot unmarshal string into Go struct field T.B of type uint"
1375 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1376 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1377 }
1378 })
1379 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("string to bool", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1380 var v T
1381 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`d: str`), &v)
1382 if err == nil {
1383 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1384 }
1385 msg := "cannot unmarshal string into Go struct field T.D of type bool"
1386 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1387 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1388 }
1389 })
1390 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("string to int at inline", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1391 var v U
1392 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`a: str`), &v)
1393 if err == nil {
1394 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1395 }
1396 msg := "cannot unmarshal string into Go struct field U.T.A of type int"
1397 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1398 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1399 }
1400 })
1401 })
1402 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("type conversion for array", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1403 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("string to int", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1404 var v map[string][]int
1405 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`v: [A,1,C]`), &v)
1406 if err == nil {
1407 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1408 }
1409 msg := "cannot unmarshal string into Go value of type int"
1410 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1411 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1412 }
1413 })
1414 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("string to int", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1415 var v map[string][]int
1416 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte("v:\n - A\n - 1\n - C"), &v)
1417 if err == nil {
1418 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1419 }
1420 msg := "cannot unmarshal string into Go value of type int"
1421 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1422 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1423 }
1424 })
1425 })
1426 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("overflow error", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1427 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("negative number to uint", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1428 var v map[string]uint
1429 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte("v: -42"), &v)
1430 if err == nil {
1431 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1432 }
1433 msg := "cannot unmarshal -42 into Go value of type uint ( overflow )"
1434 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1435 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1436 }
1437 if v["v"] != 0 {
1438 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode value")
1439 }
1440 })
1441 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("negative number to uint64", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1442 var v map[string]uint64
1443 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte("v: -4294967296"), &v)
1444 if err == nil {
1445 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1446 }
1447 msg := "cannot unmarshal -4294967296 into Go value of type uint64 ( overflow )"
1448 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1449 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1450 }
1451 if v["v"] != 0 {
1452 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode value")
1453 }
1454 })
1455 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("larger number for int32", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1456 var v map[string]int32
1457 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte("v: 4294967297"), &v)
1458 if err == nil {
1459 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1460 }
1461 msg := "cannot unmarshal 4294967297 into Go value of type int32 ( overflow )"
1462 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1463 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1464 }
1465 if v["v"] != 0 {
1466 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode value")
1467 }
1468 })
1469 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("larger number for int8", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1470 var v map[string]int8
1471 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte("v: 128"), &v)
1472 if err == nil {
1473 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1474 }
1475 msg := "cannot unmarshal 128 into Go value of type int8 ( overflow )"
1476 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1477 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1478 }
1479 if v["v"] != 0 {
1480 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode value")
1481 }
1482 })
1483 })
1484 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("type conversion for time", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1485 type T struct {
1486 A timescip-go gomod github.com/golang/go/src go1.21.0 time/.Timescip-go gomod github.com/golang/go/src go1.21.0 time/Time#
1487 B timescip-go gomod github.com/golang/go/src go1.21.0 time/.Durationscip-go gomod github.com/golang/go/src go1.21.0 time/Duration#
1488 }
1489 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("int to time", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1490 var v T
1491 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`a: 123`), &v)
1492 if err == nil {
1493 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1494 }
1495 msg := "cannot unmarshal uint64 into Go struct field T.A of type time.Time"
1496 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1497 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1498 }
1499 })
1500 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("string to duration", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1501 var v T
1502 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`b: str`), &v)
1503 if err == nil {
1504 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1505 }
1506 msg := `time: invalid duration "str"`
1507 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1508 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1509 }
1510 })
1511 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("int to duration", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1512 var v T
1513 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`b: 10`), &v)
1514 if err == nil {
1515 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
1516 }
1517 msg := "cannot unmarshal uint64 into Go struct field T.B of type time.Duration"
1518 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), msg) {
1519 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), msg)
1520 }
1521 })
1522 })
1523 }
1524
1525 func TestDecoder_AnchorReferenceDirsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_AnchorReferenceDirs().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1526 buf := bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.NewBufferStringscip-go gomod github.com/golang/go/src go1.21.0 bytes/NewBufferString().("a: *a\n")
1527 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(buf, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.ReferenceDirsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ReferenceDirs().("testdata"))
1528 var v struct {
1529 A struct {
1530 B int
1531 C string
1532 }
1533 }
1534 if err := dec.Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1535 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
1536 }
1537 if v.A.B != 1 {
1538 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode by reference dirs")
1539 }
1540 if v.A.C != "hello" {
1541 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode by reference dirs")
1542 }
1543 }
1544
1545 func TestDecoder_AnchorReferenceDirsRecursivescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_AnchorReferenceDirsRecursive().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1546 buf := bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.NewBufferStringscip-go gomod github.com/golang/go/src go1.21.0 bytes/NewBufferString().("a: *a\n")
1547 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(
1548 buf,
1549 yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.ReferenceDirsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ReferenceDirs().("testdata"),
1550 )
1551 var v struct {
1552 A struct {
1553 B int
1554 C string
1555 }
1556 }
1557 if err := dec.Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1558 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
1559 }
1560 if v.A.B != 1 {
1561 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode by reference dirs")
1562 }
1563 if v.A.C != "hello" {
1564 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode by reference dirs")
1565 }
1566 }
1567
1568 func TestDecoder_AnchorFilesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_AnchorFiles().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1569 buf := bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.NewBufferStringscip-go gomod github.com/golang/go/src go1.21.0 bytes/NewBufferString().("a: *a\n")
1570 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(buf, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.ReferenceFilesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ReferenceFiles().("testdata/anchor.yml"))
1571 var v struct {
1572 A struct {
1573 B int
1574 C string
1575 }
1576 }
1577 if err := dec.Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1578 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
1579 }
1580 if v.A.B != 1 {
1581 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode by reference dirs")
1582 }
1583 if v.A.C != "hello" {
1584 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode by reference dirs")
1585 }
1586 }
1587
1588 func TestDecodeWithMergeKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecodeWithMergeKey().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1589 yml := `
1590 a: &a
1591 b: 1
1592 c: hello
1593 items:
1594 - <<: *a
1595 - <<: *a
1596 c: world
1597 `
1598 type Item struct {
1599 B int
1600 C string
1601 }
1602 type T struct {
1603 Items []*Item
1604 }
1605 buf := bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.NewBufferStringscip-go gomod github.com/golang/go/src go1.21.0 bytes/NewBufferString().(yml)
1606 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(buf, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.AllowDuplicateMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/AllowDuplicateMapKey().())
1607 var v T
1608 if err := dec.Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1609 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
1610 }
1611 if len(v.Items) != 2 {
1612 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1613 }
1614 if v.Items[0].B != 1 || v.Items[0].C != "hello" {
1615 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1616 }
1617 if v.Items[1].B != 1 || v.Items[1].C != "world" {
1618 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1619 }
1620 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("decode with interface{}", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1621 buf := bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.NewBufferStringscip-go gomod github.com/golang/go/src go1.21.0 bytes/NewBufferString().(yml)
1622 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(buf)
1623 var v interface{}
1624 if err := dec.Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1625 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
1626 }
1627 items, _ := v.(map[string]interface{})["items"].([]interface{})
1628 if len(items) != 2 {
1629 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1630 }
1631 b0 := items[0].(map[string]interface{})["b"]
1632 if _, ok := b0.(uint64); !ok {
1633 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1634 }
1635 if b0.(uint64) != 1 {
1636 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1637 }
1638 c0 := items[0].(map[string]interface{})["c"]
1639 if _, ok := c0.(string); !ok {
1640 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1641 }
1642 if c0.(string) != "hello" {
1643 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1644 }
1645 b1 := items[1].(map[string]interface{})["b"]
1646 if _, ok := b1.(uint64); !ok {
1647 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1648 }
1649 if b1.(uint64) != 1 {
1650 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1651 }
1652 c1 := items[1].(map[string]interface{})["c"]
1653 if _, ok := c1.(string); !ok {
1654 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1655 }
1656 if c1.(string) != "world" {
1657 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1658 }
1659 })
1660 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("decode with map", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1661 var v struct {
1662 Items []map[string]interface{}
1663 }
1664 buf := bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.NewBufferStringscip-go gomod github.com/golang/go/src go1.21.0 bytes/NewBufferString().(yml)
1665 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(buf)
1666 if err := dec.Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1667 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
1668 }
1669 if len(v.Items) != 2 {
1670 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1671 }
1672 b0 := v.Items[0]["b"]
1673 if _, ok := b0.(uint64); !ok {
1674 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1675 }
1676 if b0.(uint64) != 1 {
1677 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1678 }
1679 c0 := v.Items[0]["c"]
1680 if _, ok := c0.(string); !ok {
1681 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1682 }
1683 if c0.(string) != "hello" {
1684 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1685 }
1686 b1 := v.Items[1]["b"]
1687 if _, ok := b1.(uint64); !ok {
1688 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1689 }
1690 if b1.(uint64) != 1 {
1691 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1692 }
1693 c1 := v.Items[1]["c"]
1694 if _, ok := c1.(string); !ok {
1695 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1696 }
1697 if c1.(string) != "world" {
1698 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with merge key")
1699 }
1700 })
1701 }
1702
1703 func TestDecoder_Inlinescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_Inline().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1704 type Base struct {
1705 A int
1706 B string
1707 }
1708 yml := `---
1709 a: 1
1710 b: hello
1711 c: true
1712 `
1713 var v struct {
1714 *Base `yaml:",inline"`
1715 C bool
1716 }
1717 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml)).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1718 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
1719 }
1720 if v.A != 1 {
1721 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with inline key")
1722 }
1723 if v.B != "hello" {
1724 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with inline key")
1725 }
1726 if !v.C {
1727 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with inline key")
1728 }
1729
1730 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("multiple inline with strict", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1731 type Base struct {
1732 A int
1733 B string
1734 }
1735 type Base2 struct {
1736 Base *Base `yaml:",inline"`
1737 }
1738 yml := `---
1739 a: 1
1740 b: hello
1741 `
1742 var v struct {
1743 Base2 *Base2 `yaml:",inline"`
1744 }
1745 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml), yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Strictscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Strict().()).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1746 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
1747 }
1748 if v.Base2.Base.A != 1 {
1749 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with inline key")
1750 }
1751 if v.Base2.Base.B != "hello" {
1752 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with inline key")
1753 }
1754 })
1755 }
1756
1757 func TestDecoder_InlineAndConflictKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_InlineAndConflictKey().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1758 type Base struct {
1759 A int
1760 B string
1761 }
1762 yml := `---
1763 a: 1
1764 b: hello
1765 c: true
1766 `
1767 var v struct {
1768 *Base `yaml:",inline"`
1769 A int
1770 C bool
1771 }
1772 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml)).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1773 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
1774 }
1775 if v.A != 1 {
1776 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with inline key")
1777 }
1778 if v.B != "hello" {
1779 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with inline key")
1780 }
1781 if !v.C {
1782 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with inline key")
1783 }
1784 if v.Base.A != 0 {
1785 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode with inline key")
1786 }
1787 }
1788
1789 func TestDecoder_InlineAndWrongTypeStrictscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_InlineAndWrongTypeStrict().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1790 type Base struct {
1791 A int
1792 B string
1793 }
1794 yml := `---
1795 a: notanint
1796 b: hello
1797 c: true
1798 `
1799 var v struct {
1800 *Base `yaml:",inline"`
1801 C bool
1802 }
1803 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml), yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Strictscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Strict().()).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v)
1804 if err == nil {
1805 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error")
1806 }
1807
1808 // TODO: properly check if errors are colored/have source
1809 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("%s", err)
1810 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("%s", yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.FormatErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/FormatError().(err, true, false))
1811 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("%s", yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.FormatErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/FormatError().(err, false, true))
1812 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("%s", yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.FormatErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/FormatError().(err, true, true))
1813 }
1814
1815 func TestDecoder_InvalidCasesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_InvalidCases().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1816 const src = `---
1817 a:
1818 - b
1819 c: d
1820 `
1821 var v struct {
1822 A []string
1823 }
1824 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(src)).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v)
1825 if err == nil {
1826 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error")
1827 }
1828
1829 if err.Error() != yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.FormatErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/FormatError().(err, false, true) {
1830 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("err.Error() = %s", err.Error())
1831 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("yaml.FormatError(err, false, true) = %s", yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.FormatErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/FormatError().(err, false, true))
1832 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(`err.Error() should match yaml.FormatError(err, false, true)`)
1833 }
1834
1835 // TODO: properly check if errors are colored/have source
1836 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("%s", err)
1837 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("%s", yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.FormatErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/FormatError().(err, true, false))
1838 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("%s", yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.FormatErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/FormatError().(err, false, true))
1839 t.Logfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Logf().("%s", yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.FormatErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/FormatError().(err, true, true))
1840 }
1841
1842 func TestDecoder_JSONTagsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_JSONTags().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1843 var v struct {
1844 A string `json:"a_json"` // no YAML tag
1845 B string `json:"b_json" yaml:"b_yaml"` // both tags
1846 }
1847
1848 const src = `---
1849 a_json: a_json_value
1850 b_json: b_json_value
1851 b_yaml: b_yaml_value
1852 `
1853 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(src)).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1854 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().(`parsing should succeed: %s`, err)
1855 }
1856
1857 if v.A != "a_json_value" {
1858 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.A should be `a_json_value`, got `%s`", v.A)
1859 }
1860
1861 if v.B != "b_yaml_value" {
1862 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.B should be `b_yaml_value`, got `%s`", v.B)
1863 }
1864 }
1865
1866 func TestDecoder_DisallowUnknownFieldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_DisallowUnknownField().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1867 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("different level keys with same name", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1868 var v struct {
1869 C Childscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child# `yaml:"c"`
1870 }
1871 yml := `---
1872 b: 1
1873 c:
1874 b: 1
1875 `
1876
1877 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml), yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.DisallowUnknownFieldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DisallowUnknownField().()).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v)
1878 if err == nil {
1879 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("error expected")
1880 }
1881 })
1882 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("inline", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1883 var v struct {
1884 *Childscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child# `yaml:",inline"`
1885 A string `yaml:"a"`
1886 }
1887 yml := `---
1888 a: a
1889 b: 1
1890 `
1891
1892 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml), yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.DisallowUnknownFieldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DisallowUnknownField().()).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1893 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().(`parsing should succeed: %s`, err)
1894 }
1895 if v.A != "a" {
1896 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.A should be `a`, got `%s`", v.A)
1897 }
1898 if v.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#B. != 1 {
1899 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.B should be 1, got %d", v.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#B.)
1900 }
1901 if v.Cscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#C. != 0 {
1902 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.C should be 0, got %d", v.Cscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#C.)
1903 }
1904 })
1905 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("list", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1906 type C struct {
1907 Childscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child# `yaml:",inline"`
1908 }
1909
1910 var v struct {
1911 Children []C `yaml:"children"`
1912 }
1913
1914 yml := `---
1915 children:
1916 - b: 1
1917 - b: 2
1918 `
1919
1920 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml), yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.DisallowUnknownFieldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DisallowUnknownField().()).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1921 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().(`parsing should succeed: %s`, err)
1922 }
1923
1924 if len(v.Children) != 2 {
1925 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().(`len(v.Children) should be 2, got %d`, len(v.Children))
1926 }
1927
1928 if v.Children[0].Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#B. != 1 {
1929 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().(`v.Children[0].B should be 1, got %d`, v.Children[0].Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#B.)
1930 }
1931
1932 if v.Children[1].Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#B. != 2 {
1933 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().(`v.Children[1].B should be 2, got %d`, v.Children[1].Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Child#B.)
1934 }
1935 })
1936 }
1937
1938 func TestDecoder_AllowDuplicateMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_AllowDuplicateMapKey().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1939 yml := `
1940 a: b
1941 a: c
1942 `
1943 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("map", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1944 var v map[string]string
1945 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml), yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.AllowDuplicateMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/AllowDuplicateMapKey().()).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1946 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
1947 }
1948 })
1949 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("struct", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1950 var v struct {
1951 A string
1952 }
1953 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml), yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.AllowDuplicateMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/AllowDuplicateMapKey().()).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
1954 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
1955 }
1956 })
1957 }
1958
1959 func TestDecoder_DefaultValuesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_DefaultValues().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
1960 v := struct {
1961 A string `yaml:"a"`
1962 B string `yaml:"b"`
1963 c string // private
1964 D struct {
1965 E string `yaml:"e"`
1966 F struct {
1967 G string `yaml:"g"`
1968 } `yaml:"f"`
1969 H struct {
1970 I string `yaml:"i"`
1971 } `yaml:",inline"`
1972 } `yaml:"d"`
1973 J struct {
1974 K string `yaml:"k"`
1975 L struct {
1976 M string `yaml:"m"`
1977 } `yaml:"l"`
1978 N struct {
1979 O string `yaml:"o"`
1980 } `yaml:",inline"`
1981 } `yaml:",inline"`
1982 P struct {
1983 Q string `yaml:"q"`
1984 R struct {
1985 S string `yaml:"s"`
1986 } `yaml:"r"`
1987 T struct {
1988 U string `yaml:"u"`
1989 } `yaml:",inline"`
1990 } `yaml:"p"`
1991 V struct {
1992 W string `yaml:"w"`
1993 X struct {
1994 Y string `yaml:"y"`
1995 } `yaml:"x"`
1996 Z struct {
1997 Ä string `yaml:"ä"`
1998 } `yaml:",inline"`
1999 } `yaml:",inline"`
2000 }{
2001 B: "defaultBValue",
2002 c: "defaultCValue",
2003 }
2004
2005 v.D.E = "defaultEValue"
2006 v.D.F.G = "defaultGValue"
2007 v.D.H.I = "defaultIValue"
2008 v.J.K = "defaultKValue"
2009 v.J.L.M = "defaultMValue"
2010 v.J.N.O = "defaultOValue"
2011 v.P.R.S = "defaultSValue"
2012 v.P.T.U = "defaultUValue"
2013 v.V.X.Y = "defaultYValue"
2014 v.V.Z.Ä = "defaultÄValue"
2015
2016 const src = `---
2017 a: a_value
2018 p:
2019 q: q_value
2020 w: w_value
2021 `
2022 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(src)).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
2023 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().(`parsing should succeed: %s`, err)
2024 }
2025 if v.A != "a_value" {
2026 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.A should be `a_value`, got `%s`", v.A)
2027 }
2028
2029 if v.B != "defaultBValue" {
2030 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.B should be `defaultValue`, got `%s`", v.B)
2031 }
2032
2033 if v.c != "defaultCValue" {
2034 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.c should be `defaultCValue`, got `%s`", v.c)
2035 }
2036
2037 if v.D.E != "defaultEValue" {
2038 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.D.E should be `defaultEValue`, got `%s`", v.D.E)
2039 }
2040
2041 if v.D.F.G != "defaultGValue" {
2042 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.D.F.G should be `defaultGValue`, got `%s`", v.D.F.G)
2043 }
2044
2045 if v.D.H.I != "defaultIValue" {
2046 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.D.H.I should be `defaultIValue`, got `%s`", v.D.H.I)
2047 }
2048
2049 if v.J.K != "defaultKValue" {
2050 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.J.K should be `defaultKValue`, got `%s`", v.J.K)
2051 }
2052
2053 if v.J.L.M != "defaultMValue" {
2054 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.J.L.M should be `defaultMValue`, got `%s`", v.J.L.M)
2055 }
2056
2057 if v.J.N.O != "defaultOValue" {
2058 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.J.N.O should be `defaultOValue`, got `%s`", v.J.N.O)
2059 }
2060
2061 if v.P.Q != "q_value" {
2062 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.P.Q should be `q_value`, got `%s`", v.P.Q)
2063 }
2064
2065 if v.P.R.S != "defaultSValue" {
2066 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.P.R.S should be `defaultSValue`, got `%s`", v.P.R.S)
2067 }
2068
2069 if v.P.T.U != "defaultUValue" {
2070 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.P.T.U should be `defaultUValue`, got `%s`", v.P.T.U)
2071 }
2072
2073 if v.V.W != "w_value" {
2074 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.V.W should be `w_value`, got `%s`", v.V.W)
2075 }
2076
2077 if v.V.X.Y != "defaultYValue" {
2078 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.V.X.Y should be `defaultYValue`, got `%s`", v.V.X.Y)
2079 }
2080
2081 if v.V.Z.Ä != "defaultÄValue" {
2082 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("v.V.Z.Ä should be `defaultÄValue`, got `%s`", v.V.Z.Ä)
2083 }
2084 }
2085
2086 func ExampleUnmarshal_yAMLTagsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/ExampleUnmarshal_yAMLTags().() {
2087 yml := `---
2088 foo: 1
2089 bar: c
2090 A: 2
2091 B: d
2092 `
2093 var v struct {
2094 A int `yaml:"foo" json:"A"`
2095 B string `yaml:"bar" json:"B"`
2096 }
2097 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
2098 logscip-go gomod github.com/golang/go/src go1.21.0 log/.Fatalscip-go gomod github.com/golang/go/src go1.21.0 log/Fatal().(err)
2099 }
2100 fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.21.0 fmt/Println().(v.A)
2101 fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.21.0 fmt/Println().(v.B)
2102 // OUTPUT:
2103 // 1
2104 // c
2105 }
2106
2107 type useJSONUnmarshalerTestscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/useJSONUnmarshalerTest# struct {
2108 sscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/useJSONUnmarshalerTest#s. string
2109 }
2110
2111 func (t *useJSONUnmarshalerTestscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/useJSONUnmarshalerTest#) UnmarshalJSONscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/useJSONUnmarshalerTest#UnmarshalJSON().(b []byte) error {
2112 s, err := strconvscip-go gomod github.com/golang/go/src go1.21.0 strconv/.Unquotescip-go gomod github.com/golang/go/src go1.21.0 strconv/Unquote().(string(b))
2113 if err != nil {
2114 return err
2115 }
2116 t.sscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/useJSONUnmarshalerTest#s. = s
2117 return nil
2118 }
2119
2120 func TestDecoder_UseJSONUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_UseJSONUnmarshaler().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2121 var v useJSONUnmarshalerTestscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/useJSONUnmarshalerTest#
2122 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().([]byte(`"a"`), &v, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UseJSONUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UseJSONUnmarshaler().()); err != nil {
2123 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2124 }
2125 if v.sscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/useJSONUnmarshalerTest#s. != "a" {
2126 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("unexpected decoded value: %s", v.sscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/useJSONUnmarshalerTest#s.)
2127 }
2128 }
2129
2130 func TestDecoder_CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_CustomUnmarshaler().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2131 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("override struct type", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2132 type T struct {
2133 Foo string `yaml:"foo"`
2134 }
2135 src := []byte(`foo: "bar"`)
2136 var v T
2137 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().(src, &v, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshaler().[T](func(dst *T, b []byte) error {
2138 if !bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.21.0 bytes/Equal().(src, b) {
2139 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to get decode target buffer. expected %q but got %q", src, b)
2140 }
2141 var v T
2142 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, &v); err != nil {
2143 return err
2144 }
2145 if v.Foo != "bar" {
2146 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode")
2147 }
2148 dst.Foo = "bazbaz" // assign another value to target
2149 return nil
2150 })); err != nil {
2151 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2152 }
2153 if v.Foo != "bazbaz" {
2154 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to switch to custom unmarshaler. got: %v", v.Foo)
2155 }
2156 })
2157 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("override bytes type", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2158 type T struct {
2159 Foo []byte `yaml:"foo"`
2160 }
2161 src := []byte(`foo: "bar"`)
2162 var v T
2163 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().(src, &v, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshaler().[[]byte](func(dst *[]byte, b []byte) error {
2164 if !bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.21.0 bytes/Equal().(b, []byte(`"bar"`)) {
2165 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to get target buffer: %q", b)
2166 }
2167 *dst = []byte("bazbaz")
2168 return nil
2169 })); err != nil {
2170 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2171 }
2172 if !bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.21.0 bytes/Equal().(v.Foo, []byte("bazbaz")) {
2173 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to switch to custom unmarshaler. got: %q", v.Foo)
2174 }
2175 })
2176 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("override bytes type with context", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2177 type T struct {
2178 Foo []byte `yaml:"foo"`
2179 }
2180 src := []byte(`foo: "bar"`)
2181 var v T
2182 ctx := contextscip-go gomod github.com/golang/go/src go1.21.0 context/.WithValuescip-go gomod github.com/golang/go/src go1.21.0 context/WithValue().(contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Backgroundscip-go gomod github.com/golang/go/src go1.21.0 context/Background().(), "plop", uint(42))
2183 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalContext().(ctx, src, &v, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CustomUnmarshalerContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshalerContext().[[]byte](func(ctx contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Contextscip-go gomod github.com/golang/go/src go1.21.0 context/Context#, dst *[]byte, b []byte) error {
2184 if !bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.21.0 bytes/Equal().(b, []byte(`"bar"`)) {
2185 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to get target buffer: %q", b)
2186 }
2187 if ctx.Valuescip-go gomod github.com/golang/go/src go1.21.0 context/Context#Value().("plop") != uint(42) {
2188 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("context value is not correct")
2189 }
2190 *dst = []byte("bazbaz")
2191 return nil
2192 })); err != nil {
2193 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2194 }
2195 if !bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.21.0 bytes/Equal().(v.Foo, []byte("bazbaz")) {
2196 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to switch to custom unmarshaler. got: %q", v.Foo)
2197 }
2198 })
2199 }
2200
2201 type unmarshalContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalContext# struct {
2202 vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalContext#v. int
2203 }
2204
2205 func (c *unmarshalContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalContext#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalContext#UnmarshalYAML().(ctx contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Contextscip-go gomod github.com/golang/go/src go1.21.0 context/Context#, b []byte) error {
2206 v, ok := ctx.Valuescip-go gomod github.com/golang/go/src go1.21.0 context/Context#Value().("k").(int)
2207 if !ok {
2208 return errorsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/New.("cannot get valid context")
2209 }
2210 if v != 1 {
2211 return errorsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/New.("cannot get valid context")
2212 }
2213 if string(b) != "1" {
2214 return errorsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/New.("cannot get valid bytes")
2215 }
2216 c.vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalContext#v. = v
2217 return nil
2218 }
2219
2220 func Test_UnmarshalerContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/Test_UnmarshalerContext().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2221 ctx := contextscip-go gomod github.com/golang/go/src go1.21.0 context/.WithValuescip-go gomod github.com/golang/go/src go1.21.0 context/WithValue().(contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Backgroundscip-go gomod github.com/golang/go/src go1.21.0 context/Background().(), "k", 1)
2222 var v unmarshalContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalContext#
2223 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalContext().(ctx, []byte(`1`), &v); err != nil {
2224 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
2225 }
2226 if v.vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalContext#v. != 1 {
2227 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("cannot call UnmarshalYAML")
2228 }
2229 }
2230
2231 func TestDecoder_DecodeFromNodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_DecodeFromNode().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2232 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("has reference", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2233 str := `
2234 anchor: &map
2235 text: hello
2236 map: *map`
2237 var buf bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.21.0 bytes/Buffer#
2238 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(&buf)
2239 f, err := parserscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/parser`/.ParseBytesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/parser`/ParseBytes().([]byte(str), 0)
2240 if err != nil {
2241 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to parse: %s", err)
2242 }
2243 type T struct {
2244 Map map[string]string
2245 }
2246 var v T
2247 if err := dec.DecodeFromNodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#DecodeFromNode().(f.Docsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/File#Docs.[0].Bodyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/DocumentNode#Body., &v); err != nil {
2248 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode: %s", err)
2249 }
2250 actual := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%+v", v)
2251 expect := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%+v", T{map[string]string{"text": "hello"}})
2252 if actual != expect {
2253 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("actual=[%s], expect=[%s]", actual, expect)
2254 }
2255 })
2256 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("with reference option", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2257 anchor := stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(`
2258 map: &map
2259 text: hello`)
2260 var buf bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.21.0 bytes/Buffer#
2261 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(&buf, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.ReferenceReadersscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ReferenceReaders().(anchor))
2262 f, err := parserscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/parser`/.ParseBytesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/parser`/ParseBytes().([]byte("map: *map"), 0)
2263 if err != nil {
2264 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to parse: %s", err)
2265 }
2266 type T struct {
2267 Map map[string]string
2268 }
2269 var v T
2270 if err := dec.DecodeFromNodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#DecodeFromNode().(f.Docsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/File#Docs.[0].Bodyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/DocumentNode#Body., &v); err != nil {
2271 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode: %s", err)
2272 }
2273 actual := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%+v", v)
2274 expect := fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%+v", T{map[string]string{"text": "hello"}})
2275 if actual != expect {
2276 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("actual=[%s], expect=[%s]", actual, expect)
2277 }
2278 })
2279 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("value is not pointer", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2280 var buf bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.21.0 bytes/Buffer#
2281 var v bool
2282 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(&buf).DecodeFromNodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#DecodeFromNode().(nil, v)
2283 if !errorsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/.Isscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/Is.(err, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.ErrDecodeRequiredPointerTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/ErrDecodeRequiredPointerType.) {
2284 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("unexpected error: %s", err)
2285 }
2286 })
2287 }
2288
2289 func TestCommentWithCustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestCommentWithCustomUnmarshaler().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2290 type T struct{}
2291
2292 for idx, test := range []string{
2293 `
2294 foo:
2295 # comment
2296 - a: b
2297 `,
2298 `
2299 foo: # comment
2300 bar: 1
2301 baz: true
2302 `,
2303 } {
2304 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(strconvscip-go gomod github.com/golang/go/src go1.21.0 strconv/.Itoascip-go gomod github.com/golang/go/src go1.21.0 strconv/Itoa().(idx), func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2305 m := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CommentMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentMap#{}
2306 var v T
2307 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().(
2308 []byte(test),
2309 &v,
2310 yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CommentToMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentToMap().(m),
2311 yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshaler().[T](func(dst *T, b []byte) error {
2312 expected := bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Trimscip-go gomod github.com/golang/go/src go1.21.0 bytes/Trim().([]byte(test), "\n")
2313 if !bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.21.0 bytes/Equal().(b, expected) {
2314 return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Errorf().("failed to decode: got\n%s", string(test))
2315 }
2316 return nil
2317 }),
2318 ); err != nil {
2319 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2320 }
2321 })
2322 }
2323 }
2324
2325 func ExampleUnmarshal_jSONTagsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/ExampleUnmarshal_jSONTags().() {
2326 yml := `---
2327 foo: 1
2328 bar: c
2329 `
2330 var v struct {
2331 A int `json:"foo"`
2332 B string `json:"bar"`
2333 }
2334 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
2335 logscip-go gomod github.com/golang/go/src go1.21.0 log/.Fatalscip-go gomod github.com/golang/go/src go1.21.0 log/Fatal().(err)
2336 }
2337 fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.21.0 fmt/Println().(v.A)
2338 fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.21.0 fmt/Println().(v.B)
2339 // OUTPUT:
2340 // 1
2341 // c
2342 }
2343
2344 func ExampleDecoder_Decode_disallowUnknownFieldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/ExampleDecoder_Decode_disallowUnknownField().() {
2345 var v struct {
2346 A string `yaml:"simple"`
2347 C string `yaml:"complicated"`
2348 }
2349
2350 const src = `---
2351 simple: string
2352 unknown: string
2353 `
2354 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(src), yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.DisallowUnknownFieldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/DisallowUnknownField().()).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v)
2355 fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Printfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Printf().("%v\n", err)
2356
2357 // OUTPUT:
2358 // [3:1] unknown field "unknown"
2359 // 1 | ---
2360 // 2 | simple: string
2361 // > 3 | unknown: string
2362 // ^
2363 }
2364
2365 func ExampleNodeToValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/ExampleNodeToValue().() {
2366 f, err := parserscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/parser`/.ParseBytesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/parser`/ParseBytes().([]byte("text: node example"), 0)
2367 if err != nil {
2368 panic(err)
2369 }
2370 var v struct {
2371 Text string `yaml:"text"`
2372 }
2373 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NodeToValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NodeToValue().(f.Docsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/File#Docs.[0].Bodyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/DocumentNode#Body., &v); err != nil {
2374 panic(err)
2375 }
2376 fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.21.0 fmt/Println().(v.Text)
2377 // OUTPUT:
2378 // node example
2379 }
2380
2381 type unmarshalableYAMLStringValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableYAMLStringValue# string
2382
2383 func (v *unmarshalableYAMLStringValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableYAMLStringValue#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableYAMLStringValue#UnmarshalYAML().(b []byte) error {
2384 var s string
2385 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, &s); err != nil {
2386 return err
2387 }
2388 *v = unmarshalableYAMLStringValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableYAMLStringValue#(s)
2389 return nil
2390 }
2391
2392 type unmarshalableTextStringValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableTextStringValue# string
2393
2394 func (v *unmarshalableTextStringValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableTextStringValue#) UnmarshalTextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableTextStringValue#UnmarshalText().(b []byte) error {
2395 *v = unmarshalableTextStringValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableTextStringValue#(string(b))
2396 return nil
2397 }
2398
2399 type unmarshalableStringContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer# struct {
2400 Ascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#A. unmarshalableYAMLStringValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableYAMLStringValue# `yaml:"a"`
2401 Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#B. unmarshalableTextStringValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableTextStringValue# `yaml:"b"`
2402 }
2403
2404 func TestUnmarshalableStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestUnmarshalableString().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2405 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("empty string", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2406 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2407 yml := `
2408 a: ""
2409 b: ""
2410 `
2411 var container unmarshalableStringContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#
2412 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &container); err != nil {
2413 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2414 }
2415 if container.Ascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#A. != "" {
2416 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected empty string, but %q is set", container.Ascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#A.)
2417 }
2418 if container.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#B. != "" {
2419 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected empty string, but %q is set", container.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#B.)
2420 }
2421 })
2422 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("filled string", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2423 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2424 yml := `
2425 a: "aaa"
2426 b: "bbb"
2427 `
2428 var container unmarshalableStringContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#
2429 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &container); err != nil {
2430 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2431 }
2432 if container.Ascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#A. != "aaa" {
2433 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected \"aaa\", but %q is set", container.Ascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#A.)
2434 }
2435 if container.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#B. != "bbb" {
2436 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected \"bbb\", but %q is set", container.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#B.)
2437 }
2438 })
2439 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("single-quoted string", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2440 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2441 yml := `
2442 a: 'aaa'
2443 b: 'bbb'
2444 `
2445 var container unmarshalableStringContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#
2446 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &container); err != nil {
2447 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2448 }
2449 if container.Ascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#A. != "aaa" {
2450 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected \"aaa\", but %q is set", container.Ascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#A.)
2451 }
2452 if container.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#B. != "bbb" {
2453 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected \"aaa\", but %q is set", container.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#B.)
2454 }
2455 })
2456 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("literal", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2457 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2458 yml := `
2459 a: |
2460 a
2461 b
2462 c
2463 b: |
2464 a
2465 b
2466 c
2467 `
2468 var container unmarshalableStringContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#
2469 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &container); err != nil {
2470 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2471 }
2472 if container.Ascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#A. != "a\nb\nc\n" {
2473 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected \"a\nb\nc\n\", but %q is set", container.Ascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#A.)
2474 }
2475 if container.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#B. != "a\nb\nc\n" {
2476 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected \"a\nb\nc\n\", but %q is set", container.Bscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableStringContainer#B.)
2477 }
2478 })
2479 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("anchor/alias", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2480 yml := `
2481 a: &x 1
2482 b: *x
2483 c: &y hello
2484 d: *y
2485 `
2486 var v struct {
2487 A, B, C, D unmarshalableTextStringValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableTextStringValue#
2488 }
2489 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
2490 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2491 }
2492 if v.A != "1" {
2493 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to unmarshal")
2494 }
2495 if v.B != "1" {
2496 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to unmarshal")
2497 }
2498 if v.C != "hello" {
2499 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to unmarshal")
2500 }
2501 if v.D != "hello" {
2502 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to unmarshal")
2503 }
2504 })
2505 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("net.IP", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2506 yml := `
2507 a: &a 127.0.0.1
2508 b: *a
2509 `
2510 var v struct {
2511 A, B netscip-go gomod github.com/golang/go/src go1.21.0 net/.IPscip-go gomod github.com/golang/go/src go1.21.0 net/IP#
2512 }
2513 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
2514 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2515 }
2516 if v.A.Stringscip-go gomod github.com/golang/go/src go1.21.0 net/IP#String().() != netscip-go gomod github.com/golang/go/src go1.21.0 net/.IPv4scip-go gomod github.com/golang/go/src go1.21.0 net/IPv4().(127, 0, 0, 1).Stringscip-go gomod github.com/golang/go/src go1.21.0 net/IP#String().() {
2517 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to unmarshal")
2518 }
2519 if v.B.Stringscip-go gomod github.com/golang/go/src go1.21.0 net/IP#String().() != netscip-go gomod github.com/golang/go/src go1.21.0 net/.IPv4scip-go gomod github.com/golang/go/src go1.21.0 net/IPv4().(127, 0, 0, 1).Stringscip-go gomod github.com/golang/go/src go1.21.0 net/IP#String().() {
2520 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to unmarshal")
2521 }
2522 })
2523 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("quoted map keys", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2524 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2525 yml := `
2526 a:
2527 "b" : 2
2528 'c': true
2529 `
2530 var v struct {
2531 A struct {
2532 B int
2533 C bool
2534 }
2535 }
2536 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
2537 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2538 }
2539 if v.A.B != 2 {
2540 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected a.b to equal 2 but was %d", v.A.B)
2541 }
2542 if !v.A.C {
2543 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected a.c to be true but was false")
2544 }
2545 })
2546 }
2547
2548 type unmarshalablePtrStringContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrStringContainer# struct {
2549 Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrStringContainer#V. *string `yaml:"value"`
2550 }
2551
2552 func TestUnmarshalablePtrStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestUnmarshalablePtrString().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2553 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("empty string", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2554 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2555 var container unmarshalablePtrStringContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrStringContainer#
2556 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`value: ""`), &container); err != nil {
2557 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2558 }
2559 if container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrStringContainer#V. == nil || *container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrStringContainer#V. != "" {
2560 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected empty string, but %q is set", *container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrStringContainer#V.)
2561 }
2562 })
2563
2564 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("null", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2565 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2566 var container unmarshalablePtrStringContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrStringContainer#
2567 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`value: null`), &container); err != nil {
2568 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2569 }
2570 if container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrStringContainer#V. != (*string)(nil) {
2571 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected nil, but %q is set", *container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrStringContainer#V.)
2572 }
2573 })
2574 }
2575
2576 type unmarshalableIntValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntValue# int
2577
2578 func (v *unmarshalableIntValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntValue#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntValue#UnmarshalYAML().(raw []byte) error {
2579 i, err := strconvscip-go gomod github.com/golang/go/src go1.21.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.21.0 strconv/Atoi().(string(raw))
2580 if err != nil {
2581 return err
2582 }
2583 *v = unmarshalableIntValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntValue#(i)
2584 return nil
2585 }
2586
2587 type unmarshalableIntContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer# struct {
2588 Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#V. unmarshalableIntValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntValue# `yaml:"value"`
2589 }
2590
2591 func TestUnmarshalableIntscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestUnmarshalableInt().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2592 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("empty int", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2593 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2594 var container unmarshalableIntContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#
2595 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(``), &container); err != nil {
2596 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2597 }
2598 if container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#V. != 0 {
2599 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected empty int, but %d is set", container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#V.)
2600 }
2601 })
2602 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("filled int", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2603 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2604 var container unmarshalableIntContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#
2605 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`value: 9`), &container); err != nil {
2606 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2607 }
2608 if container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#V. != 9 {
2609 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected 9, but %d is set", container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#V.)
2610 }
2611 })
2612 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("filled number", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2613 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2614 var container unmarshalableIntContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#
2615 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`value: 9`), &container); err != nil {
2616 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2617 }
2618 if container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#V. != 9 {
2619 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected 9, but %d is set", container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalableIntContainer#V.)
2620 }
2621 })
2622 }
2623
2624 type unmarshalablePtrIntContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrIntContainer# struct {
2625 Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrIntContainer#V. *int `yaml:"value"`
2626 }
2627
2628 func TestUnmarshalablePtrIntscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestUnmarshalablePtrInt().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2629 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("empty int", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2630 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2631 var container unmarshalablePtrIntContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrIntContainer#
2632 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`value: 0`), &container); err != nil {
2633 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2634 }
2635 if container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrIntContainer#V. == nil || *container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrIntContainer#V. != 0 {
2636 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected 0, but %q is set", *container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrIntContainer#V.)
2637 }
2638 })
2639
2640 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("null", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2641 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
2642 var container unmarshalablePtrIntContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrIntContainer#
2643 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`value: null`), &container); err != nil {
2644 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
2645 }
2646 if container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrIntContainer#V. != (*int)(nil) {
2647 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected nil, but %q is set", *container.Vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalablePtrIntContainer#V.)
2648 }
2649 })
2650 }
2651
2652 type literalContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/literalContainer# struct {
2653 vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/literalContainer#v. string
2654 }
2655
2656 func (c *literalContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/literalContainer#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/literalContainer#UnmarshalYAML().(v []byte) error {
2657 var lit string
2658 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(v, &lit); err != nil {
2659 return err
2660 }
2661 c.vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/literalContainer#v. = lit
2662 return nil
2663 }
2664
2665 func TestDecode_Literalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecode_Literal().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2666 yml := `---
2667 value: |
2668 {
2669 "key": "value"
2670 }
2671 `
2672 var v map[string]*literalContainerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/literalContainer#
2673 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
2674 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %+v", err)
2675 }
2676 if v["value"] == nil {
2677 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to unmarshal literal with bytes unmarshaler")
2678 }
2679 if v["value"].vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/literalContainer#v. == "" {
2680 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to unmarshal literal with bytes unmarshaler")
2681 }
2682 }
2683
2684 func TestDecoder_UseOrderedMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_UseOrderedMap().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2685 yml := `
2686 a: b
2687 c: d
2688 e:
2689 f: g
2690 h: i
2691 j: k
2692 `
2693 var v interface{}
2694 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml), yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UseOrderedMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UseOrderedMap().()).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
2695 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
2696 }
2697 if _, ok := v.(yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.MapSlicescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapSlice#); !ok {
2698 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to convert to ordered map: %T", v)
2699 }
2700 bytes, err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Marshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Marshal().(v)
2701 if err != nil {
2702 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
2703 }
2704 if string(yml) != "\n"+string(bytes) {
2705 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected:[%s] actual:[%s]", string(yml), "\n"+string(bytes))
2706 }
2707 }
2708
2709 func TestDecoder_Streamscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_Stream().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2710 yml := `
2711 ---
2712 a: b
2713 c: d
2714 ---
2715 e: f
2716 g: h
2717 ---
2718 i: j
2719 k: l
2720 `
2721 dec := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(yml))
2722 values := []map[string]string{}
2723 for {
2724 var v map[string]string
2725 if err := dec.Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
2726 if err == ioscip-go gomod github.com/golang/go/src go1.21.0 io/.EOFscip-go gomod github.com/golang/go/src go1.21.0 io/EOF. {
2727 break
2728 }
2729 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
2730 }
2731 values = append(values, v)
2732 }
2733 if len(values) != 3 {
2734 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to stream decoding")
2735 }
2736 if values[0]["a"] != "b" {
2737 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to stream decoding")
2738 }
2739 if values[1]["e"] != "f" {
2740 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to stream decoding")
2741 }
2742 if values[2]["i"] != "j" {
2743 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to stream decoding")
2744 }
2745 }
2746
2747 type unmarshalYAMLWithAliasStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasString# string
2748
2749 func (v *unmarshalYAMLWithAliasStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasString#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasString#UnmarshalYAML().(b []byte) error {
2750 var s string
2751 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, &s); err != nil {
2752 return err
2753 }
2754 *v = unmarshalYAMLWithAliasStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasString#(s)
2755 return nil
2756 }
2757
2758 type unmarshalYAMLWithAliasMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasMap# map[string]interface{}
2759
2760 func (v *unmarshalYAMLWithAliasMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasMap#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasMap#UnmarshalYAML().(b []byte) error {
2761 var m map[string]interface{}
2762 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, &m); err != nil {
2763 return err
2764 }
2765 *v = unmarshalYAMLWithAliasMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasMap#(m)
2766 return nil
2767 }
2768
2769 func TestDecoder_UnmarshalYAMLWithAliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_UnmarshalYAMLWithAlias().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2770 type value struct {
2771 String unmarshalYAMLWithAliasStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasString#
2772 Map unmarshalYAMLWithAliasMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasMap#
2773 }
2774 tests := []struct {
2775 name string
2776 yaml string
2777 expectedValue value
2778 err string
2779 }{
2780 {
2781 name: "ok",
2782 yaml: `
2783 anchors:
2784 w: &w "\"hello\" \"world\""
2785 map: &x
2786 a: b
2787 c: d
2788 d: *w
2789 string: *w
2790 map:
2791 <<: *x
2792 e: f
2793 `,
2794 expectedValue: value{
2795 String: unmarshalYAMLWithAliasStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasString#(`"hello" "world"`),
2796 Map: unmarshalYAMLWithAliasMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalYAMLWithAliasMap#(map[string]interface{}{
2797 "a": "b",
2798 "c": "d",
2799 "d": `"hello" "world"`,
2800 "e": "f",
2801 }),
2802 },
2803 },
2804 {
2805 name: "unknown alias",
2806 yaml: `
2807 anchors:
2808 w: &w "\"hello\" \"world\""
2809 map: &x
2810 a: b
2811 c: d
2812 d: *w
2813 string: *y
2814 map:
2815 <<: *z
2816 e: f
2817 `,
2818 err: `could not find alias "y"`,
2819 },
2820 }
2821
2822 for _, test := range tests {
2823 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2824 var v value
2825 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(test.yaml), &v)
2826
2827 if test.err != "" {
2828 if err == nil {
2829 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to error")
2830 }
2831 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), test.err) {
2832 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected error message: %s to contain: %s", err.Error(), test.err)
2833 }
2834 } else {
2835 if err != nil {
2836 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
2837 }
2838 if !reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21.0 reflect/DeepEqual().(test.expectedValue, v) {
2839 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("non matching values:\nexpected[%s]\ngot [%s]", test.expectedValue, v)
2840 }
2841 }
2842 })
2843 }
2844 }
2845
2846 type unmarshalStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalString# string
2847
2848 func (u *unmarshalStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalString#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalString#UnmarshalYAML().(b []byte) error {
2849 *u = unmarshalStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalString#(string(b))
2850 return nil
2851 }
2852
2853 type unmarshalListscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList# struct {
2854 vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#v. []map[string]unmarshalStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalString#
2855 }
2856
2857 func (u *unmarshalListscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#UnmarshalYAML().(b []byte) error {
2858 expected := `
2859 - b: c # comment
2860 # comment
2861 d: | # comment
2862 hello
2863
2864 hello
2865 f: g
2866 - h: i`
2867 actual := "\n" + string(b)
2868 if expected != actual {
2869 return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Errorf().("unexpected bytes: expected [%q] but got [%q]", expected, actual)
2870 }
2871 var v []map[string]unmarshalStringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalString#
2872 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, &v); err != nil {
2873 return err
2874 }
2875 u.vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#v. = v
2876 return nil
2877 }
2878
2879 func TestDecoder_DecodeWithAnchorAnyValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_DecodeWithAnchorAnyValue().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2880 type Config struct {
2881 Env []string `json:"env"`
2882 }
2883
2884 type Schema struct {
2885 Def map[string]any `json:"def"`
2886 Config Config `json:"config"`
2887 }
2888
2889 data := `
2890 def:
2891 myenv: &my_env
2892 - VAR1=1
2893 - VAR2=2
2894 config:
2895 env: *my_env
2896 `
2897
2898 var cfg Schema
2899 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.21.0 strings/NewReader().(data)).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&cfg); err != nil {
2900 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2901 }
2902 if !reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21.0 reflect/DeepEqual().(cfg.Config.Env, []string{"VAR1=1", "VAR2=2"}) {
2903 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode value. actual = %+v", cfg)
2904 }
2905 }
2906
2907 func TestDecoder_UnmarshalBytesWithSeparatedListscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_UnmarshalBytesWithSeparatedList().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2908 yml := `
2909 a:
2910 - b: c # comment
2911 # comment
2912 d: | # comment
2913 hello
2914
2915 hello
2916 f: g
2917 - h: i
2918 `
2919 var v struct {
2920 A unmarshalListscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#
2921 }
2922 cm := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CommentMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentMap#{}
2923 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().([]byte(yml), &v, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CommentToMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentToMap().(cm)); err != nil {
2924 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2925 }
2926 if len(v.A.vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#v.) != 2 {
2927 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %+v", v)
2928 }
2929 if len(v.A.vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#v.[0]) != 3 {
2930 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %+v", v.A.vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#v.[0])
2931 }
2932 if len(v.A.vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#v.[1]) != 1 {
2933 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %+v", v.A.vscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshalList#v.[1])
2934 }
2935 }
2936
2937 func TestDecoder_LiteralWithNewLinescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_LiteralWithNewLine().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2938 type A struct {
2939 Node string `yaml:"b"`
2940 LastNode string `yaml:"last"`
2941 }
2942 tests := []A{
2943 {
2944 Node: "hello\nworld",
2945 },
2946 {
2947 Node: "hello\nworld\n",
2948 },
2949 {
2950 LastNode: "hello\nworld",
2951 },
2952 {
2953 LastNode: "hello\nworld\n",
2954 },
2955 }
2956 // struct(want) -> Marshal -> Unmarchal -> struct(got)
2957 for _, want := range tests {
2958 bytes, _ := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Marshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Marshal().(want)
2959 got := A{}
2960 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(bytes, &got); err != nil {
2961 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2962 }
2963 if want.Node != got.Node {
2964 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected:%q but got %q", want.Node, got.Node)
2965 }
2966 if want.LastNode != got.LastNode {
2967 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected:%q but got %q", want.LastNode, got.LastNode)
2968 }
2969 }
2970 }
2971
2972 func TestDecoder_TabCharacterAtRightscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_TabCharacterAtRight().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2973 yml := `
2974 - a: [2 , 2]
2975 b: [2 , 2]
2976 c: [2 , 2]`
2977 var v []map[string][]int
2978 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
2979 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
2980 }
2981 if len(v) != 1 {
2982 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %+v", v)
2983 }
2984 if len(v[0]) != 3 {
2985 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %+v", v)
2986 }
2987 }
2988
2989 func TestDecoder_Canonicalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_Canonical().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
2990 yml := `
2991 !!map {
2992 ? !!str "explicit":!!str "entry",
2993 ? !!str "implicit" : !!str "entry",
2994 ? !!null "" : !!null "",
2995 }
2996 `
2997 var v interface{}
2998 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
2999 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
3000 }
3001 m, ok := v.(map[string]interface{})
3002 if !ok {
3003 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode canonical yaml: %+v", v)
3004 }
3005 if m["explicit"] != "entry" {
3006 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode canonical yaml: %+v", m)
3007 }
3008 if m["implicit"] != "entry" {
3009 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode canonical yaml: %+v", m)
3010 }
3011 if m["null"] != nil {
3012 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode canonical yaml: %+v", m)
3013 }
3014 }
3015
3016 func TestDecoder_DecodeFromFilescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_DecodeFromFile().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3017 yml := `
3018 a: b
3019 c: d
3020 `
3021 file, err := parserscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/parser`/.ParseBytesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/parser`/ParseBytes().([]byte(yml), 0)
3022 if err != nil {
3023 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3024 }
3025 var v map[string]string
3026 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.NewDecoderscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/NewDecoder().(file).Decodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Decoder#Decode().(&v); err != nil {
3027 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3028 }
3029 if len(v) != 2 {
3030 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode from ast.File")
3031 }
3032 if v["a"] != "b" {
3033 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode from ast.File")
3034 }
3035 if v["c"] != "d" {
3036 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to decode from ast.File")
3037 }
3038 }
3039
3040 func TestDecoder_DecodeWithNodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoder_DecodeWithNode().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3041 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("abstract node", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3042 type T struct {
3043 Text astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.Nodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/Node# `yaml:"text"`
3044 }
3045 var v T
3046 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`text: hello`), &v); err != nil {
3047 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
3048 }
3049 expected := "hello"
3050 got := v.Text.Stringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/Node#String.()
3051 if expected != got {
3052 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode to ast.Node: expected %s but got %s", expected, got)
3053 }
3054 })
3055 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("concrete node", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3056 type T struct {
3057 Text *astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.StringNodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/StringNode# `yaml:"text"`
3058 }
3059 var v T
3060 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`text: hello`), &v); err != nil {
3061 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
3062 }
3063 expected := "hello"
3064 got := v.Text.Stringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/StringNode#String().()
3065 if expected != got {
3066 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode to ast.Node: expected %s but got %s", expected, got)
3067 }
3068 })
3069 }
3070
3071 func TestRoundtripAnchorAliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestRoundtripAnchorAlias().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3072 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("irreversible", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3073 type foo struct {
3074 K1 string
3075 K2 string
3076 }
3077
3078 type bar struct {
3079 K1 string
3080 K3 string
3081 }
3082
3083 type doc struct {
3084 Foo foo
3085 Bar bar
3086 }
3087 yml := `
3088 foo:
3089 <<: &test-anchor
3090 k1: "One"
3091 k2: "Two"
3092
3093 bar:
3094 <<: *test-anchor
3095 k3: "Three"
3096 `
3097 var v doc
3098 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
3099 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
3100 }
3101 bytes, err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Marshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Marshal().(v)
3102 if err != nil {
3103 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
3104 }
3105 expected := `
3106 foo:
3107 k1: One
3108 k2: Two
3109 bar:
3110 k1: One
3111 k3: Three
3112 `
3113 got := "\n" + string(bytes)
3114 if expected != got {
3115 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected:[%s] but got [%s]", expected, got)
3116 }
3117 })
3118 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("reversible", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3119 type TestAnchor struct {
3120 K1 string
3121 }
3122 type foo struct {
3123 *TestAnchor `yaml:",inline,alias"`
3124 K2 string
3125 }
3126 type bar struct {
3127 *TestAnchor `yaml:",inline,alias"`
3128 K3 string
3129 }
3130 type doc struct {
3131 TestAnchor *TestAnchor `yaml:"test-anchor,anchor"`
3132 Foo foo
3133 Bar bar
3134 }
3135 yml := `
3136 test-anchor: &test-anchor
3137 k1: One
3138 foo:
3139 <<: *test-anchor
3140 k2: Two
3141 bar:
3142 <<: *test-anchor
3143 k3: Three
3144 `
3145 var v doc
3146 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
3147 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
3148 }
3149 bytes, err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Marshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Marshal().(v)
3150 if err != nil {
3151 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("%+v", err)
3152 }
3153 got := "\n" + string(bytes)
3154 if yml != got {
3155 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected:[%s] but got [%s]", yml, got)
3156 }
3157 })
3158 }
3159
3160 func TestDecodeWithSameAnchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecodeWithSameAnchor().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3161 yml := `
3162 a: &a 1
3163 b: &a 2
3164 c: &a 3
3165 d: *a
3166 `
3167 type T struct {
3168 A int
3169 B int
3170 C int
3171 D int
3172 }
3173 var v T
3174 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
3175 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3176 }
3177 if !reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21.0 reflect/DeepEqual().(v, T{A: 1, B: 2, C: 3, D: 3}) {
3178 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode same anchor: %+v", v)
3179 }
3180 }
3181
3182 func TestUnmarshalMapSliceParallelscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestUnmarshalMapSliceParallel().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3183 content := `
3184 steps:
3185 req0:
3186 desc: Get /users/1
3187 req:
3188 /users/1:
3189 get: nil
3190 test: |
3191 current.res.status == 200
3192 req1:
3193 desc: Get /private
3194 req:
3195 /private:
3196 get: nil
3197 test: |
3198 current.res.status == 403
3199 req2:
3200 desc: Get /users
3201 req:
3202 /users:
3203 get: nil
3204 test: |
3205 current.res.status == 200
3206 `
3207 type mappedSteps struct {
3208 Steps yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.MapSlicescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapSlice# `yaml:"steps,omitempty"`
3209 }
3210 for i := 0; i < 100; i++ {
3211 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("i=%d", i), func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3212 t.Parallelscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Parallel().()
3213 for i := 0; i < 10; i++ {
3214 m := mappedSteps{
3215 Steps: yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.MapSlicescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapSlice#{},
3216 }
3217 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(content), &m); err != nil {
3218 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3219 }
3220 for _, s := range m.Steps {
3221 _, ok := s.Valuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/MapItem#Value..(map[string]interface{})
3222 if !ok {
3223 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("unexpected error")
3224 }
3225 }
3226 }
3227 })
3228 }
3229 }
3230
3231 func TestSameNameInineStructscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestSameNameInineStruct().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3232 type X struct {
3233 X float64 `yaml:"x"`
3234 }
3235
3236 type T struct {
3237 X `yaml:",inline"`
3238 }
3239
3240 var v T
3241 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`x: 0.7`), &v); err != nil {
3242 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3243 }
3244 if fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprint().(v.X.X) != "0.7" {
3245 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to decode")
3246 }
3247 }
3248
3249 type unmarshableMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshableMapKey# struct {
3250 Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshableMapKey#Key. string
3251 }
3252
3253 func (mk *unmarshableMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshableMapKey#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshableMapKey#UnmarshalYAML().(b []byte) error {
3254 mk.Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshableMapKey#Key. = string(b)
3255 return nil
3256 }
3257
3258 type testNodeUnmarshalerCtxscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx# struct {
3259 outErrscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#outErr. error
3260 receivedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#received. astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.Nodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/Node#
3261 }
3262
3263 func (u *testNodeUnmarshalerCtxscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#UnmarshalYAML().(ctx contextscip-go gomod github.com/golang/go/src go1.21.0 context/.Contextscip-go gomod github.com/golang/go/src go1.21.0 context/Context#, node astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.Nodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/Node#) error {
3264 if u.outErrscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#outErr. != nil {
3265 return u.outErrscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#outErr.
3266 }
3267
3268 if ctx == nil {
3269 return errorsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/New.("nil context")
3270 }
3271
3272 u.receivedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#received. = node
3273 return nil
3274 }
3275
3276 func TestNodeUnmarshalerContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestNodeUnmarshalerContext().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3277 type testNodeUnmarshalerBody struct {
3278 Root testNodeUnmarshalerCtxscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx# `yaml:"root"`
3279 }
3280
3281 cases := []struct {
3282 name string
3283 expectErr string
3284 src []string
3285 body testNodeUnmarshalerBody
3286 }{
3287 {
3288 name: "should pass node",
3289 src: []string{
3290 "root:",
3291 " foo: bar",
3292 " fizz: buzz",
3293 },
3294 },
3295 {
3296 name: "should pass returned error",
3297 body: testNodeUnmarshalerBody{
3298 Root: testNodeUnmarshalerCtxscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#{
3299 outErrscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#outErr.: errorsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/New.("test error"),
3300 },
3301 },
3302 expectErr: "test error",
3303 src: []string{
3304 "root:",
3305 " foo: bar",
3306 " fizz: buzz",
3307 },
3308 },
3309 }
3310
3311 for _, c := range cases {
3312 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(c.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3313 src := []byte(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.21.0 strings/Join().(c.src, "\n"))
3314 out := c.body
3315 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(src, &out)
3316 if c.expectErr != "" {
3317 if err == nil {
3318 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected error but got nil")
3319 return
3320 }
3321
3322 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), c.expectErr) {
3323 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("error message %q should contain %q", err.Error(), c.expectErr)
3324 }
3325 return
3326 }
3327
3328 expect := struct {
3329 Root astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.Nodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/Node# `yaml:"root"`
3330 }{}
3331 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalContextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalContext().(contextscip-go gomod github.com/golang/go/src go1.21.0 context/.TODOscip-go gomod github.com/golang/go/src go1.21.0 context/TODO().(), src, &expect); err != nil {
3332 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("invalid test yaml:", err)
3333 return
3334 }
3335
3336 if err != nil {
3337 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("unexpected error: %s", err)
3338 }
3339
3340 if !reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21.0 reflect/DeepEqual().(out.Root.receivedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#received., expect.Root) {
3341 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected:\n%#v\n but got:\n%#v", expect.Root, out.Root.receivedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshalerCtx#received.)
3342 }
3343 })
3344 }
3345
3346 }
3347
3348 type testNodeUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler# struct {
3349 outErrscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#outErr. error
3350 receivedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#received. astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.Nodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/Node#
3351 }
3352
3353 func (u *testNodeUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#UnmarshalYAML().(node astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.Nodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/Node#) error {
3354 if u.outErrscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#outErr. != nil {
3355 return u.outErrscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#outErr.
3356 }
3357
3358 u.receivedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#received. = node
3359 return nil
3360 }
3361
3362 func TestNodeUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestNodeUnmarshaler().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3363 type testNodeUnmarshalerBody struct {
3364 Root testNodeUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler# `yaml:"root"`
3365 }
3366
3367 cases := []struct {
3368 name string
3369 expectErr string
3370 src []string
3371 body testNodeUnmarshalerBody
3372 }{
3373 {
3374 name: "should pass node",
3375 src: []string{
3376 "root:",
3377 " foo: bar",
3378 " fizz: buzz",
3379 },
3380 },
3381 {
3382 name: "should pass returned error",
3383 body: testNodeUnmarshalerBody{
3384 Root: testNodeUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#{
3385 outErrscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#outErr.: errorsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/.Newscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/internal/errors`/New.("test error"),
3386 },
3387 },
3388 expectErr: "test error",
3389 src: []string{
3390 "root:",
3391 " foo: bar",
3392 " fizz: buzz",
3393 },
3394 },
3395 }
3396
3397 for _, c := range cases {
3398 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(c.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3399 src := []byte(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.21.0 strings/Join().(c.src, "\n"))
3400 out := c.body
3401 err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(src, &out)
3402 if c.expectErr != "" {
3403 if err == nil {
3404 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected error but got nil")
3405 return
3406 }
3407
3408 if !stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.21.0 strings/Contains().(err.Error(), c.expectErr) {
3409 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("error message %q should contain %q", err.Error(), c.expectErr)
3410 }
3411 return
3412 }
3413
3414 expect := struct {
3415 Root astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.Nodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/Node# `yaml:"root"`
3416 }{}
3417 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(src, &expect); err != nil {
3418 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("invalid test yaml:", err)
3419 return
3420 }
3421
3422 if err != nil {
3423 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("unexpected error: %s", err)
3424 }
3425
3426 if !reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21.0 reflect/DeepEqual().(out.Root.receivedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#received., expect.Root) {
3427 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected:\n%#v\n but got:\n%#v", expect.Root, out.Root.receivedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/testNodeUnmarshaler#received.)
3428 }
3429 })
3430 }
3431
3432 }
3433
3434 func TestMapKeyCustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestMapKeyCustomUnmarshaler().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3435 var m map[unmarshableMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshableMapKey#]string
3436 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(`key: value`), &m); err != nil {
3437 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to unmarshal %v", err)
3438 }
3439 if len(m) != 1 {
3440 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected 1 element in map, but got %d", len(m))
3441 }
3442 val, ok := m[unmarshableMapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshableMapKey#{Keyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/unmarshableMapKey#Key.: "key"}]
3443 if !ok {
3444 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("expected to have element 'key' in map")
3445 }
3446 if val != "value" {
3447 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("expected to have value \"value\", but got %q", val)
3448 }
3449 }
3450
3451 type bytesUnmershalerWithMapAliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/bytesUnmershalerWithMapAlias# struct{}
3452
3453 func (*bytesUnmershalerWithMapAliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/bytesUnmershalerWithMapAlias#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/bytesUnmershalerWithMapAlias#UnmarshalYAML().(b []byte) error {
3454 expected := stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimPrefix().(`
3455 aaaaa:
3456 bbbbb:
3457 bar:
3458 - |
3459 foo
3460 bar
3461 - name: |
3462 foo
3463 bar
3464
3465 `, "\n")
3466 if string(b) != expected {
3467 return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Errorf().("failed to decode: expected:\n[%s]\nbut got:\n[%s]\n", expected, string(b))
3468 }
3469 return nil
3470 }
3471
3472 func TestBytesUnmarshalerWithMapAliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestBytesUnmarshalerWithMapAlias().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3473 yml := `
3474 x-foo: &data
3475 bar:
3476 - |
3477 foo
3478 bar
3479 - name: |
3480 foo
3481 bar
3482
3483 foo:
3484 aaaaa:
3485 bbbbb: *data
3486 `
3487 type T struct {
3488 Foo bytesUnmershalerWithMapAliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/bytesUnmershalerWithMapAlias# `yaml:"foo"`
3489 }
3490 var v T
3491 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
3492 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3493 }
3494 }
3495
3496 func TestBytesUnmarshalerWithEmptyValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestBytesUnmarshalerWithEmptyValue().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3497 type T struct{}
3498
3499 unmarshaler := func(dst *T, b []byte) error {
3500 var v any
3501 return yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, &v)
3502 }
3503
3504 yml := `
3505 map: &m {}
3506 seq: &seq []
3507 foo: # comment
3508 bar: *m
3509 baz: *seq
3510 `
3511 m := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CommentMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentMap#{}
3512 var v T
3513 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().(
3514 []byte(yml),
3515 &v,
3516 yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CommentToMapscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CommentToMap().(m),
3517 yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshaler().[T](unmarshaler),
3518 ); err != nil {
3519 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3520 }
3521 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().(
3522 []byte(yml),
3523 &v,
3524 yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshaler().[T](unmarshaler),
3525 ); err != nil {
3526 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3527 }
3528
3529 }
3530
3531 func TestIssue650scip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestIssue650().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3532 type Disk struct {
3533 Name string `yaml:"name"`
3534 Format *bool `yaml:"format"`
3535 }
3536
3537 type Sample struct {
3538 Disks []Disk `yaml:"disks"`
3539 }
3540
3541 unmarshalDisk := func(dst *Disk, b []byte) error {
3542 var s string
3543 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, &s); err == nil {
3544 *dst = Disk{Name: s}
3545 return nil
3546 }
3547 return yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, dst)
3548 }
3549
3550 data := []byte(`
3551 disks:
3552 - name: foo
3553 format: true
3554 `)
3555
3556 var sample Sample
3557 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().(data, &sample, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshaler().[Disk](unmarshalDisk)); err != nil {
3558 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3559 }
3560 }
3561
3562 func TestBytesUnmarshalerWithLiteralscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestBytesUnmarshalerWithLiteral().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3563 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("map value", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3564 type Literal string
3565
3566 unmarshalLit := func(dst *Literal, b []byte) error {
3567 var s string
3568 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, &s); err != nil {
3569 return err
3570 }
3571 *dst = Literal(s)
3572 return nil
3573 }
3574
3575 data := []byte(`
3576 - name: |
3577 foo
3578 bar
3579 - name:
3580 |
3581 foo
3582 bar
3583 `)
3584
3585 var v []map[string]Literal
3586 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().(data, &v, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshaler().[Literal](unmarshalLit)); err != nil {
3587 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3588 }
3589 if !reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21.0 reflect/DeepEqual().(v, []map[string]Literal{{"name": "foo\n bar\n"}, {"name": "foo\nbar\n"}}) {
3590 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to get decoded value. got: %q", v)
3591 }
3592 })
3593 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("sequence value", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3594 type Literal string
3595
3596 unmarshalLit := func(dst *Literal, b []byte) error {
3597 var s string
3598 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().(b, &s); err != nil {
3599 return err
3600 }
3601 *dst = Literal(s)
3602 return nil
3603 }
3604
3605 data := []byte(`
3606 - |
3607 foo
3608 bar
3609 -
3610 |
3611 foo
3612 bar
3613 `)
3614
3615 var v []Literal
3616 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.UnmarshalWithOptionsscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/UnmarshalWithOptions().(data, &v, yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.CustomUnmarshalerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/CustomUnmarshaler().[Literal](unmarshalLit)); err != nil {
3617 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3618 }
3619 if !reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21.0 reflect/DeepEqual().(v, []Literal{"foo\n bar\n", "foo\nbar\n"}) {
3620 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("failed to get decoded value. got: %q", v)
3621 }
3622 })
3623 }
3624
3625 func TestDecoderPreservesDefaultValuesscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecoderPreservesDefaultValues().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3626 type nested struct {
3627 Val string `yaml:"val"`
3628 }
3629
3630 type test struct {
3631 First string `yaml:"first"`
3632 Default nested `yaml:"nested"`
3633 }
3634
3635 yml := `
3636 first: "Test"
3637 nested:
3638 # Just some comment here
3639 # val: "default"
3640 `
3641 v := test{Default: nested{Val: "default"}}
3642 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
3643 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3644 }
3645 if v.Default.Val != "default" {
3646 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("decoder doesn't preserve struct defaults")
3647 }
3648 }
3649
3650 func TestDecodeErrorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestDecodeError().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3651 tests := []struct {
3652 name string
3653 source string
3654 }{
3655 {
3656 name: "duplicated map key name with anchor-alias",
3657 source: "&0: *0\n*0:\n*0:",
3658 },
3659 }
3660 for _, test := range tests {
3661 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3662 var v any
3663 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(test.source), &v); err == nil {
3664 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("cannot catch decode error")
3665 }
3666 })
3667 }
3668 }
3669
3670 func TestIssue617scip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestIssue617().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3671 data := `
3672 a: !Not [!Equals [!Ref foo, 'bar']]
3673 `
3674 var v map[string][]any
3675 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(data), &v); err != nil {
3676 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3677 }
3678 if !reflectscip-go gomod github.com/golang/go/src go1.21.0 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21.0 reflect/DeepEqual().(v, map[string][]any{
3679 "a": {[]any{"foo", "bar"}},
3680 }) {
3681 t.Fatalfscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatalf().("found unexpected value: %v", v)
3682 }
3683 }
3684
3685 type issue337Templatescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/issue337Template# struct{}
3686
3687 func (i *issue337Templatescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/issue337Template#) UnmarshalYAMLscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/issue337Template#UnmarshalYAML().(b []byte) error {
3688 expected := stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimPrefixscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimPrefix().(`
3689 |
3690 apiVersion: v1
3691 kind: ConfigMap
3692 metadata:
3693 name: "abc"
3694 namespace: "abc"
3695 data:
3696 foo: FOO
3697 `, "\n")
3698 if !bytesscip-go gomod github.com/golang/go/src go1.21.0 bytes/.Equalscip-go gomod github.com/golang/go/src go1.21.0 bytes/Equal().(b, []byte(expected)) {
3699 return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Errorf().("expected:\n%s\nbut got:\n%s\n", expected, string(b))
3700 }
3701 return nil
3702 }
3703
3704 func TestIssue337scip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestIssue337().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3705 yml := `
3706 releases:
3707 - name: foo
3708 chart: ./raw
3709 values:
3710 - templates:
3711 - |
3712 apiVersion: v1
3713 kind: ConfigMap
3714 metadata:
3715 name: "abc"
3716 namespace: "abc"
3717 data:
3718 foo: FOO
3719 `
3720 type Value struct {
3721 Templates []*issue337Templatescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/issue337Template# `yaml:"templates"`
3722 }
3723 type Release struct {
3724 Values []*Value `yaml:"values"`
3725 }
3726 var v struct {
3727 Releases []*Release `yaml:"releases"`
3728 }
3729 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(yml), &v); err != nil {
3730 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3731 }
3732 }
3733
3734 func TestSetNullValuescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml_test`/TestSetNullValue().(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3735 tests := []struct {
3736 name string
3737 src string
3738 }{
3739 {
3740 name: "empty document",
3741 src: "",
3742 },
3743 {
3744 name: "null value",
3745 src: "null",
3746 },
3747 }
3748 for _, test := range tests {
3749 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3750 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("set null", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3751 var v any
3752 v = 0x1
3753 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(test.src), &v); err != nil {
3754 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3755 }
3756 if v != nil {
3757 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to set nil value")
3758 }
3759 })
3760 t.Runscip-go gomod github.com/golang/go/src go1.21.0 testing/T#Run().("invalid value", func(t *testingscip-go gomod github.com/golang/go/src go1.21.0 testing/.Tscip-go gomod github.com/golang/go/src go1.21.0 testing/T#) {
3761 var v *struct{}
3762 if err := yamlscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/.Unmarshalscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml`/Unmarshal().([]byte(test.src), v); err != nil {
3763 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().(err)
3764 }
3765 if v != nil {
3766 t.Fatalscip-go gomod github.com/golang/go/src go1.21.0 testing/common#Fatal().("failed to set nil value")
3767 }
3768 })
3769 })
3770 }
3771 }