data-cursor.go: fixed filter

This commit is contained in:
Celestino Amoroso 2024-07-13 00:12:08 +02:00
parent a02f998fc6
commit 8547248ea2
2 changed files with 3 additions and 6 deletions

View File

@ -166,9 +166,8 @@ func (dc *dataCursor) filter(item any) (filterdItem any, err error) {
func (dc *dataCursor) Next() (item any, err error) { // must return io.EOF after the last item func (dc *dataCursor) Next() (item any, err error) { // must return io.EOF after the last item
if dc.resource != nil { if dc.resource != nil {
ctx := cloneContext(dc.ctx)
// fmt.Printf("Entering Inner-Ctx [%p]: %s\n", ctx, CtxToString(ctx, 0))
for item == nil && err == nil { for item == nil && err == nil {
ctx := cloneContext(dc.ctx)
if item, err = dc.nextFunc.Invoke(ctx, nextName, []any{dc.resource}); err == nil { if item, err = dc.nextFunc.Invoke(ctx, nextName, []any{dc.resource}); err == nil {
if item == nil { if item == nil {
err = io.EOF err = io.EOF
@ -177,10 +176,8 @@ func (dc *dataCursor) Next() (item any, err error) { // must return io.EOF after
item, err = dc.filter(item) item, err = dc.filter(item)
} }
} }
exportObjects(dc.ctx, ctx)
} }
// fmt.Printf("Exiting Inner-Ctx [%p]: %s\n", ctx, CtxToString(ctx, 0))
exportObjects(dc.ctx, ctx)
// fmt.Printf("Outer-Ctx [%p]: %s\n", dc.ctx, CtxToString(dc.ctx, 0))
} else { } else {
err = errInvalidDataSource() err = errInvalidDataSource()
} }

View File

@ -20,7 +20,7 @@ func TestIteratorParser(t *testing.T) {
/* 9 */ {`include "test-resources/file-reader.expr"; it=$(ds,"test-resources/int.list"); it.clean`, true, nil}, /* 9 */ {`include "test-resources/file-reader.expr"; it=$(ds,"test-resources/int.list"); it.clean`, true, nil},
/* 10 */ {`it=$(1,2,3); it++`, int64(1), nil}, /* 10 */ {`it=$(1,2,3); it++`, int64(1), nil},
/* 11 */ {`it=$(1,2,3); it++; it.reset; it++`, int64(1), nil}, /* 11 */ {`it=$(1,2,3); it++; it.reset; it++`, int64(1), nil},
// /* 12 */ {`include "test-resources/filter.expr"; it=$(ds,10); it++`, int64(1), nil}, /* 12 */ {`include "test-resources/filter.expr"; it=$(ds,10); it++`, int64(1), nil},
} }
//runTestSuiteSpec(t, section, inputs, 12) //runTestSuiteSpec(t, section, inputs, 12)