-
Notifications
You must be signed in to change notification settings - Fork 29
/
iterator_test.go
100 lines (78 loc) · 2.03 KB
/
iterator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package toolbox_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/viant/toolbox"
)
func TestSliceIterator(t *testing.T) {
{
slice := []string{"a", "r", "c"}
iterator := toolbox.NewSliceIterator(slice)
var values = make([]interface{}, 1)
value := values[0]
assert.True(t, iterator.HasNext())
err := iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, "a", value)
assert.True(t, iterator.HasNext())
err = iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, "r", value)
assert.True(t, iterator.HasNext())
err = iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, "c", value)
}
{
slice := []string{"a", "r", "c"}
iterator := toolbox.NewSliceIterator(slice)
value := ""
assert.True(t, iterator.HasNext())
err := iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, "a", value)
assert.True(t, iterator.HasNext())
err = iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, "r", value)
assert.True(t, iterator.HasNext())
err = iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, "c", value)
}
{
slice := []interface{}{"a", "z", "c"}
iterator := toolbox.NewSliceIterator(slice)
value := ""
assert.True(t, iterator.HasNext())
err := iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, "a", value)
assert.True(t, iterator.HasNext())
err = iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, "z", value)
var values = make([]interface{}, 1)
assert.True(t, iterator.HasNext())
err = iterator.Next(&values[0])
assert.Nil(t, err)
assert.Equal(t, "c", values[0])
}
{
slice := []int{3, 2, 1}
iterator := toolbox.NewSliceIterator(slice)
value := 0
assert.True(t, iterator.HasNext())
err := iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, 3, value)
assert.True(t, iterator.HasNext())
err = iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, 2, value)
assert.True(t, iterator.HasNext())
err = iterator.Next(&value)
assert.Nil(t, err)
assert.Equal(t, 1, value)
}
}