diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-12 14:20:52 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-05-12 14:20:52 +0000 |
| commit | 2aefc871b35db434fbc07af48cfe1b5f75a73076 (patch) | |
| tree | 7128f5a336cbc232c593122b0ae65363e81d4c24 /spec | |
| parent | make EvtStreams carry a single value (diff) | |
| download | alive-2aefc871b35db434fbc07af48cfe1b5f75a73076.tar.gz alive-2aefc871b35db434fbc07af48cfe1b5f75a73076.zip | |
RTNode constifies constant SigStreams
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/input_spec.moon | 15 | ||||
| -rw-r--r-- | spec/match_spec.moon | 13 | ||||
| -rw-r--r-- | spec/rtnode_spec.moon | 49 |
3 files changed, 55 insertions, 22 deletions
diff --git a/spec/input_spec.moon b/spec/input_spec.moon index 3a8eff9..9237fd8 100644 --- a/spec/input_spec.moon +++ b/spec/input_spec.moon @@ -28,6 +28,9 @@ describe 'Input.cold', -> basic_tests result, input + it 'is marked cold', -> + assert.is.equal 'cold', input.mode + it 'is never dirty', -> assert.is.false input\dirty! result\set 2 @@ -51,6 +54,9 @@ describe 'Input.hot', -> basic_tests result, input + it 'is marked cold', -> + assert.is.equal 'cold', input.mode + describe 'at evaltime', -> it 'is dirty when new', -> assert.is.false result\dirty! @@ -84,8 +90,8 @@ describe 'Input.hot', -> basic_tests result, input - it 'is marked for lifting', -> - assert.is.nil input.io + it 'is marked hot', -> + assert.is.equal 'hot', input.mode it 'is dirty when the EvtStream is dirty', -> assert.is.false input\dirty! @@ -115,7 +121,7 @@ describe 'Input.hot', -> basic_tests result, input it 'is marked for lifting', -> - assert.is.true input.io + assert.is.equal 'io', input.mode it 'is dirty when the IOStream is dirty', -> result.is_dirty = false @@ -172,6 +178,9 @@ describe 'Input.hot', -> assert.is.false newinput\dirty! newinput\finish_setup! + it 'is marked hot', -> + assert.is.equal 'hot', input.mode + describe 'at runtime', -> it 'is dirty when the result is dirty', -> result\set 3 diff --git a/spec/match_spec.moon b/spec/match_spec.moon index afaef56..8be64de 100644 --- a/spec/match_spec.moon +++ b/spec/match_spec.moon @@ -1,15 +1,18 @@ import val, evt from require 'alv.base.match' +import Op, Input from require 'alv.base' import RTNode, T, Error from require 'alv' +op_with_inputs = (inputs) -> + with Op! + \setup inputs if inputs + mk_val = (type, const) -> - result = T[type]\mk_sig! - with RTNode :result - .side_inputs = { 'fake' } unless const + result = T[type]\mk_sig true + RTNode :result, op: op_with_inputs { Input.hot result } mk_evt = (type, const) -> result = T[type]\mk_evt! - with RTNode :result - .side_inputs = { 'fake' } unless const + RTNode :result, op: op_with_inputs { Input.hot result } describe 'val and evt', -> describe 'type-less shorthand', -> diff --git a/spec/rtnode_spec.moon b/spec/rtnode_spec.moon index 9c62350..1719620 100644 --- a/spec/rtnode_spec.moon +++ b/spec/rtnode_spec.moon @@ -4,18 +4,23 @@ import T, Input, Op, Constant, IOStream from require 'alv.base' setup do_setup +class DirtyIO extends IOStream + new: => super T.dirty_io + dirty: => true + op_with_inputs = (inputs) -> with Op! \setup inputs if inputs +dirty_op = -> + result = DirtyIO! + input = Input.hot result + result, input, op_with_inputs { input } + node_with_sideinput = (result, input) -> with RTNode :result .side_inputs = { [result]: input } -class DirtyIO extends IOStream - new: => super T.dirty_io - dirty: => true - describe 'RTNode', -> it 'wraps result, children', -> result = Constant.num 3 @@ -69,23 +74,41 @@ describe 'RTNode', -> value_input = Input.hot value op = op_with_inputs { event_input, value_input } - node = RTNode op: op, result: value + node = RTNode :op, result: value assert.is.equal op, node.op assert.is.same { [event]: event_input, [value]: value_input }, node.side_inputs - it 'does not lift up op inputs that are also child values', -> + it 'does not lift up op inputs that are also children', -> + child_result, child_input, child_op = dirty_op! + result = T.num\mk_sig 4 + child = RTNode op: child_op, :result + event = T.bang\mk_evt! event_input = Input.hot event + input = Input.hot child - result = T.num\mk_sig 4 - value_input = Input.hot result + op = op_with_inputs { event_input, input } + node = RTNode :op, children: { child } - op = op_with_inputs { event_input, value_input } - node = RTNode op: op, :result, children: { RTNode :result } + assert.is.same { [event]: event_input, [child_result]: child_input }, + node.side_inputs + + it 'does not lift up op inputs that are cold', -> + bang = T.bang\mk_const true + bang_input = Input.hot bang + + num = T.num\mk_const 2 + num_input = Input.cold num + + sym = T.sym\mk_sig 'hello' + sym_input = Input.hot sym + + op = op_with_inputs { bang_input, num_input, sym_input } + node = RTNode :op - assert.is.same { [event]: event_input }, node.side_inputs + assert.is.same { [sym]: sym_input }, node.side_inputs it 'lifts up side_inputs from children', -> event_value = T.bang\mk_evt! @@ -169,9 +192,7 @@ describe 'RTNode', -> describe ':poll_io', -> it 'polls IOs referenced in side_inputs', -> - io = DirtyIO! - input = Input.hot io - op = op_with_inputs { input } + io, input, op = dirty_op! node = RTNode :op s = spy.on io, 'poll' |
