Skip to content

Commit 72fa3cc

Browse files
committed
goccy decoder supports merge maps
1 parent f89605e commit 72fa3cc

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

pkg/yqlib/candidate_node_goccy_yaml.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,13 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
167167
o.Value = aliasNode.Value.String()
168168
o.Alias = anchorMap[o.Value]
169169

170+
case ast.MergeKeyType:
171+
log.Debugf("UnmarshalYAML - a merge key")
172+
o.Kind = ScalarNode
173+
o.Value = "<<"
174+
170175
default:
171-
log.Debugf("UnmarshalYAML - node idea of the type!!")
176+
log.Debugf("UnmarshalYAML - no idea of the type!!\n%v: %v", node.Type(), node.String())
172177
}
173178
log.Debugf("KIND: %v", o.Kind)
174179
return nil

pkg/yqlib/candidate_node_yaml.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ func (o *CandidateNode) copyToYamlNode(node *yaml.Node) {
7878
node.Value = o.Value
7979
node.Anchor = o.Anchor
8080

81-
// node.Alias = TODO - find Alias in our own structure
82-
// might need to be a post process thing
83-
8481
node.HeadComment = o.HeadComment
8582

8683
node.LineComment = o.LineComment

pkg/yqlib/goccy_yaml_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,24 @@ var goccyYamlFormatScenarios = []formatScenario{
219219
// expression: "explode(.)",
220220
// expected: "a: mike\nb: mike\n",
221221
// },
222+
// {
223+
// description: "multi document anchor map",
224+
// skipDoc: true,
225+
// input: "a: &remember mike\n---\nb: *remember",
226+
// expression: "explode(.)",
227+
// expected: "a: mike\n---\nb: mike\n",
228+
// },
229+
// {
230+
// description: "merge anchor",
231+
// skipDoc: true,
232+
// input: "a: &remember\n c: mike\nb:\n <<: *remember",
233+
// expected: "a: &remember\n c: mike\nb:\n <<: *remember\n",
234+
// },
222235
{
223-
description: "multi document anchor map",
236+
description: "custom tag",
224237
skipDoc: true,
225-
input: "a: &remember mike\n---\nb: *remember",
226-
expression: "explode(.)",
227-
expected: "a: mike\n---\nb: mike\n",
238+
input: "a: !cat mike",
239+
expected: "a: !cat mike\n",
228240
},
229241
// {
230242
// description: "basic - [~]",
@@ -256,6 +268,7 @@ var goccyYamlFormatScenarios = []formatScenario{
256268
// input: "[1, 2]",
257269
// expected: "[1, 2]\n",
258270
// },
271+
259272
}
260273

261274
func testGoccyYamlScenario(t *testing.T, s formatScenario) {

0 commit comments

Comments
 (0)