-
Notifications
You must be signed in to change notification settings - Fork 0
/
many_test.go
46 lines (35 loc) · 877 Bytes
/
many_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
package piper
import (
"reflect"
"testing"
)
func TestManyReturnsElementsFromSlice(t *testing.T) {
many := &many{items: reflect.ValueOf([...]string{"a", "b", "c"})}
var s WrappedSource = many.Source
var result []reflect.Value
result, s = s()
if s == nil {
t.Fatal("Expected an element but none come next")
}
if result[0].String() != "a" {
t.Fatalf("Expected element 'a' but got %v", result)
}
result, s = s()
if s == nil {
t.Fatal("Expected a second element but none come next")
}
if result[0].String() != "b" {
t.Fatalf("Expected element 'b' but got %v", result)
}
result, s = s()
if s == nil {
t.Fatal("Expected a third element but none come next")
}
if result[0].String() != "c" {
t.Fatalf("Expected element 'c' but got %v", result)
}
result, s = s()
if s != nil {
t.Fatalf("Expected no more elements but got %v", result)
}
}