increased test coverage (83.9%)
This commit is contained in:
+79
-1
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
"git.portale-stac.it/go-pkg/expr/scan"
|
||||
)
|
||||
|
||||
func TestIteratorParser(t *testing.T) {
|
||||
@@ -35,12 +36,89 @@ func TestIteratorParser(t *testing.T) {
|
||||
/* 20 */ {`it=$({1:"one",2:"two",3:"three"}, "default", "value"); it++`, "one", nil},
|
||||
/* 21 */ {`it=$({1:"one",2:"two",3:"three"}, "desc", "key"); it++`, int64(3), nil},
|
||||
/* 22 */ {`it=$({1:"one",2:"two",3:"three"}, "asc", "item"); it++`, kern.NewList([]any{int64(1), "one"}), nil},
|
||||
/* 23 */ {`$$($(1,4,0))`, nil, `step cannot be zero`},
|
||||
/* 24 */ {`$$($(1,4,-1))`, nil, `step cannot be negative when start < stop`},
|
||||
/* 25 */ {`$$($(4,1,1))`, nil, `step cannot be positive when start > stop`},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 1)
|
||||
// runTestSuiteSpec(t, section, inputs, 25)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestCallOpIntIter(t *testing.T) {
|
||||
section := "IntIterator-CallOp"
|
||||
|
||||
if it, err := NewIntIteratorA(int64(1), int64(4), int64(1)); err != nil {
|
||||
t.Errorf(`%s -- NewIntIteratorA() failed: %v`, section, err)
|
||||
} else {
|
||||
testIteratorCallOp(t, section, it)
|
||||
testIterAttrs(t, section, it, "IntIterator", "$(1..4..1)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallOpIterIter(t *testing.T) {
|
||||
section := "IterIterator-CallOp"
|
||||
|
||||
ctx := NewSimpleStore()
|
||||
if inner, err := NewIntIteratorA(int64(1), int64(4), int64(1)); err == nil {
|
||||
if it, err := NewIterIter(inner, ctx, []*scan.Term{}); err != nil {
|
||||
t.Errorf(`%s -- NewIterIter() failed: %v`, section, err)
|
||||
} else {
|
||||
testIteratorCallOp(t, section, it)
|
||||
testIterAttrs(t, section, it, "IterIter", "$($(1..4..1))")
|
||||
}
|
||||
} else {
|
||||
t.Errorf(`%s -- can't create inner iterator: %v`, section, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallOpDictIter(t *testing.T) {
|
||||
section := "DictIterator-CallOp"
|
||||
|
||||
inner := kern.NewDict(map[any]any{"a": 1})
|
||||
if it, err := NewDictIterator(inner, nil); err != nil {
|
||||
t.Errorf(`%s -- NewIterIter() failed: %v`, section, err)
|
||||
} else {
|
||||
testIteratorCallOp(t, section, it)
|
||||
testIterAttrs(t, section, it, "DictIterator", "$({#1})")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallOpLinkedListIter(t *testing.T) {
|
||||
section := "LinkedListIterator-CallOp"
|
||||
|
||||
inner := kern.NewLinkedListA(1, 2, 3)
|
||||
it := NewLinkedListIterator(inner, nil)
|
||||
testIteratorCallOp(t, section, it)
|
||||
|
||||
// wanted := "$([<#3>])"
|
||||
// got := it.String()
|
||||
// if wanted != got {
|
||||
// t.Errorf(`%s -- LinkedListIterator.String() failed: expected %q, got %q`, section, wanted, got)
|
||||
// }
|
||||
|
||||
// wanted = "LinkedListIterator"
|
||||
// got = it.TypeName()
|
||||
// if wanted != got {
|
||||
// t.Errorf(`%s -- LinkedListIterator.TypeName() failed: expected %q, got %q`, section, wanted, got)
|
||||
// }
|
||||
testIterAttrs(t, section, it, "LinkedListIterator", "$([<#3>])")
|
||||
}
|
||||
|
||||
func testIterAttrs(t *testing.T, section string, it kern.Iterator, name, repr string) {
|
||||
wanted := repr
|
||||
got := it.String()
|
||||
if wanted != got {
|
||||
t.Errorf(`%s -- %s.String() failed: expected %q, got %q`, section, name, wanted, got)
|
||||
}
|
||||
|
||||
wanted = name
|
||||
got = it.TypeName()
|
||||
if wanted != got {
|
||||
t.Errorf(`%s -- %s.TypeName() failed: expected %q, got %q`, section, name, wanted, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterIterator(t *testing.T) {
|
||||
section := "Iterator-Filter"
|
||||
inputs := []inputType{
|
||||
|
||||
Reference in New Issue
Block a user