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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
import do_setup from require 'spec.test_setup'
import Input, Result, ValueStream, EventStream, IOStream from require 'alv.base'
setup do_setup
class MyIO extends IOStream
new: => super 'my-io'
dirty: => @is_dirty
basic_tests = (stream, input) ->
it 'gives access to the Stream', ->
assert.is.equal stream, input.stream
it 'forwards :unwrap', ->
assert.is.same stream\unwrap!, input\unwrap!
assert.is.same stream\unwrap!, input!
it 'gives access to the type string', ->
assert.is.equal stream.type, input\type!
it 'gives access to the metatype string', ->
assert.is.equal stream.metatype, input\metatype!
describe 'Input.cold', ->
stream = ValueStream.num 1
input = Input.cold stream
basic_tests stream, input
it 'is never dirty', ->
assert.is.false input\dirty!
stream\set 2
assert.is.false input\dirty!
input\setup nil
assert.is.false input\dirty!
input\finish_setup!
new_input = Input.cold ValueStream.num 3
new_input\setup input
assert.is.false new_input\dirty!
new_input.stream\set 4
assert.is.false new_input\dirty!
input\finish_setup!
describe 'Input.hot', ->
describe 'with EventStream', ->
stream = EventStream 'num'
input = Input.hot stream
basic_tests stream, input
it 'is marked for lifting', ->
assert.is.nil input.io
it 'is dirty when the EventStream is dirty', ->
assert.is.false input\dirty!
assert.is.false stream\dirty!
input\setup nil
assert.is.false input\dirty!
input\finish_setup!
COPILOT\next_tick!
stream\add 1
assert.is.true input\dirty!
assert.is.true stream\dirty!
input\setup nil
assert.is.true input\dirty!
input\finish_setup!
assert.is.true input\dirty!
assert.is.true stream\dirty!
describe 'with IOStream', ->
stream = MyIO!
input = Input.hot stream
basic_tests stream, input
it 'is marked for lifting', ->
assert.is.true input.io
it 'is dirty when the IOStream is dirty', ->
stream.is_dirty = false
assert.is.false input\dirty!
assert.is.false stream\dirty!
input\setup nil
assert.is.false input\dirty!
input\finish_setup!
COPILOT\next_tick!
stream.is_dirty = true
assert.is.true input\dirty!
assert.is.true stream\dirty!
input\setup nil
assert.is.true input\dirty!
input\finish_setup!
assert.is.true input\dirty!
assert.is.true stream\dirty!
describe 'with ValueStream', ->
stream = ValueStream.num 1
local input
describe 'at evaltime', ->
it 'is dirty when new', ->
assert.is.false stream\dirty!
input = Input.hot stream
input\setup nil
assert.is.true input\dirty!
input\finish_setup!
it 'is dirty when different', ->
newval = ValueStream.num 2
assert.is.false newval\dirty!
newinput = Input.hot newval
newinput\setup input
assert.is.true newinput\dirty!
newinput\finish_setup!
it 'is not dirty when equal', ->
newval = ValueStream.num!
newval\set 1
assert.is.true newval\dirty!
newinput = Input.hot newval
newinput\setup input
assert.is.false newinput\dirty!
newinput\finish_setup!
describe 'at runtime', ->
it 'is dirty when the stream is dirty', ->
stream\set 3
assert.is.true stream\dirty!
assert.is.true input\dirty!
COPILOT\next_tick!
assert.is.false stream\dirty!
assert.is.false input\dirty!
|