This commit is contained in:
Mike Farah 2021-07-07 14:29:24 +10:00
parent f285a684ec
commit d1b6a6fdd9
3 changed files with 22 additions and 2 deletions

View File

@ -66,3 +66,9 @@ func (n *Context) ReadOnlyClone() Context {
clone.DontAutoCreate = true clone.DontAutoCreate = true
return clone return clone
} }
func (n *Context) WritableClone() Context {
clone := n.Clone()
clone.DontAutoCreate = false
return clone
}

View File

@ -32,11 +32,11 @@ func multiply(preferences multiplyPreferences) func(d *dataTreeNavigator, contex
var newBlank = lhs.CreateChild(nil, &yaml.Node{}) var newBlank = lhs.CreateChild(nil, &yaml.Node{})
var newThing, err = mergeObjects(d, context, newBlank, lhs, multiplyPreferences{}) var newThing, err = mergeObjects(d, context.WritableClone(), newBlank, lhs, multiplyPreferences{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
return mergeObjects(d, context, newThing, rhs, preferences) return mergeObjects(d, context.WritableClone(), newThing, rhs, preferences)
} else if lhs.Node.Tag == "!!int" && rhs.Node.Tag == "!!int" { } else if lhs.Node.Tag == "!!int" && rhs.Node.Tag == "!!int" {
return multiplyIntegers(lhs, rhs) return multiplyIntegers(lhs, rhs)
} else if (lhs.Node.Tag == "!!int" || lhs.Node.Tag == "!!float") && (rhs.Node.Tag == "!!int" || rhs.Node.Tag == "!!float") { } else if (lhs.Node.Tag == "!!int" || lhs.Node.Tag == "!!float") && (rhs.Node.Tag == "!!int" || rhs.Node.Tag == "!!float") {

View File

@ -47,6 +47,20 @@ var multiplyOperatorScenarios = []expressionScenario{
docExpected, docExpected,
}, },
}, },
{
skipDoc: true,
expression: `.x = {"things": "whatever"} * {}`,
expected: []string{
"D0, P[], ()::x:\n things: whatever\n",
},
},
{
skipDoc: true,
expression: `.x = {} * {"things": "whatever"}`,
expected: []string{
"D0, P[], ()::x:\n things: whatever\n",
},
},
{ {
skipDoc: true, skipDoc: true,
expression: `3 * 4.5`, expression: `3 * 4.5`,