Debian Codegraph @

testdata/unmarshal_errors.yaml

raw symbols SCIP
1 # Copyright 2025 The go-yaml Project Contributors
2 # SPDX-License-Identifier: Apache-2.0
3
4 # Unmarshal error test cases for go-yaml
5 #
6 # Purpose: Tests that the YAML unmarshaler correctly detects and reports errors
7 # for invalid YAML input, malformed syntax, and type conversion failures.
8 #
9 # Format: Test cases use type-as-key format:
10 # - test-type:
11 # name: Test case name
12 # ...
13 #
14 # Test Types:
15 # unmarshal-error - Verifies that unmarshaling produces the expected error message
16 #
17 # Common Keys:
18 # name - Test case name (string)
19 # yaml - Invalid or malformed YAML input (string)
20 # want - Expected error message (string)
21 #
22 # Note:
23 # All tests in this file expect unmarshaling to fail. The 'want' field contains
24 # the exact error message that should be produced.
25
26 - unmarshal-error:
27 name: Invalid float value
28 yaml: 'v: !!float ''error'''
29 want: 'go-yaml load error in resolver at <unknown position>: cannot construct !!str `error` as a !!float'
30
31 - unmarshal-error:
32 name: Incomplete flow sequence
33 yaml: 'v: [A,'
34 want: 'go-yaml load error in parser (while parsing a flow node) at L2.C1: did not find expected node content'
35
36 - unmarshal-error:
37 name: Incomplete flow sequence in list
38 yaml: |
39 v:
40 - [A,
41 want: 'go-yaml load error in parser (while parsing a flow node) at L3.C1: did not find expected node content'
42
43 - unmarshal-error:
44 name: Invalid alias syntax
45 yaml: |
46 a:
47 - b: *,
48 want: 'go-yaml load error in scanner (while scanning an alias) at L2.C6-C7: did not find expected alphabetic or numeric character'
49
50 - unmarshal-error:
51 name: Unknown anchor referenced
52 yaml: "a: *b\n"
53 want: "go-yaml load error in composer at L1.C4: unknown anchor 'b' referenced"
54
55 - unmarshal-error:
56 name: Anchor contains itself
57 yaml: |
58 a: &a
59 b: *a
60 want: "go-yaml load error in composer at L2.C6: anchor 'a' value contains itself"
61
62 - unmarshal-error:
63 name: Block sequence in invalid context
64 yaml: 'value: -'
65 want: 'go-yaml load error in scanner at L1.C8: block sequence entries are not allowed in this context'
66
67 - unmarshal-error:
68 name: Invalid base64 in binary
69 yaml: 'a: !!binary =='
70 want: 'go-yaml load error in constructor at L1.C4: !!binary value contains invalid base64 data'
71
72 - unmarshal-error:
73 name: Slice as map key
74 yaml: '{[.]}'
75 want: "go-yaml load error in constructor at L1.C2: cannot use '[]interface {}{\".\"}' as a map key; try decoding into yaml.Node"
76
77 - unmarshal-error:
78 name: Map as map key
79 yaml: '{{.}}'
80 want: "go-yaml load error in constructor at L1.C2: cannot use 'map[string]interface {}{\".\":interface {}(nil)}' as a map key; try decoding into yaml.Node"
81
82 - unmarshal-error:
83 name: Forward reference to anchor
84 yaml: |
85 b: *a
86 a: &a {c: 1}
87 want: "go-yaml load error in composer at L1.C4: unknown anchor 'a' referenced"
88
89 - unmarshal-error:
90 name: Invalid TAG directive
91 yaml: |
92 %TAG !%79! tag:yaml.org,2002:
93 ---
94 v: !%79!int '1'
95 want: 'go-yaml load error in scanner (while scanning a %TAG directive) at L1.C1-C7: did not find expected whitespace'
96
97 - unmarshal-error:
98 name: Missing colon in mapping (multiline)
99 yaml: |
100 a:
101 1:
102 b
103 2:
104 want: 'go-yaml load error in scanner at L4.C4: mapping values are not allowed in this context'
105
106 - unmarshal-error:
107 name: Missing colon in mapping (inline)
108 yaml: |
109 a: 1
110 b: 2
111 c 2
112 d: 3
113 want: "go-yaml load error in scanner (while scanning a simple key) at L3.C1-L4.C1: could not find expected ':'"
114
115 - unmarshal-error:
116 name: Missing colon after comment and list (Issue 665)
117 yaml: |
118 #
119 -
120 {
121 want: 'go-yaml load error in parser (while parsing a flow node) at L4.C1: did not find expected node content'
122
123 - unmarshal-error:
124 name: Incomplete UTF-8 sequence (Issue 666)
125 yaml: "0: [:!00 \xEF"
126 want: "go-yaml load error in parser (while parsing a flow sequence) at L1.C4-L2.C1: did not find expected ',' or ']'"
127
128 - unmarshal-error:
129 name: Anchor with colon (Issue 109)
130 yaml: |
131 foo: &bar: bar
132 *bar: : quz
133 want: 'go-yaml load error in scanner at L1.C10: mapping values are not allowed in this context'
134
135 - unmarshal-error:
136 name: Excessive aliasing
137 yaml: |
138 a: &a [00,00,00,00,00,00,00,00,00]
139 b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
140 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b]
141 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c]
142 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d]
143 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e]
144 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f]
145 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g]
146 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h]
147 want: 'go-yaml load error in constructor at L2.C17: document contains excessive aliasing'
148
149 # TextUnmarshaler validation errors
150
151 - unmarshal-error:
152 name: Mapping into TextUnmarshaler (value field)
153 type: testStructA_TextUnmarshaler
154 yaml: 'a: {foo: bar}'
155 want: 'yaml: construct errors: line 1: cannot construct !!map into yaml_test.simpleTextUnmarshaler (TextUnmarshaler)'
156
157 - unmarshal-error:
158 name: Sequence into TextUnmarshaler (value field)
159 type: testStructA_TextUnmarshaler
160 yaml: 'a: [foo, bar]'
161 want: 'yaml: construct errors: line 1: cannot construct !!seq into yaml_test.simpleTextUnmarshaler (TextUnmarshaler)'
162
163 - unmarshal-error:
164 name: Mapping into TextUnmarshaler (pointer field)
165 type: testStructA_TextUnmarshalerPtr
166 yaml: 'a: {foo: bar}'
167 want: 'yaml: construct errors: line 1: cannot construct !!map into yaml_test.simpleTextUnmarshaler (TextUnmarshaler)'
168
169 - unmarshal-error:
170 name: Sequence into TextUnmarshaler (pointer field)
171 type: testStructA_TextUnmarshalerPtr
172 yaml: 'a: [foo, bar]'
173 want: 'yaml: construct errors: line 1: cannot construct !!seq into yaml_test.simpleTextUnmarshaler (TextUnmarshaler)'
174
175 - unmarshal-error:
176 name: Mapping into TextUnmarshaler (pointer-pointer field)
177 type: testStructA_TextUnmarshalerPtrPtr
178 yaml: 'a: {foo: bar}'
179 want: 'yaml: construct errors: line 1: cannot construct !!map into yaml_test.simpleTextUnmarshaler (TextUnmarshaler)'
180
181 - unmarshal-error:
182 name: Sequence into TextUnmarshaler (pointer-pointer field)
183 type: testStructA_TextUnmarshalerPtrPtr
184 yaml: 'a: [foo, bar]'
185 want: 'yaml: construct errors: line 1: cannot construct !!seq into yaml_test.simpleTextUnmarshaler (TextUnmarshaler)'