Fixed tests

This commit is contained in:
Mike Farah 2025-07-22 11:25:02 +10:00
parent 3018396ed2
commit db2a4550e5
4 changed files with 250 additions and 600 deletions

View File

@ -42,68 +42,6 @@ y: 2
r: 10 r: 10
``` ```
## Merge multiple maps
see https://yaml.org/type/merge.html
Given a sample.yml file of:
```yaml
- &CENTER
x: 1
y: 2
- &LEFT
x: 0
y: 2
- &BIG
r: 10
- &SMALL
r: 1
- !!merge <<:
- *CENTER
- *BIG
```
then
```bash
yq '.[4] | explode(.)' sample.yml
```
will output
```yaml
r: 10
x: 1
y: 2
```
## Override
see https://yaml.org/type/merge.html
Given a sample.yml file of:
```yaml
- &CENTER
x: 1
y: 2
- &LEFT
x: 0
y: 2
- &BIG
r: 10
- &SMALL
r: 1
- !!merge <<:
- *BIG
- *LEFT
- *SMALL
x: 1
```
then
```bash
yq '.[4] | explode(.)' sample.yml
```
will output
```yaml
r: 10
x: 1
y: 2
```
## Get anchor ## Get anchor
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml
@ -341,53 +279,66 @@ foobar:
thing: foobar_thing thing: foobar_thing
``` ```
## FIXED: Explode with merge anchors ## Merge multiple maps
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025 see https://yaml.org/type/merge.html
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml
foo: &foo - &CENTER
a: foo_a x: 1
thing: foo_thing y: 2
c: foo_c - &LEFT
bar: &bar x: 0
b: bar_b y: 2
thing: bar_thing - &BIG
c: bar_c r: 10
foobarList: - &SMALL
b: foobarList_b r: 1
!!merge <<: - !!merge <<:
- *foo - *CENTER
- *bar - *BIG
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
``` ```
then then
```bash ```bash
yq 'explode(.)' sample.yml yq '.[4] | explode(.)' sample.yml
``` ```
will output will output
```yaml ```yaml
foo: r: 10
a: foo_a x: 1
thing: foo_thing y: 2
c: foo_c ```
bar:
b: bar_b ## Override
thing: bar_thing see https://yaml.org/type/merge.html
c: bar_c
foobarList: Given a sample.yml file of:
b: foobarList_b ```yaml
a: foo_a - &CENTER
thing: foo_thing x: 1
c: foobarList_c y: 2
foobar: - &LEFT
c: foobar_c x: 0
a: foo_a y: 2
thing: foobar_thing - &BIG
r: 10
- &SMALL
r: 1
- !!merge <<:
- *BIG
- *LEFT
- *SMALL
x: 1
```
then
```bash
yq '.[4] | explode(.)' sample.yml
```
will output
```yaml
r: 10
x: 1
y: 2
``` ```
## FIXED: Explode with merge anchors ## FIXED: Explode with merge anchors
@ -439,53 +390,66 @@ foobar:
thing: foobar_thing thing: foobar_thing
``` ```
## FIXED: Explode with merge anchors ## Merge multiple maps
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025 see https://yaml.org/type/merge.html
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml
foo: &foo - &CENTER
a: foo_a x: 1
thing: foo_thing y: 2
c: foo_c - &LEFT
bar: &bar x: 0
b: bar_b y: 2
thing: bar_thing - &BIG
c: bar_c r: 10
foobarList: - &SMALL
b: foobarList_b r: 1
!!merge <<: - !!merge <<:
- *foo - *CENTER
- *bar - *BIG
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
``` ```
then then
```bash ```bash
yq 'explode(.)' sample.yml yq '.[4] | explode(.)' sample.yml
``` ```
will output will output
```yaml ```yaml
foo: x: 1
a: foo_a y: 2
thing: foo_thing r: 10
c: foo_c ```
bar:
b: bar_b ## Override
thing: bar_thing see https://yaml.org/type/merge.html
c: bar_c
foobarList: Given a sample.yml file of:
b: foobarList_b ```yaml
a: foo_a - &CENTER
thing: foo_thing x: 1
c: foobarList_c y: 2
foobar: - &LEFT
c: foobar_c x: 0
a: foo_a y: 2
thing: foobar_thing - &BIG
r: 10
- &SMALL
r: 1
- !!merge <<:
- *BIG
- *LEFT
- *SMALL
x: 1
```
then
```bash
yq '.[4] | explode(.)' sample.yml
```
will output
```yaml
r: 10
y: 2
x: 1
``` ```
## FIXED: Explode with merge anchors ## FIXED: Explode with merge anchors
@ -537,395 +501,65 @@ foobar:
thing: foobar_thing thing: foobar_thing
``` ```
## FIXED: Explode with merge anchors ## Merge multiple maps
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025 see https://yaml.org/type/merge.html
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml
foo: &foo - &CENTER
a: foo_a x: 1
thing: foo_thing y: 2
c: foo_c - &LEFT
bar: &bar x: 0
b: bar_b y: 2
thing: bar_thing - &BIG
c: bar_c r: 10
foobarList: - &SMALL
b: foobarList_b r: 1
!!merge <<: - !!merge <<:
- *foo - *CENTER
- *bar - *BIG
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
``` ```
then then
```bash ```bash
yq 'explode(.)' sample.yml yq '.[4] | explode(.)' sample.yml
``` ```
will output will output
```yaml ```yaml
foo: x: 1
a: foo_a y: 2
thing: foo_thing r: 10
c: foo_c
bar:
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
a: foo_a
thing: foo_thing
c: foobarList_c
foobar:
c: foobar_c
a: foo_a
thing: foobar_thing
``` ```
## FIXED: Explode with merge anchors ## Override
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025 see https://yaml.org/type/merge.html
Given a sample.yml file of: Given a sample.yml file of:
```yaml ```yaml
foo: &foo - &CENTER
a: foo_a x: 1
thing: foo_thing y: 2
c: foo_c - &LEFT
bar: &bar x: 0
b: bar_b y: 2
thing: bar_thing - &BIG
c: bar_c r: 10
foobarList: - &SMALL
b: foobarList_b r: 1
!!merge <<: - !!merge <<:
- *foo - *BIG
- *bar - *LEFT
c: foobarList_c - *SMALL
foobar: x: 1
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
``` ```
then then
```bash ```bash
yq 'explode(.)' sample.yml yq '.[4] | explode(.)' sample.yml
``` ```
will output will output
```yaml ```yaml
foo: r: 10
a: foo_a y: 2
thing: foo_thing x: 1
c: foo_c
bar:
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
a: foo_a
thing: foo_thing
c: foobarList_c
foobar:
c: foobar_c
a: foo_a
thing: foobar_thing
```
## FIXED: Explode with merge anchors
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
Given a sample.yml file of:
```yaml
foo: &foo
a: foo_a
thing: foo_thing
c: foo_c
bar: &bar
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
```
then
```bash
yq 'explode(.)' sample.yml
```
will output
```yaml
foo:
a: foo_a
thing: foo_thing
c: foo_c
bar:
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
a: foo_a
thing: foo_thing
c: foobarList_c
foobar:
c: foobar_c
a: foo_a
thing: foobar_thing
```
## FIXED: Explode with merge anchors
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
Given a sample.yml file of:
```yaml
foo: &foo
a: foo_a
thing: foo_thing
c: foo_c
bar: &bar
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
```
then
```bash
yq 'explode(.)' sample.yml
```
will output
```yaml
foo:
a: foo_a
thing: foo_thing
c: foo_c
bar:
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
a: foo_a
thing: foo_thing
c: foobarList_c
foobar:
c: foobar_c
a: foo_a
thing: foobar_thing
```
## FIXED: Explode with merge anchors
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
Given a sample.yml file of:
```yaml
foo: &foo
a: foo_a
thing: foo_thing
c: foo_c
bar: &bar
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
```
then
```bash
yq 'explode(.)' sample.yml
```
will output
```yaml
foo:
a: foo_a
thing: foo_thing
c: foo_c
bar:
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
a: foo_a
thing: foo_thing
c: foobarList_c
foobar:
c: foobar_c
a: foo_a
thing: foobar_thing
```
## FIXED: Explode with merge anchors
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
Given a sample.yml file of:
```yaml
foo: &foo
a: foo_a
thing: foo_thing
c: foo_c
bar: &bar
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
```
then
```bash
yq 'explode(.)' sample.yml
```
will output
```yaml
foo:
a: foo_a
thing: foo_thing
c: foo_c
bar:
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
a: foo_a
thing: foo_thing
c: foobarList_c
foobar:
c: foobar_c
a: foo_a
thing: foobar_thing
```
## FIXED: Explode with merge anchors
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
Given a sample.yml file of:
```yaml
foo: &foo
a: foo_a
thing: foo_thing
c: foo_c
bar: &bar
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
```
then
```bash
yq 'explode(.)' sample.yml
```
will output
```yaml
foo:
a: foo_a
thing: foo_thing
c: foo_c
bar:
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
a: foo_a
thing: foo_thing
c: foobarList_c
foobar:
c: foobar_c
a: foo_a
thing: foobar_thing
```
## FIXED: Explode with merge anchors
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
Given a sample.yml file of:
```yaml
foo: &foo
a: foo_a
thing: foo_thing
c: foo_c
bar: &bar
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
!!merge <<:
- *foo
- *bar
c: foobarList_c
foobar:
c: foobar_c
!!merge <<: *foo
thing: foobar_thing
```
then
```bash
yq 'explode(.)' sample.yml
```
will output
```yaml
foo:
a: foo_a
thing: foo_thing
c: foo_c
bar:
b: bar_b
thing: bar_thing
c: bar_c
foobarList:
b: foobarList_b
a: foo_a
thing: foo_thing
c: foobarList_c
foobar:
c: foobar_c
a: foo_a
thing: foobar_thing
``` ```

View File

@ -8,7 +8,11 @@ Use the `alias` and `anchor` operators to read and write yaml aliases and anchor
## NOTE --yaml-fix-merge-anchor-to-spec flag ## NOTE --yaml-fix-merge-anchor-to-spec flag
`yq` doesn't merge anchors `<<:` to spec, in some circumstances it incorrectly overrides existing keys when the spec documents not to do that. `yq` doesn't merge anchors `<<:` to spec, in some circumstances it incorrectly overrides existing keys when the spec documents not to do that.
To minimise disruption while still fixing the issue, a flag has been added to toggle this behaviour. This will first default to false; and log warnings to users. Then it will default to true (and still allow users to specify false if needed) To minimise disruption while still fixing the issue, a flag has been added to toggle this behaviour. This will first default to false; and log warnings to users. Then it will default to true (and still allow users to specify false if needed).
See examples of the flag difference below. This flag also enables advanced merging, like inline maps, as well as fixes to ensure when exploding a particular path, neighbours are not affect ed.
Long story short, you should be setting this flag to true.
See examples of the flag differences below.

View File

@ -147,18 +147,15 @@ func fixedReconstructAliasedMap(node *CandidateNode) error {
keyNode := node.Content[index] keyNode := node.Content[index]
valueNode := node.Content[index+1] valueNode := node.Content[index+1]
if keyNode.Tag != "!!merge" { if keyNode.Tag != "!!merge" {
// copy to ensure exploding doesn't modify the original node
keyNodeCopy := keyNode.Copy()
valueNodeCopy := valueNode.Copy()
// always add in plain nodes // always add in plain nodes
// explode both the key and value nodes // explode both the key and value nodes
if err := explodeNode(keyNodeCopy, Context{}); err != nil { if err := explodeNode(keyNode, Context{}); err != nil {
return err return err
} }
if err := explodeNode(valueNodeCopy, Context{}); err != nil { if err := explodeNode(valueNode, Context{}); err != nil {
return err return err
} }
newContent = append(newContent, keyNodeCopy, valueNodeCopy) newContent = append(newContent, keyNode, valueNode)
} else { } else {
sequence := valueNode sequence := valueNode
if sequence.Kind == AliasNode { if sequence.Kind == AliasNode {

View File

@ -64,8 +64,8 @@ bar:
foobarList: foobarList:
b: bar_b b: bar_b
thing: foo_thing thing: foo_thing
a: foo_a
c: foobarList_c c: foobarList_c
a: foo_a
foobar: foobar:
c: foo_c c: foo_c
a: foo_a a: foo_a
@ -136,6 +136,87 @@ var fixedAnchorOperatorScenarios = []expressionScenario{
"D0, P[foobar], (!!map)::{c: foobar_c, a: foo_a, thing: foobar_thing}\n", "D0, P[foobar], (!!map)::{c: foobar_c, a: foo_a, thing: foobar_thing}\n",
}, },
}, },
{
description: "Merge multiple maps",
subdescription: "see https://yaml.org/type/merge.html",
document: specDocument + "- << : [ *CENTER, *BIG ]\n",
expression: ".[4] | explode(.)",
expected: []string{"D0, P[4], (!!map)::x: 1\ny: 2\nr: 10\n"},
},
{
description: "Override",
subdescription: "see https://yaml.org/type/merge.html",
document: specDocument + "- << : [ *BIG, *LEFT, *SMALL ]\n x: 1\n",
expression: ".[4] | explode(.)",
expected: []string{"D0, P[4], (!!map)::r: 10\ny: 2\nx: 1\n"},
},
{
skipDoc: true,
description: "Exploding inline merge anchor",
subdescription: "`<<` map must be exploded, otherwise `c: *b` will become invalid",
document: `{a: {b: &b 42}, <<: {c: *b}}`,
expression: `explode(.) | sort_keys(.)`,
expected: []string{
"D0, P[], (!!map)::{a: {b: 42}, c: 42}\n",
},
},
{
skipDoc: true,
description: "Exploding inline merge anchor in sequence",
subdescription: "`<<` map must be exploded, otherwise `c: *b` will become invalid",
document: `{a: {b: &b 42}, <<: [{c: *b}]}`,
expression: `explode(.) | sort_keys(.)`,
expected: []string{
"D0, P[], (!!map)::{a: {b: 42}, c: 42}\n",
},
},
{
skipDoc: true,
description: "Exploding merge anchor should not explode neighbors",
subdescription: "b must not be exploded, as `r: *a` will become invalid",
document: `{b: &b {a: &a 42}, r: *a, c: {<<: *b}}`,
expression: `explode(.c)`,
expected: []string{
"D0, P[], (!!map)::{b: &b {a: &a 42}, r: *a, c: {a: 42}}\n",
},
},
{
skipDoc: true,
description: "Exploding sequence merge anchor should not explode neighbors",
subdescription: "b must not be exploded, as `r: *a` will become invalid",
document: `{b: &b {a: &a 42}, r: *a, c: {<<: [*b]}}`,
expression: `explode(.c)`,
expected: []string{
"D0, P[], (!!map)::{b: &b {a: &a 42}, r: *a, c: {a: 42}}\n",
},
},
{
skipDoc: true,
description: "Merge anchor with inline map",
document: `{<<: {a: 42}}`,
expression: `explode(.)`,
expected: []string{
"D0, P[], (!!map)::{a: 42}\n",
},
},
{
skipDoc: true,
description: "Merge anchor with sequence with inline map",
document: `{<<: [{a: 42}]}`,
expression: `explode(.)`,
expected: []string{
"D0, P[], (!!map)::{a: 42}\n",
},
},
{
skipDoc: true,
description: "Merge anchor with aliased sequence with inline map",
document: `{s: &s [{a: 42}], m: {<<: *s}}`,
expression: `.m | explode(.)`,
expected: []string{
"D0, P[m], (!!map)::{a: 42}\n",
},
},
} }
var badAnchorOperatorScenarios = []expressionScenario{ var badAnchorOperatorScenarios = []expressionScenario{
@ -159,7 +240,7 @@ var badAnchorOperatorScenarios = []expressionScenario{
expression: `.foo* | explode(.) | (. style="flow")`, expression: `.foo* | explode(.) | (. style="flow")`,
expected: []string{ expected: []string{
"D0, P[foo], (!!map)::{a: foo_a, thing: foo_thing, c: foo_c}\n", "D0, P[foo], (!!map)::{a: foo_a, thing: foo_thing, c: foo_c}\n",
"D0, P[foobarList], (!!map)::{b: bar_b, thing: foo_thing, a: foo_a, c: foobarList_c}\n", "D0, P[foobarList], (!!map)::{b: bar_b, thing: foo_thing, c: foobarList_c, a: foo_a}\n",
"D0, P[foobar], (!!map)::{c: foo_c, a: foo_a, thing: foobar_thing}\n", "D0, P[foobar], (!!map)::{c: foo_c, a: foo_a, thing: foobar_thing}\n",
}, },
}, },
@ -169,10 +250,24 @@ var badAnchorOperatorScenarios = []expressionScenario{
expression: `.foo* | explode(explode(.)) | (. style="flow")`, expression: `.foo* | explode(explode(.)) | (. style="flow")`,
expected: []string{ expected: []string{
"D0, P[foo], (!!map)::{a: foo_a, thing: foo_thing, c: foo_c}\n", "D0, P[foo], (!!map)::{a: foo_a, thing: foo_thing, c: foo_c}\n",
"D0, P[foobarList], (!!map)::{b: bar_b, thing: foo_thing, a: foo_a, c: foobarList_c}\n", "D0, P[foobarList], (!!map)::{b: bar_b, thing: foo_thing, c: foobarList_c, a: foo_a}\n",
"D0, P[foobar], (!!map)::{c: foo_c, a: foo_a, thing: foobar_thing}\n", "D0, P[foobar], (!!map)::{c: foo_c, a: foo_a, thing: foobar_thing}\n",
}, },
}, },
{
description: "Merge multiple maps",
subdescription: "see https://yaml.org/type/merge.html",
document: specDocument + "- << : [ *CENTER, *BIG ]\n",
expression: ".[4] | explode(.)",
expected: []string{"D0, P[4], (!!map)::r: 10\nx: 1\ny: 2\n"}, // correct data, but wrong key order
},
{
description: "Override",
subdescription: "see https://yaml.org/type/merge.html",
document: specDocument + "- << : [ *BIG, *LEFT, *SMALL ]\n x: 1\n",
expression: ".[4] | explode(.)",
expected: []string{"D0, P[4], (!!map)::r: 10\nx: 1\ny: 2\n"},
},
} }
var anchorOperatorScenarios = []expressionScenario{ var anchorOperatorScenarios = []expressionScenario{
@ -197,20 +292,7 @@ var anchorOperatorScenarios = []expressionScenario{
expression: ".[4] | explode(.)", expression: ".[4] | explode(.)",
expected: []string{expectedSpecResult}, expected: []string{expectedSpecResult},
}, },
{
description: "Merge multiple maps",
subdescription: "see https://yaml.org/type/merge.html",
document: specDocument + "- << : [ *CENTER, *BIG ]\n",
expression: ".[4] | explode(.)",
expected: []string{"D0, P[4], (!!map)::x: 1\ny: 2\nr: 10\n"},
},
{
description: "Override",
subdescription: "see https://yaml.org/type/merge.html",
document: specDocument + "- << : [ *BIG, *LEFT, *SMALL ]\n x: 1\n",
expression: ".[4] | explode(.)",
expected: []string{"D0, P[4], (!!map)::r: 10\ny: 2\nx: 1\n"},
},
{ {
description: "Get anchor", description: "Get anchor",
document: `a: &billyBob cat`, document: `a: &billyBob cat`,
@ -386,73 +468,6 @@ var anchorOperatorScenarios = []expressionScenario{
expression: `.thingOne |= (explode(.) | sort_keys(.)) * {"value": false}`, expression: `.thingOne |= (explode(.) | sort_keys(.)) * {"value": false}`,
expected: []string{expectedUpdatedArrayRef}, expected: []string{expectedUpdatedArrayRef},
}, },
{
skipDoc: true,
description: "Merge anchor with inline map",
document: `{<<: {a: 42}}`,
expression: `explode(.)`,
expected: []string{
"D0, P[], (!!map)::{a: 42}\n",
},
},
{
skipDoc: true,
description: "Merge anchor with sequence with inline map",
document: `{<<: [{a: 42}]}`,
expression: `explode(.)`,
expected: []string{
"D0, P[], (!!map)::{a: 42}\n",
},
},
{
skipDoc: true,
description: "Merge anchor with aliased sequence with inline map",
document: `{s: &s [{a: 42}], m: {<<: *s}}`,
expression: `.m | explode(.)`,
expected: []string{
"D0, P[m], (!!map)::{a: 42}\n",
},
},
{
skipDoc: true,
description: "Exploding merge anchor should not explode neighbors",
subdescription: "b must not be exploded, as `r: *a` will become invalid",
document: `{b: &b {a: &a 42}, r: *a, c: {<<: *b}}`,
expression: `explode(.c)`,
expected: []string{
"D0, P[], (!!map)::{b: &b {a: &a 42}, r: *a, c: {a: 42}}\n",
},
},
{
skipDoc: true,
description: "Exploding sequence merge anchor should not explode neighbors",
subdescription: "b must not be exploded, as `r: *a` will become invalid",
document: `{b: &b {a: &a 42}, r: *a, c: {<<: [*b]}}`,
expression: `explode(.c)`,
expected: []string{
"D0, P[], (!!map)::{b: &b {a: &a 42}, r: *a, c: {a: 42}}\n",
},
},
{
skipDoc: true,
description: "Exploding inline merge anchor",
subdescription: "`<<` map must be exploded, otherwise `c: *b` will become invalid",
document: `{a: {b: &b 42}, <<: {c: *b}}`,
expression: `explode(.) | sort_keys(.)`,
expected: []string{
"D0, P[], (!!map)::{a: {b: 42}, c: 42}\n",
},
},
{
skipDoc: true,
description: "Exploding inline merge anchor in sequence",
subdescription: "`<<` map must be exploded, otherwise `c: *b` will become invalid",
document: `{a: {b: &b 42}, <<: [{c: *b}]}`,
expression: `explode(.) | sort_keys(.)`,
expected: []string{
"D0, P[], (!!map)::{a: {b: 42}, c: 42}\n",
},
},
{ {
skipDoc: true, skipDoc: true,
description: "Duplicate keys", description: "Duplicate keys",