mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-24 06:35:40 +00:00
Fixes #1123
This commit is contained in:
parent
6c220d4562
commit
ff047d0748
@ -124,7 +124,9 @@ func (n *CandidateNode) Copy() (*CandidateNode, error) {
|
|||||||
func (n *CandidateNode) UpdateFrom(other *CandidateNode, prefs assignPreferences) {
|
func (n *CandidateNode) UpdateFrom(other *CandidateNode, prefs assignPreferences) {
|
||||||
|
|
||||||
// if this is an empty map or empty array, use the style of other node.
|
// if this is an empty map or empty array, use the style of other node.
|
||||||
if n.Node.Kind != yaml.ScalarNode && len(n.Node.Content) == 0 {
|
if (n.Node.Kind != yaml.ScalarNode && len(n.Node.Content) == 0) ||
|
||||||
|
// if the tag has changed (e.g. from str to bool)
|
||||||
|
(guessTagFromCustomType(n.Node) != guessTagFromCustomType(other.Node)) {
|
||||||
n.Node.Style = other.Node.Style
|
n.Node.Style = other.Node.Style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,33 @@ var assignOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (doc)::a:\n - cat\n",
|
"D0, P[], (doc)::a:\n - cat\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "change to number when old value is valid number",
|
||||||
|
document: `a: "3"`,
|
||||||
|
expression: `.a = 3`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (doc)::a: 3\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "change to bool when old value is valid bool",
|
||||||
|
document: `a: "true"`,
|
||||||
|
expression: `.a = true`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (doc)::a: true\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
skipDoc: true,
|
||||||
|
description: "update custom tag string, dont clobber style",
|
||||||
|
document: `a: !cat "meow"`,
|
||||||
|
expression: `.a = "woof"`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (doc)::a: !cat \"woof\"\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Update node to be the child value",
|
description: "Update node to be the child value",
|
||||||
document: `{a: {b: {g: foof}}}`,
|
document: `{a: {b: {g: foof}}}`,
|
||||||
|
Loading…
Reference in New Issue
Block a user