mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Can add string to scalars in any order #1234
This commit is contained in:
parent
b9309a42a4
commit
60c037f57e
@ -103,6 +103,9 @@ func addScalars(context Context, target *CandidateNode, lhs *yaml.Node, rhs *yam
|
|||||||
} else if lhsTag == "!!str" {
|
} else if lhsTag == "!!str" {
|
||||||
target.Node.Tag = lhs.Tag
|
target.Node.Tag = lhs.Tag
|
||||||
target.Node.Value = lhs.Value + rhs.Value
|
target.Node.Value = lhs.Value + rhs.Value
|
||||||
|
} else if rhsTag == "!!str" {
|
||||||
|
target.Node.Tag = rhs.Tag
|
||||||
|
target.Node.Value = lhs.Value + rhs.Value
|
||||||
} else if lhsTag == "!!int" && rhsTag == "!!int" {
|
} else if lhsTag == "!!int" && rhsTag == "!!int" {
|
||||||
format, lhsNum, err := parseInt64(lhs.Value)
|
format, lhsNum, err := parseInt64(lhs.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -199,6 +199,24 @@ var addOperatorScenarios = []expressionScenario{
|
|||||||
"D0, P[], (doc)::{a: catmeow, b: meow}\n",
|
"D0, P[], (doc)::{a: catmeow, b: meow}\n",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "String concatenation - str + int",
|
||||||
|
skipDoc: true,
|
||||||
|
document: `{a: !cool cat, b: meow}`,
|
||||||
|
expression: `.a + 3`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[a], (!cool)::cat3\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: "String concatenation - int + str",
|
||||||
|
skipDoc: true,
|
||||||
|
document: `{a: !cool cat, b: meow}`,
|
||||||
|
expression: `3 + .a`,
|
||||||
|
expected: []string{
|
||||||
|
"D0, P[], (!cool)::3cat\n",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "Number addition - float",
|
description: "Number addition - float",
|
||||||
subdescription: "If the lhs or rhs are floats then the expression will be calculated with floats.",
|
subdescription: "If the lhs or rhs are floats then the expression will be calculated with floats.",
|
||||||
|
Loading…
Reference in New Issue
Block a user