iter-iter.go: check ctx against nil on creation
This commit is contained in:
+10
-2
@@ -12,6 +12,8 @@ import (
|
|||||||
"git.portale-stac.it/go-pkg/expr/scan"
|
"git.portale-stac.it/go-pkg/expr/scan"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const iterIterType = "IterIter"
|
||||||
|
|
||||||
type IterIter struct {
|
type IterIter struct {
|
||||||
it kern.Iterator
|
it kern.Iterator
|
||||||
count int64
|
count int64
|
||||||
@@ -22,7 +24,13 @@ type IterIter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewIterIter(it kern.Iterator, ctx kern.ExprContext, exprs []*scan.Term) (iter kern.Iterator, err error) {
|
func NewIterIter(it kern.Iterator, ctx kern.ExprContext, exprs []*scan.Term) (iter kern.Iterator, err error) {
|
||||||
iter = &IterIter{it: it, count: 0, index: -1, ctx: ctx, exprList: exprs, current: nil}
|
if ctx == nil {
|
||||||
|
err = fmt.Errorf("context is required for %s", iterIterType)
|
||||||
|
} else if it == nil {
|
||||||
|
err = fmt.Errorf("source iterator is required for %s", iterIterType)
|
||||||
|
} else {
|
||||||
|
iter = &IterIter{it: it, count: 0, index: -1, ctx: ctx, exprList: exprs, current: nil}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +39,7 @@ func (it *IterIter) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (it *IterIter) TypeName() string {
|
func (it *IterIter) TypeName() string {
|
||||||
return "IterIter"
|
return iterIterType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *IterIter) HasOperation(name string) bool {
|
func (it *IterIter) HasOperation(name string) bool {
|
||||||
|
|||||||
+3
-2
@@ -92,9 +92,10 @@ func TestNewIterList5(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewIterList6(t *testing.T) {
|
func TestNewIterList6(t *testing.T) {
|
||||||
|
ctx := NewSimpleStore()
|
||||||
list := kern.NewListA("a", "b", "c", "d")
|
list := kern.NewListA("a", "b", "c", "d")
|
||||||
it1, _ := NewIterator(nil, list, nil)
|
it1, _ := NewIterator(ctx, list, nil)
|
||||||
it, _ := NewIterator(nil, it1, nil)
|
it, _ := NewIterator(ctx, it1, nil)
|
||||||
if item, err := it.Next(); err != nil {
|
if item, err := it.Next(); err != nil {
|
||||||
t.Errorf("error: %v", err)
|
t.Errorf("error: %v", err)
|
||||||
} else if item != "a" {
|
} else if item != "a" {
|
||||||
|
|||||||
Reference in New Issue
Block a user