-
Notifications
You must be signed in to change notification settings - Fork 1
/
always_test.go
52 lines (39 loc) · 981 Bytes
/
always_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
package incr
import (
"context"
"testing"
"github.com/wcharczuk/go-incr/testutil"
)
func Test_Always(t *testing.T) {
g := New()
v := Var(g, "foo")
v.Node().SetLabel("v")
m0 := Map(g, v, ident)
m0.Node().SetLabel("m0")
a := Always(g, m0)
a.Node().SetLabel("a")
m1 := Map(g, a, ident)
m1.Node().SetLabel("m1")
a.(IAlways).Always() // does nothing
var updates int
m1.Node().OnUpdate(func(_ context.Context) {
updates++
})
o := MustObserve(g, m1)
testutil.Equal(t, 0, v.Node().height)
testutil.Equal(t, 1, m0.Node().height)
testutil.Equal(t, 2, a.Node().height)
testutil.Equal(t, 3, m1.Node().height)
testutil.Equal(t, -1, o.Node().height)
ctx := testContext()
_ = g.Stabilize(ctx)
testutil.Equal(t, "foo", o.Value())
testutil.Equal(t, 1, updates)
_ = g.Stabilize(ctx)
testutil.Equal(t, "foo", o.Value())
testutil.Equal(t, 2, updates)
v.Set("bar")
_ = g.Stabilize(ctx)
testutil.Equal(t, "bar", o.Value())
testutil.Equal(t, 3, updates)
}