-
Notifications
You must be signed in to change notification settings - Fork 13
/
apply_test.go
59 lines (48 loc) · 1.07 KB
/
apply_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
package pipeline
import (
"context"
"strings"
"testing"
)
func TestLoopApply(t *testing.T) {
t.Parallel()
transform := NewProcessor(func(_ context.Context, s string) ([]string, error) {
return strings.Split(s, ","), nil
}, nil)
double := NewProcessor(func(_ context.Context, s string) (string, error) {
return s + s, nil
}, nil)
addLeadingZero := NewProcessor(func(_ context.Context, s string) (string, error) {
return "0" + s, nil
}, nil)
looper := Apply(
transform,
Sequence(
double,
addLeadingZero,
double,
),
)
gotCount := 0
input := "1,2,3,4,5"
want := []string{"011011", "022022", "033033", "044044", "055055"}
for out := range Process(context.Background(), looper, Emit(input)) {
for j := range out {
gotCount++
if !contains(want, out[j]) {
t.Errorf("does not contains got=%v, want=%v", out[j], want)
}
}
}
if gotCount != len(want) {
t.Errorf("total results got=%v, want=%v", gotCount, len(want))
}
}
func contains(s []string, e string) bool {
for i := range s {
if s[i] == e {
return true
}
}
return false
}