mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-05 20:15:36 +00:00
* Update docs given https://github.com/yaml/go-yaml/pull/348 * Fix for https://github.com/mikefarah/yq/issues/2677 Depends on https://github.com/yaml/go-yaml/pull/348 * Test for https://github.com/mikefarah/yq/issues/2677 * Remove redundant check and add test case for explicit `!!merge` on `*+` traversal * Bump go.yaml.in/yaml/v4 from 4.0.0-rc.4 to 4.0.0-rc.5
This commit is contained in:
parent
25dfcf280f
commit
30e16a33c3
2
go.mod
2
go.mod
@ -19,7 +19,7 @@ require (
|
|||||||
github.com/spf13/pflag v1.0.10
|
github.com/spf13/pflag v1.0.10
|
||||||
github.com/yuin/gopher-lua v1.1.2
|
github.com/yuin/gopher-lua v1.1.2
|
||||||
github.com/zclconf/go-cty v1.18.1
|
github.com/zclconf/go-cty v1.18.1
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.4
|
go.yaml.in/yaml/v4 v4.0.0-rc.5
|
||||||
golang.org/x/mod v0.36.0
|
golang.org/x/mod v0.36.0
|
||||||
golang.org/x/net v0.55.0
|
golang.org/x/net v0.55.0
|
||||||
golang.org/x/text v0.37.0
|
golang.org/x/text v0.37.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -68,8 +68,8 @@ github.com/zclconf/go-cty v1.18.1/go.mod h1:qpnV6EDNgC1sns/AleL1fvatHw72j+S+nS+M
|
|||||||
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
|
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
|
||||||
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
|
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
|
||||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U=
|
go.yaml.in/yaml/v4 v4.0.0-rc.5 h1:JVliQq9EGOYaTgMi+k8BhUJyqcGk4ZqeuiN1Cirba9c=
|
||||||
go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
go.yaml.in/yaml/v4 v4.0.0-rc.5/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
|
||||||
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
|
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
|
||||||
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
|
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
|
||||||
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
|
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
|
||||||
|
|||||||
@ -46,7 +46,11 @@ const (
|
|||||||
func createStringScalarNode(stringValue string) *CandidateNode {
|
func createStringScalarNode(stringValue string) *CandidateNode {
|
||||||
var node = &CandidateNode{Kind: ScalarNode}
|
var node = &CandidateNode{Kind: ScalarNode}
|
||||||
node.Value = stringValue
|
node.Value = stringValue
|
||||||
node.Tag = "!!str"
|
if stringValue == "<<" {
|
||||||
|
node.Tag = "!!merge"
|
||||||
|
} else {
|
||||||
|
node.Tag = "!!str"
|
||||||
|
}
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ Given a sample.yml file of:
|
|||||||
r: 10
|
r: 10
|
||||||
- &SMALL
|
- &SMALL
|
||||||
r: 1
|
r: 1
|
||||||
- !!merge <<: *CENTRE
|
- <<: *CENTRE
|
||||||
r: 10
|
r: 10
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -213,10 +213,10 @@ item_value: &item_value
|
|||||||
value: true
|
value: true
|
||||||
thingOne:
|
thingOne:
|
||||||
name: item_1
|
name: item_1
|
||||||
!!merge <<: *item_value
|
<<: *item_value
|
||||||
thingTwo:
|
thingTwo:
|
||||||
name: item_2
|
name: item_2
|
||||||
!!merge <<: *item_value
|
<<: *item_value
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
@ -231,7 +231,7 @@ thingOne:
|
|||||||
value: false
|
value: false
|
||||||
thingTwo:
|
thingTwo:
|
||||||
name: item_2
|
name: item_2
|
||||||
!!merge <<: *item_value
|
<<: *item_value
|
||||||
```
|
```
|
||||||
|
|
||||||
## LEGACY: Explode with merge anchors
|
## LEGACY: Explode with merge anchors
|
||||||
@ -249,13 +249,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -298,7 +298,7 @@ Given a sample.yml file of:
|
|||||||
r: 10
|
r: 10
|
||||||
- &SMALL
|
- &SMALL
|
||||||
r: 1
|
r: 1
|
||||||
- !!merge <<:
|
- <<:
|
||||||
- *CENTRE
|
- *CENTRE
|
||||||
- *BIG
|
- *BIG
|
||||||
```
|
```
|
||||||
@ -328,7 +328,7 @@ Given a sample.yml file of:
|
|||||||
r: 10
|
r: 10
|
||||||
- &SMALL
|
- &SMALL
|
||||||
r: 1
|
r: 1
|
||||||
- !!merge <<:
|
- <<:
|
||||||
- *BIG
|
- *BIG
|
||||||
- *LEFT
|
- *LEFT
|
||||||
- *SMALL
|
- *SMALL
|
||||||
@ -361,13 +361,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -411,7 +411,7 @@ Given a sample.yml file of:
|
|||||||
r: 10
|
r: 10
|
||||||
- &SMALL
|
- &SMALL
|
||||||
r: 1
|
r: 1
|
||||||
- !!merge <<:
|
- <<:
|
||||||
- *CENTRE
|
- *CENTRE
|
||||||
- *BIG
|
- *BIG
|
||||||
```
|
```
|
||||||
@ -442,7 +442,7 @@ Given a sample.yml file of:
|
|||||||
r: 10
|
r: 10
|
||||||
- &SMALL
|
- &SMALL
|
||||||
r: 1
|
r: 1
|
||||||
- !!merge <<:
|
- <<:
|
||||||
- *BIG
|
- *BIG
|
||||||
- *LEFT
|
- *LEFT
|
||||||
- *SMALL
|
- *SMALL
|
||||||
@ -467,7 +467,7 @@ Given a sample.yml file of:
|
|||||||
```yaml
|
```yaml
|
||||||
a:
|
a:
|
||||||
b: &b 42
|
b: &b 42
|
||||||
!!merge <<:
|
<<:
|
||||||
c: *b
|
c: *b
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
|
|||||||
@ -55,7 +55,7 @@ yq '.a = .a / 0 | .b = .b / 0' sample.yml
|
|||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
a: !!float +Inf
|
a: +Inf
|
||||||
b: !!float -Inf
|
b: -Inf
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ yq '.a = .a % .b' sample.yml
|
|||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
a: !!float 2
|
a: 2
|
||||||
b: 2.5
|
b: 2.5
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ yq '.a = .a % .b' sample.yml
|
|||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
a: !!float NaN
|
a: NaN
|
||||||
b: 0
|
b: 0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -471,13 +471,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -487,7 +487,7 @@ yq '.foobar * .foobarList' sample.yml
|
|||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
|
|||||||
@ -131,13 +131,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -147,7 +147,7 @@ yq '.foobar | [..]' sample.yml
|
|||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
- c: foobar_c
|
- c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
- foobar_c
|
- foobar_c
|
||||||
- *foo
|
- *foo
|
||||||
|
|||||||
@ -294,13 +294,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -325,13 +325,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -376,13 +376,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -409,13 +409,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -442,13 +442,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -477,13 +477,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -513,13 +513,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -546,13 +546,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -579,13 +579,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
@ -614,13 +614,13 @@ bar: &bar
|
|||||||
c: bar_c
|
c: bar_c
|
||||||
foobarList:
|
foobarList:
|
||||||
b: foobarList_b
|
b: foobarList_b
|
||||||
!!merge <<:
|
<<:
|
||||||
- *foo
|
- *foo
|
||||||
- *bar
|
- *bar
|
||||||
c: foobarList_c
|
c: foobarList_c
|
||||||
foobar:
|
foobar:
|
||||||
c: foobar_c
|
c: foobar_c
|
||||||
!!merge <<: *foo
|
<<: *foo
|
||||||
thing: foobar_thing
|
thing: foobar_thing
|
||||||
```
|
```
|
||||||
then
|
then
|
||||||
|
|||||||
@ -230,8 +230,7 @@ var goccyYamlFormatScenarios = []formatScenario{
|
|||||||
description: "merge anchor",
|
description: "merge anchor",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
input: "a: &remember\n c: mike\nb:\n <<: *remember",
|
input: "a: &remember\n c: mike\nb:\n <<: *remember",
|
||||||
// fine to have !!merge as that's what the current impl does
|
expected: "a: &remember\n c: mike\nb:\n <<: *remember\n",
|
||||||
expected: "a: &remember\n c: mike\nb:\n !!merge <<: *remember\n",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "custom tag",
|
description: "custom tag",
|
||||||
|
|||||||
@ -24,7 +24,7 @@ type parseSnippetScenario struct {
|
|||||||
var parseSnippetScenarios = []parseSnippetScenario{
|
var parseSnippetScenarios = []parseSnippetScenario{
|
||||||
{
|
{
|
||||||
snippet: ":",
|
snippet: ":",
|
||||||
expectedError: "yaml: while parsing a block mapping at <unknown position>: did not find expected key",
|
expectedError: "go-yaml load error in parser (while parsing a block mapping) at L1.C1: did not find expected key",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
snippet: "",
|
snippet: "",
|
||||||
|
|||||||
@ -31,7 +31,7 @@ thingOne:
|
|||||||
value: false
|
value: false
|
||||||
thingTwo:
|
thingTwo:
|
||||||
name: item_2
|
name: item_2
|
||||||
!!merge <<: *item_value
|
<<: *item_value
|
||||||
`
|
`
|
||||||
|
|
||||||
var explodeMergeAnchorsFixedExpected = `D0, P[], (!!map)::foo:
|
var explodeMergeAnchorsFixedExpected = `D0, P[], (!!map)::foo:
|
||||||
@ -288,7 +288,63 @@ var badAnchorOperatorScenarios = []expressionScenario{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mixedMergeTagStyleDocument = `
|
||||||
|
constants:
|
||||||
|
errorResponse: &errorResponse
|
||||||
|
status: 200
|
||||||
|
endpoints:
|
||||||
|
- condition: true
|
||||||
|
!!merge <<: *errorResponse
|
||||||
|
- condition: false
|
||||||
|
<<: *errorResponse
|
||||||
|
other:
|
||||||
|
!!merge <<: *errorResponse
|
||||||
|
somethingElse:
|
||||||
|
<<: *errorResponse
|
||||||
|
`
|
||||||
|
|
||||||
|
var mixedMergeTagStyleExplodedDocument = `
|
||||||
|
constants:
|
||||||
|
errorResponse:
|
||||||
|
status: 200
|
||||||
|
endpoints:
|
||||||
|
- condition: true
|
||||||
|
status: 200
|
||||||
|
- condition: false
|
||||||
|
status: 200
|
||||||
|
other:
|
||||||
|
status: 200
|
||||||
|
somethingElse:
|
||||||
|
status: 200
|
||||||
|
`
|
||||||
|
|
||||||
var anchorOperatorScenarios = []expressionScenario{
|
var anchorOperatorScenarios = []expressionScenario{
|
||||||
|
{
|
||||||
|
// mergeObjects previously skipped all !!merge-tagged nodes. Since !!merge only appears on
|
||||||
|
// << map keys, this meant applyAssignment was never called for the << key. It was later
|
||||||
|
// autocreated by createStringScalarNode("<<") with tag !!str, silently dropping !!merge.
|
||||||
|
// DontFollowAlias:true already prevents aliases being followed, so the skip was redundant.
|
||||||
|
// Old (buggy) output: "D0, P[], (!!map)::base: &base\n x: 1\ndest:\n <<: *base\n"
|
||||||
|
skipDoc: true,
|
||||||
|
description: "direct *+ preserves explicit !!merge tag on << key (regression for issue 2677)",
|
||||||
|
document: "base: &base\n x: 1\ndest:\n !!merge <<: *base\n",
|
||||||
|
expression: `. as $d | {} *+ $d`,
|
||||||
|
expected: []string{"D0, P[], (!!map)::base: &base\n x: 1\ndest:\n !!merge <<: *base\n"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "explicit !!merge tag on << key is preserved through ireduce merge",
|
||||||
|
document: mixedMergeTagStyleDocument,
|
||||||
|
expression: `. as $item ireduce ({}; . *+ $item)`,
|
||||||
|
expected: []string{"D0, P[], (!!map)::" + mixedMergeTagStyleDocument},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "explode expands << merge keys regardless of explicit tag style (!!merge or plain)",
|
||||||
|
document: mixedMergeTagStyleDocument,
|
||||||
|
expression: `explode(.)`,
|
||||||
|
expected: []string{"D0, P[], (!!map)::" + mixedMergeTagStyleExplodedDocument},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
description: "merge anchor to alias alias",
|
description: "merge anchor to alias alias",
|
||||||
|
|||||||
@ -45,7 +45,7 @@ var divideOperatorScenarios = []expressionScenario{
|
|||||||
document: `{a: 1, b: -1}`,
|
document: `{a: 1, b: -1}`,
|
||||||
expression: `.a = .a / 0 | .b = .b / 0`,
|
expression: `.a = .a / 0 | .b = .b / 0`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{a: !!float +Inf, b: !!float -Inf}\n",
|
"D0, P[], (!!map)::{a: +Inf, b: -Inf}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -77,7 +77,7 @@ var loadScenarios = []expressionScenario{
|
|||||||
document: `{something: {file: "thing.yml"}, over: {here: [{file: "thing.yml"}]}}`,
|
document: `{something: {file: "thing.yml"}, over: {here: [{file: "thing.yml"}]}}`,
|
||||||
expression: `(.. | select(has("file"))) |= load("../../examples/" + .file)`,
|
expression: `(.. | select(has("file"))) |= load("../../examples/" + .file)`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{something: {a: apple is included, b: cool.}, over: {here: [{a: apple is included, b: cool.}]}}\n",
|
"D0, P[], (!!map)::{something: {a: apple is included, b: cool.}, over: {here: [{a: apple is included,\n b: cool.}]}}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -37,7 +37,7 @@ var moduloOperatorScenarios = []expressionScenario{
|
|||||||
document: `{a: 12, b: 2.5}`,
|
document: `{a: 12, b: 2.5}`,
|
||||||
expression: `.a = .a % .b`,
|
expression: `.a = .a % .b`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{a: !!float 2, b: 2.5}\n",
|
"D0, P[], (!!map)::{a: 2, b: 2.5}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -53,7 +53,7 @@ var moduloOperatorScenarios = []expressionScenario{
|
|||||||
document: `{a: 1.1, b: 0}`,
|
document: `{a: 1.1, b: 0}`,
|
||||||
expression: `.a = .a % .b`,
|
expression: `.a = .a % .b`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{a: !!float NaN, b: 0}\n",
|
"D0, P[], (!!map)::{a: NaN, b: 0}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ var moduloOperatorScenarios = []expressionScenario{
|
|||||||
document: "a: 2\nb: !goat 2.3",
|
document: "a: 2\nb: !goat 2.3",
|
||||||
expression: `.a = .a % .b`,
|
expression: `.a = .a % .b`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::a: !!float 2\nb: !goat 2.3\n",
|
"D0, P[], (!!map)::a: 2\nb: !goat 2.3\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -189,10 +189,6 @@ func mergeObjects(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs
|
|||||||
|
|
||||||
log.Debugf("going to applied assignment to LHS: %v with RHS: %v", NodeToString(lhs), NodeToString(candidate))
|
log.Debugf("going to applied assignment to LHS: %v with RHS: %v", NodeToString(lhs), NodeToString(candidate))
|
||||||
|
|
||||||
if candidate.Tag == "!!merge" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
err := applyAssignment(d, context, pathIndexToStartFrom, lhs, candidate, preferences)
|
err := applyAssignment(d, context, pathIndexToStartFrom, lhs, candidate, preferences)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -121,7 +121,7 @@ var multiplyOperatorScenarios = []expressionScenario{
|
|||||||
document: mergeArrayWithAnchors,
|
document: mergeArrayWithAnchors,
|
||||||
expression: `. * .`,
|
expression: `. * .`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::sample:\n - &a\n - !!merge <<: *a\n",
|
"D0, P[], (!!map)::sample:\n - &a\n - <<: *a\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -514,7 +514,7 @@ var multiplyOperatorScenarios = []expressionScenario{
|
|||||||
environmentVariables: map[string]string{"originalPath": ".myArray", "otherPath": ".newArray", "idPath": ".a"},
|
environmentVariables: map[string]string{"originalPath": ".myArray", "otherPath": ".newArray", "idPath": ".a"},
|
||||||
expression: mergeExpression,
|
expression: mergeExpression,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{myArray: [{a: apple, b: appleB2}, {a: kiwi, b: kiwiB}, {a: banana, b: bananaB, c: bananaC}, {a: dingo, c: dingoC}], something: else}\n",
|
"D0, P[], (!!map)::{myArray: [{a: apple, b: appleB2}, {a: kiwi, b: kiwiB}, {a: banana, b: bananaB, c: bananaC},\n {a: dingo, c: dingoC}], something: else}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -546,7 +546,7 @@ var multiplyOperatorScenarios = []expressionScenario{
|
|||||||
document: mergeDocSample,
|
document: mergeDocSample,
|
||||||
expression: `.foobar * .foobarList`,
|
expression: `.foobar * .foobarList`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[foobar], (!!map)::c: foobarList_c\n!!merge <<: [*foo, *bar]\nthing: foobar_thing\nb: foobarList_b\n",
|
"D0, P[foobar], (!!map)::c: foobarList_c\n<<: [*foo, *bar]\nthing: foobar_thing\nb: foobarList_b\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -554,7 +554,7 @@ var multiplyOperatorScenarios = []expressionScenario{
|
|||||||
document: document,
|
document: document,
|
||||||
expression: `.b * .c`,
|
expression: `.b * .c`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[b], (!!map)::{name: dog, \"<<\": *cat}\n",
|
"D0, P[b], (!!map)::{name: dog, <<: *cat}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -581,7 +581,7 @@ var multiplyOperatorScenarios = []expressionScenario{
|
|||||||
document: "a: 2\nb: !goat 3.5",
|
document: "a: 2\nb: !goat 3.5",
|
||||||
expression: ".a = .a * .b",
|
expression: ".a = .a * .b",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::a: !!float 7\nb: !goat 3.5\n",
|
"D0, P[], (!!map)::a: 7\nb: !goat 3.5\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -187,7 +187,7 @@ var recursiveDescentOperatorScenarios = []expressionScenario{
|
|||||||
document: mergeDocSample,
|
document: mergeDocSample,
|
||||||
expression: `.foobar | [..]`,
|
expression: `.foobar | [..]`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[foobar], (!!seq)::- c: foobar_c\n !!merge <<: *foo\n thing: foobar_thing\n- foobar_c\n- *foo\n- foobar_thing\n",
|
"D0, P[foobar], (!!seq)::- c: foobar_c\n <<: *foo\n thing: foobar_thing\n- foobar_c\n- *foo\n- foobar_thing\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -195,7 +195,7 @@ var recursiveDescentOperatorScenarios = []expressionScenario{
|
|||||||
document: mergeDocSample,
|
document: mergeDocSample,
|
||||||
expression: `.foobar | [...]`,
|
expression: `.foobar | [...]`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[foobar], (!!seq)::- c: foobar_c\n !!merge <<: *foo\n thing: foobar_thing\n- c\n- foobar_c\n- !!merge <<\n- *foo\n- thing\n- foobar_thing\n",
|
"D0, P[foobar], (!!seq)::- c: foobar_c\n <<: *foo\n thing: foobar_thing\n- c\n- foobar_c\n- <<\n- *foo\n- thing\n- foobar_thing\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -203,7 +203,7 @@ var recursiveDescentOperatorScenarios = []expressionScenario{
|
|||||||
document: mergeDocSample,
|
document: mergeDocSample,
|
||||||
expression: `.foobarList | ..`,
|
expression: `.foobarList | ..`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[foobarList], (!!map)::b: foobarList_b\n!!merge <<: [*foo, *bar]\nc: foobarList_c\n",
|
"D0, P[foobarList], (!!map)::b: foobarList_b\n<<: [*foo, *bar]\nc: foobarList_c\n",
|
||||||
"D0, P[foobarList b], (!!str)::foobarList_b\n",
|
"D0, P[foobarList b], (!!str)::foobarList_b\n",
|
||||||
"D0, P[foobarList <<], (!!seq)::[*foo, *bar]\n",
|
"D0, P[foobarList <<], (!!seq)::[*foo, *bar]\n",
|
||||||
"D0, P[foobarList << 0], (alias)::*foo\n",
|
"D0, P[foobarList << 0], (alias)::*foo\n",
|
||||||
@ -216,7 +216,7 @@ var recursiveDescentOperatorScenarios = []expressionScenario{
|
|||||||
document: mergeDocSample,
|
document: mergeDocSample,
|
||||||
expression: `.foobarList | ...`,
|
expression: `.foobarList | ...`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[foobarList], (!!map)::b: foobarList_b\n!!merge <<: [*foo, *bar]\nc: foobarList_c\n",
|
"D0, P[foobarList], (!!map)::b: foobarList_b\n<<: [*foo, *bar]\nc: foobarList_c\n",
|
||||||
"D0, P[foobarList b], (!!str)::b\n",
|
"D0, P[foobarList b], (!!str)::b\n",
|
||||||
"D0, P[foobarList b], (!!str)::foobarList_b\n",
|
"D0, P[foobarList b], (!!str)::foobarList_b\n",
|
||||||
"D0, P[foobarList <<], (!!merge)::<<\n",
|
"D0, P[foobarList <<], (!!merge)::<<\n",
|
||||||
|
|||||||
@ -98,7 +98,7 @@ var selectOperatorScenarios = []expressionScenario{
|
|||||||
document: `[{animal: cat, legs: {cool: true}}, {animal: fish}]`,
|
document: `[{animal: cat, legs: {cool: true}}, {animal: fish}]`,
|
||||||
expression: `(.[] | select(.legs.cool == true).canWalk) = true | (.[] | .alive.things) = "yes"`,
|
expression: `(.[] | select(.legs.cool == true).canWalk) = true | (.[] | .alive.things) = "yes"`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!seq)::[{animal: cat, legs: {cool: true}, canWalk: true, alive: {things: yes}}, {animal: fish, alive: {things: yes}}]\n",
|
"D0, P[], (!!seq)::[{animal: cat, legs: {cool: true}, canWalk: true, alive: {things: yes}}, {animal: fish,\n alive: {things: yes}}]\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -37,7 +37,7 @@ var sortKeysOperatorScenarios = []expressionScenario{
|
|||||||
document: `{bParent: {c: dog, array: [3,1,2]}, aParent: {z: donkey, x: [{c: yum, b: delish}, {b: ew, a: apple}]}}`,
|
document: `{bParent: {c: dog, array: [3,1,2]}, aParent: {z: donkey, x: [{c: yum, b: delish}, {b: ew, a: apple}]}}`,
|
||||||
expression: `sort_keys(..)`,
|
expression: `sort_keys(..)`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::{aParent: {x: [{b: delish, c: yum}, {a: apple, b: ew}], z: donkey}, bParent: {array: [3, 1, 2], c: dog}}\n",
|
"D0, P[], (!!map)::{aParent: {x: [{b: delish, c: yum}, {a: apple, b: ew}], z: donkey}, bParent: {array: [\n 3, 1, 2], c: dog}}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,7 +50,7 @@ var styleOperatorScenarios = []expressionScenario{
|
|||||||
document: "bing: &foo {x: z}\na:\n c: cat\n <<: [*foo]",
|
document: "bing: &foo {x: z}\na:\n c: cat\n <<: [*foo]",
|
||||||
expression: `(... | select(tag=="!!str")) style="single"`,
|
expression: `(... | select(tag=="!!str")) style="single"`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::'bing': &foo {'x': 'z'}\n'a':\n 'c': 'cat'\n !!merge <<: [*foo]\n",
|
"D0, P[], (!!map)::'bing': &foo {'x': 'z'}\n'a':\n 'c': 'cat'\n <<: [*foo]\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -494,7 +494,7 @@ var traversePathOperatorScenarios = []expressionScenario{
|
|||||||
document: mergeDocSample,
|
document: mergeDocSample,
|
||||||
expression: `.foobar`,
|
expression: `.foobar`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[foobar], (!!map)::c: foobar_c\n!!merge <<: *foo\nthing: foobar_thing\n",
|
"D0, P[foobar], (!!map)::c: foobar_c\n<<: *foo\nthing: foobar_thing\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -518,7 +518,7 @@ var traversePathOperatorScenarios = []expressionScenario{
|
|||||||
document: mergeDocSample,
|
document: mergeDocSample,
|
||||||
expression: `.foobarList`,
|
expression: `.foobarList`,
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[foobarList], (!!map)::b: foobarList_b\n!!merge <<: [*foo, *bar]\nc: foobarList_c\n",
|
"D0, P[foobarList], (!!map)::b: foobarList_b\n<<: [*foo, *bar]\nc: foobarList_c\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user