-
Notifications
You must be signed in to change notification settings - Fork 338
/
single_test.go
70 lines (58 loc) · 1.22 KB
/
single_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
package rxgo
import (
"testing"
"github.com/reactivex/rxgo/handlers"
"github.com/reactivex/rxgo/optional"
"github.com/stretchr/testify/assert"
)
func TestSingleFilterNotMatching(t *testing.T) {
got := 0
Just(1, 2, 3).ElementAt(1).Filter(func(i interface{}) bool {
switch i := i.(type) {
case int:
if i == 2 {
return true
}
}
return false
}).Subscribe(handlers.NextFunc(func(i interface{}) {
switch i := i.(type) {
case optional.Optional:
if !i.IsEmpty() {
g, _ := i.Get()
got = g.(int)
}
}
})).Block()
assert.Equal(t, 2, got)
}
func TestSingleFilterMatching(t *testing.T) {
got := 0
Just(1, 2, 3).ElementAt(1).Filter(func(i interface{}) bool {
switch i := i.(type) {
case int:
if i == 2 {
return false
}
}
return true
}).Subscribe(handlers.NextFunc(func(i interface{}) {
switch i := i.(type) {
case optional.Optional:
if !i.IsEmpty() {
g, _ := i.Get()
got = g.(int)
}
}
})).Block()
assert.Equal(t, 0, got)
}
func TestSingleMap(t *testing.T) {
got := 0
Just(1, 2, 3).ElementAt(1).Map(func(i interface{}) interface{} {
return i
}).Subscribe(handlers.NextFunc(func(i interface{}) {
got = i.(int) + 10
})).Block()
assert.Equal(t, 12, got)
}