mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-07 14:25:38 +00:00
Adding some tests
This commit is contained in:
parent
30e16a33c3
commit
5cf0adcc5b
@ -106,6 +106,31 @@ func TestCreateScalarNodeScenarios(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type createStringScalarNodeScenario struct {
|
||||||
|
stringValue string
|
||||||
|
expectedTag string
|
||||||
|
}
|
||||||
|
|
||||||
|
var createStringScalarNodeScenarios = []createStringScalarNodeScenario{
|
||||||
|
{
|
||||||
|
stringValue: "yourKey",
|
||||||
|
expectedTag: "!!str",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
stringValue: "<<",
|
||||||
|
expectedTag: "!!merge",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateStringScalarNodeScenarios(t *testing.T) {
|
||||||
|
for _, tt := range createStringScalarNodeScenarios {
|
||||||
|
actual := createStringScalarNode(tt.stringValue)
|
||||||
|
test.AssertResultWithContext(t, tt.stringValue, actual.Value, fmt.Sprintf("Value for: %v", tt.stringValue))
|
||||||
|
test.AssertResultWithContext(t, tt.expectedTag, actual.Tag, fmt.Sprintf("Tag for: %v", tt.stringValue))
|
||||||
|
test.AssertResultWithContext(t, ScalarNode, actual.Kind, fmt.Sprintf("Kind for: %v", tt.stringValue))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetKeyForMapValue(t *testing.T) {
|
func TestGetKeyForMapValue(t *testing.T) {
|
||||||
key := createStringScalarNode("yourKey")
|
key := createStringScalarNode("yourKey")
|
||||||
n := CandidateNode{Key: key, Value: "meow", document: 3}
|
n := CandidateNode{Key: key, Value: "meow", document: 3}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Use the `alias` and `anchor` operators to read and write yaml aliases and anchors. The `explode` operator normalises a yaml file (dereference (or expands) aliases and remove anchor names).
|
Use the `alias` and `anchor` operators to read and write yaml aliases and anchors. The `explode` operator normalises a yaml file (dereference (or expands) aliases and remove anchor names).
|
||||||
|
|
||||||
`yq` supports merge aliases (like `<<: *blah`) however this is no longer in the standard yaml spec (1.2) and so `yq` will automatically add the `!!merge` tag to these nodes as it is effectively a custom tag.
|
`yq` supports merge keys (like `<<: *blah`) from YAML 1.1. These are no longer part of the YAML 1.2 standard, but remain common in practice. Plain `<<:` keys are recognised as merge keys and round-trip as `<<:` without an explicit `!!merge` tag. When the source uses an explicit `!!merge` tag, that is preserved on output. Internally, when `yq` synthesises a `<<` map key (for example during merge operations), it tags the key as `!!merge` rather than `!!str`.
|
||||||
|
|
||||||
|
|
||||||
## NOTE --yaml-fix-merge-anchor-to-spec flag
|
## NOTE --yaml-fix-merge-anchor-to-spec flag
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Use the `alias` and `anchor` operators to read and write yaml aliases and anchors. The `explode` operator normalises a yaml file (dereference (or expands) aliases and remove anchor names).
|
Use the `alias` and `anchor` operators to read and write yaml aliases and anchors. The `explode` operator normalises a yaml file (dereference (or expands) aliases and remove anchor names).
|
||||||
|
|
||||||
`yq` supports merge aliases (like `<<: *blah`) however this is no longer in the standard yaml spec (1.2) and so `yq` will automatically add the `!!merge` tag to these nodes as it is effectively a custom tag.
|
`yq` supports merge keys (like `<<: *blah`) from YAML 1.1. These are no longer part of the YAML 1.2 standard, but remain common in practice. Plain `<<:` keys are recognised as merge keys and round-trip as `<<:` without an explicit `!!merge` tag. When the source uses an explicit `!!merge` tag, that is preserved on output. Internally, when `yq` synthesises a `<<` map key (for example during merge operations), it tags the key as `!!merge` rather than `!!str`.
|
||||||
|
|
||||||
|
|
||||||
## NOTE --yaml-fix-merge-anchor-to-spec flag
|
## NOTE --yaml-fix-merge-anchor-to-spec flag
|
||||||
|
|||||||
@ -230,7 +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",
|
||||||
expected: "a: &remember\n c: mike\nb:\n <<: *remember\n",
|
expected: "a: &remember\n c: mike\nb:\n <<: *remember\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "custom tag",
|
description: "custom tag",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user