Reset ctx variables between calculating field VALUE and ASSERT

If the field value was changed in the VALUE statement, then the context variables were not reset to reflect this change in the ASSERT statement. As a result the ASSERT would receive the old values prior to being affected by the VALUE statement.
This commit is contained in:
Tobie Morgan Hitchcock 2017-12-04 10:09:49 +00:00
parent 14d3539dbf
commit 7733b7b129

View file

@ -271,6 +271,8 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
err = d.current.Walk(func(key string, val interface{}) (err error) {
vars := data.New()
var old = d.initial.Get(key).Data()
// Ensure the field is the correct type
@ -281,7 +283,8 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
}
}
vars := data.New()
// Reset the variables
vars.Set(val, varKeyValue)
vars.Set(val, varKeyAfter)
vars.Set(old, varKeyBefore)
@ -295,6 +298,13 @@ func (d *document) mrgFld(ctx context.Context) (err error) {
}
}
// Reset the variables
vars.Set(val, varKeyValue)
vars.Set(val, varKeyAfter)
vars.Set(old, varKeyBefore)
ctx = context.WithValue(ctx, ctxKeySubs, vars)
// We are checking the value of the field
if fd.Assert != nil {