Skip to content

Commit 60c037f

Browse files
committed
Can add string to scalars in any order #1234
1 parent b9309a4 commit 60c037f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pkg/yqlib/operator_add.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ func addScalars(context Context, target *CandidateNode, lhs *yaml.Node, rhs *yam
103103
} else if lhsTag == "!!str" {
104104
target.Node.Tag = lhs.Tag
105105
target.Node.Value = lhs.Value + rhs.Value
106+
} else if rhsTag == "!!str" {
107+
target.Node.Tag = rhs.Tag
108+
target.Node.Value = lhs.Value + rhs.Value
106109
} else if lhsTag == "!!int" && rhsTag == "!!int" {
107110
format, lhsNum, err := parseInt64(lhs.Value)
108111
if err != nil {

pkg/yqlib/operator_add_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ var addOperatorScenarios = []expressionScenario{
199199
"D0, P[], (doc)::{a: catmeow, b: meow}\n",
200200
},
201201
},
202+
{
203+
description: "String concatenation - str + int",
204+
skipDoc: true,
205+
document: `{a: !cool cat, b: meow}`,
206+
expression: `.a + 3`,
207+
expected: []string{
208+
"D0, P[a], (!cool)::cat3\n",
209+
},
210+
},
211+
{
212+
description: "String concatenation - int + str",
213+
skipDoc: true,
214+
document: `{a: !cool cat, b: meow}`,
215+
expression: `3 + .a`,
216+
expected: []string{
217+
"D0, P[], (!cool)::3cat\n",
218+
},
219+
},
202220
{
203221
description: "Number addition - float",
204222
subdescription: "If the lhs or rhs are floats then the expression will be calculated with floats.",

0 commit comments

Comments
 (0)