Fix Err fallout for graph/iterator.Or iterator
This commit is contained in:
parent
40cbbfcc1b
commit
aaa3f27754
2 changed files with 54 additions and 0 deletions
|
|
@ -33,6 +33,7 @@ type Or struct {
|
||||||
itCount int
|
itCount int
|
||||||
currentIterator int
|
currentIterator int
|
||||||
result graph.Value
|
result graph.Value
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOr() *Or {
|
func NewOr() *Or {
|
||||||
|
|
@ -147,6 +148,11 @@ func (it *Or) Next() bool {
|
||||||
return graph.NextLogOut(it, it.result, true)
|
return graph.NextLogOut(it, it.result, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := graph.Err(curIt); err != nil {
|
||||||
|
it.err = err
|
||||||
|
return graph.NextLogOut(it, nil, false)
|
||||||
|
}
|
||||||
|
|
||||||
if it.isShortCircuiting && !first {
|
if it.isShortCircuiting && !first {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -159,6 +165,10 @@ func (it *Or) Next() bool {
|
||||||
return graph.NextLogOut(it, nil, false)
|
return graph.NextLogOut(it, nil, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (it *Or) Err() error {
|
||||||
|
return it.err
|
||||||
|
}
|
||||||
|
|
||||||
func (it *Or) Result() graph.Value {
|
func (it *Or) Result() graph.Value {
|
||||||
return it.result
|
return it.result
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
package iterator
|
package iterator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
@ -148,3 +149,46 @@ func TestShortCircuitingOrBasics(t *testing.T) {
|
||||||
t.Errorf("Failed to iterate optimized Or correctly, got:%v expect:%v", got, expect)
|
t.Errorf("Failed to iterate optimized Or correctly, got:%v expect:%v", got, expect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOrIteratorErr(t *testing.T) {
|
||||||
|
retErr := errors.New("unique")
|
||||||
|
orErr := newTestIterator(false, retErr)
|
||||||
|
|
||||||
|
fix1 := NewFixed(Identity)
|
||||||
|
fix1.Add(1)
|
||||||
|
|
||||||
|
or := NewOr()
|
||||||
|
or.AddSubIterator(fix1)
|
||||||
|
or.AddSubIterator(orErr)
|
||||||
|
or.AddSubIterator(NewInt64(1, 5))
|
||||||
|
|
||||||
|
if !or.Next() {
|
||||||
|
t.Errorf("Failed to iterate Or correctly")
|
||||||
|
}
|
||||||
|
if got := or.Result(); got != 1 {
|
||||||
|
t.Errorf("Failed to iterate Or correctly, got:%v expect:1", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if or.Next() != false {
|
||||||
|
t.Errorf("Or iterator did not pass through underlying 'false'")
|
||||||
|
}
|
||||||
|
if or.Err() != retErr {
|
||||||
|
t.Errorf("Or iterator did not pass through underlying Err")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestShortCircuitOrIteratorErr(t *testing.T) {
|
||||||
|
retErr := errors.New("unique")
|
||||||
|
orErr := newTestIterator(false, retErr)
|
||||||
|
|
||||||
|
or := NewOr()
|
||||||
|
or.AddSubIterator(orErr)
|
||||||
|
or.AddSubIterator(NewInt64(1, 5))
|
||||||
|
|
||||||
|
if or.Next() != false {
|
||||||
|
t.Errorf("Or iterator did not pass through underlying 'false'")
|
||||||
|
}
|
||||||
|
if or.Err() != retErr {
|
||||||
|
t.Errorf("Or iterator did not pass through underlying Err")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue