Skip to content

Commit 92309b1

Browse files
committed
Fixed test doc gen
1 parent d5757fc commit 92309b1

File tree

5 files changed

+142
-5
lines changed

5 files changed

+142
-5
lines changed

pkg/yqlib/doc/operators/anchor-and-alias-operators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This flag also enables advanced merging, like inline maps, as well as fixes to e
1414

1515
Long story short, you should be setting this flag to true.
1616

17-
See examples of the flag differences below.
17+
See examples of the flag differences below, where LEGACY is with the flag off; and FIXED is with the flag on.
1818

1919

2020
## Merge one map

pkg/yqlib/doc/operators/headers/anchor-and-alias-operators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ This flag also enables advanced merging, like inline maps, as well as fixes to e
1414

1515
Long story short, you should be setting this flag to true.
1616

17-
See examples of the flag differences below.
17+
See examples of the flag differences below, where LEGACY is with the flag off; and FIXED is with the flag on.
1818

pkg/yqlib/doc/operators/headers/traverse-read.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ This is the simplest (and perhaps most used) operator. It is used to navigate de
88

99
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)
1010

11-
See examples of the flag differences below.
11+
See examples of the flag differences below, where LEGACY is the flag off; and FIXED is with the flag on.
1212

pkg/yqlib/doc/operators/traverse-read.md

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is the simplest (and perhaps most used) operator. It is used to navigate de
88

99
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)
1010

11-
See examples of the flag differences below.
11+
See examples of the flag differences below, where LEGACY is the flag off; and FIXED is with the flag on.
1212

1313

1414
## Simple map navigation
@@ -498,3 +498,140 @@ bar_thing
498498
foobarList_c
499499
```
500500

501+
## FIXED: Traversing merge anchors with override
502+
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour.
503+
504+
Given a sample.yml file of:
505+
```yaml
506+
foo: &foo
507+
a: foo_a
508+
thing: foo_thing
509+
c: foo_c
510+
bar: &bar
511+
b: bar_b
512+
thing: bar_thing
513+
c: bar_c
514+
foobarList:
515+
b: foobarList_b
516+
!!merge <<:
517+
- *foo
518+
- *bar
519+
c: foobarList_c
520+
foobar:
521+
c: foobar_c
522+
!!merge <<: *foo
523+
thing: foobar_thing
524+
```
525+
then
526+
```bash
527+
yq '.foobar.c' sample.yml
528+
```
529+
will output
530+
```yaml
531+
foobar_c
532+
```
533+
534+
## FIXED: Traversing merge anchor lists
535+
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Note that the keys earlier in the merge anchors sequence override later ones
536+
537+
Given a sample.yml file of:
538+
```yaml
539+
foo: &foo
540+
a: foo_a
541+
thing: foo_thing
542+
c: foo_c
543+
bar: &bar
544+
b: bar_b
545+
thing: bar_thing
546+
c: bar_c
547+
foobarList:
548+
b: foobarList_b
549+
!!merge <<:
550+
- *foo
551+
- *bar
552+
c: foobarList_c
553+
foobar:
554+
c: foobar_c
555+
!!merge <<: *foo
556+
thing: foobar_thing
557+
```
558+
then
559+
```bash
560+
yq '.foobarList.thing' sample.yml
561+
```
562+
will output
563+
```yaml
564+
foo_thing
565+
```
566+
567+
## FIXED: Splatting merge anchors
568+
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Note that the keys earlier in the merge anchors sequence override later ones
569+
570+
Given a sample.yml file of:
571+
```yaml
572+
foo: &foo
573+
a: foo_a
574+
thing: foo_thing
575+
c: foo_c
576+
bar: &bar
577+
b: bar_b
578+
thing: bar_thing
579+
c: bar_c
580+
foobarList:
581+
b: foobarList_b
582+
!!merge <<:
583+
- *foo
584+
- *bar
585+
c: foobarList_c
586+
foobar:
587+
c: foobar_c
588+
!!merge <<: *foo
589+
thing: foobar_thing
590+
```
591+
then
592+
```bash
593+
yq '.foobar[]' sample.yml
594+
```
595+
will output
596+
```yaml
597+
foo_a
598+
foobar_thing
599+
foobar_c
600+
```
601+
602+
## FIXED: Splatting merge anchor lists
603+
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Note that the keys earlier in the merge anchors sequence override later ones
604+
605+
Given a sample.yml file of:
606+
```yaml
607+
foo: &foo
608+
a: foo_a
609+
thing: foo_thing
610+
c: foo_c
611+
bar: &bar
612+
b: bar_b
613+
thing: bar_thing
614+
c: bar_c
615+
foobarList:
616+
b: foobarList_b
617+
!!merge <<:
618+
- *foo
619+
- *bar
620+
c: foobarList_c
621+
foobar:
622+
c: foobar_c
623+
!!merge <<: *foo
624+
thing: foobar_thing
625+
```
626+
then
627+
```bash
628+
yq '.foobarList[]' sample.yml
629+
```
630+
will output
631+
```yaml
632+
foobarList_b
633+
foo_thing
634+
foobarList_c
635+
foo_a
636+
```
637+

pkg/yqlib/operator_traverse_path_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,6 @@ func TestTraversePathOperatorAlignedToSpecScenarios(t *testing.T) {
679679
for _, tt := range append(fixedTraversePathOperatorScenarios, traversePathOperatorScenarios...) {
680680
testScenario(t, &tt)
681681
}
682-
appendOperatorDocumentScenario(t, "anchor-and-alias-operators", fixedAnchorOperatorScenarios)
682+
appendOperatorDocumentScenario(t, "traverse-read", fixedTraversePathOperatorScenarios)
683683
ConfiguredYamlPreferences.FixMergeAnchorToSpec = false
684684
}

0 commit comments

Comments
 (0)