diff options
Diffstat (limited to 'spec/rtnode_spec.moon')
| -rw-r--r-- | spec/rtnode_spec.moon | 97 |
1 files changed, 49 insertions, 48 deletions
diff --git a/spec/rtnode_spec.moon b/spec/rtnode_spec.moon index a842a74..a6cd63d 100644 --- a/spec/rtnode_spec.moon +++ b/spec/rtnode_spec.moon @@ -1,6 +1,7 @@ import do_setup from require 'spec.test_setup' import RTNode, Scope, SimpleRegistry from require 'alv' -import Primitive, Input, Op, Constant, EvtStream, IOStream from require 'alv.base' +import Primitive, Input, Op, Constant, SigStream, EvtStream, IOStream + from require 'alv.base' setup do_setup num = Primitive 'num' @@ -10,99 +11,99 @@ op_with_inputs = (inputs) -> with Op! \setup inputs if inputs -result_with_sideinput = (value, input) -> - with RTNode :value - .side_inputs = { [value]: input } +node_with_sideinput = (result, input) -> + with RTNode :result + .side_inputs = { [result]: input } class DirtyIO extends IOStream new: => super Primitive 'dirty-io' dirty: => true describe 'RTNode', -> - it 'wraps value, children', -> - value = Constant.num 3 + it 'wraps result, children', -> + result = Constant.num 3 a = RTNode! b = RTNode! children = { a, b } - result = RTNode :value, :children + node = RTNode :result, :children - assert.is.equal value, result.value - assert.is.same children, result.children + assert.is.equal result, node.result + assert.is.same children, node.children it ':type gets type and assets value', -> - result = RTNode value: Constant.num 2 - assert.is.equal num, result\type! + node = RTNode result: Constant.num 2 + assert.is.equal num, node\type! - result = RTNode! - assert.has.error -> result\type! + node = RTNode! + assert.has.error -> node\type! it ':is_const', -> - value = Constant.num 2 - pure = RTNode :value - impure = result_with_sideinput value, {} + result = Constant.num 2 + pure = RTNode :result + impure = node_with_sideinput result, {} assert.is.true pure\is_const! assert.is.false impure\is_const! - assert.is.equal value, pure\const! + assert.is.equal result, pure\const! assert.has.error -> impure\const! assert.has.error (-> impure\const 'test'), 'test' it ':make_ref', -> - value = Constant.num 2 - input = Input.hot value + result = SigStream.num 2 + input = Input.hot result op = op_with_inputs { input } - thick = RTNode :value, :op, children: { RTNode!, RTNode! } + thick = RTNode :result, :op, children: { RTNode!, RTNode! } ref = thick\make_ref! assert ref - assert.is.equal thick.value, ref.value + assert.is.equal thick.result, ref.result assert.is.same thick.side_inputs, ref.side_inputs assert.is.same {}, ref.children assert.is.nil ref.op it 'lifts up inputs from op', -> - event = Constant bang, false + event = EvtStream bang event_input = Input.hot event - value = Constant num, 4 + value = SigStream num, 4 value_input = Input.hot value op = op_with_inputs { event_input, value_input } - result = RTNode op: op, :value + node = RTNode op: op, result: value - assert.is.equal op, result.op + assert.is.equal op, node.op assert.is.same { [event]: event_input, [value]: value_input }, - result.side_inputs + node.side_inputs it 'does not lift up op inputs that are also child values', -> - event = Constant bang, false + event = EvtStream bang event_input = Input.hot event - value = Constant num, 4 - value_input = Input.hot value + result = SigStream num, 4 + value_input = Input.hot result op = op_with_inputs { event_input, value_input } - result = RTNode op: op, :value, children: { RTNode :value } + node = RTNode op: op, :result, children: { RTNode :result } - assert.is.same { [event]: event_input }, result.side_inputs + assert.is.same { [event]: event_input }, node.side_inputs it 'lifts up side_inputs from children', -> - event_value = Constant bang, false + event_value = EvtStream bang event_input = Input.hot event_value event = RTNode op: op_with_inputs { event_input } assert.is.same { [event_value]: event_input }, event.side_inputs - value_value = Constant num, 4 + value_value = SigStream num, 4 value_input = Input.hot value_value value = RTNode op: op_with_inputs { value_input } assert.is.same { [value_value]: value_input }, value.side_inputs - result = RTNode children: { event, value } + node = RTNode children: { event, value } assert.is.same { [event_value]: event_input, [value_value]: value_input }, - result.side_inputs + node.side_inputs describe ':tick', -> local a_value, a_child, a_input @@ -110,11 +111,11 @@ describe 'RTNode', -> before_each -> a_value = EvtStream num a_input = Input.hot a_value - a_child = result_with_sideinput a_value, a_input + a_child = node_with_sideinput a_value, a_input b_value = EvtStream num b_input = Input.hot b_value - b_child = result_with_sideinput b_value, b_input + b_child = node_with_sideinput b_value, b_input it 'updates children when a side_input is dirty', -> a_value\add 1 @@ -124,8 +125,8 @@ describe 'RTNode', -> a = spy.on a_child, 'tick' b = spy.on b_child, 'tick' - result = RTNode children: { a_child, b_child } - result\tick! + node = RTNode children: { a_child, b_child } + node\tick! assert.spy(a).was_called_with match.ref a_child assert.spy(b).was_called_with match.ref b_child @@ -137,8 +138,8 @@ describe 'RTNode', -> a = spy.on a_child, 'tick' b = spy.on b_child, 'tick' - result = RTNode children: { a_child, b_child } - result\tick! + node = RTNode children: { a_child, b_child } + node\tick! assert.spy(a).was_not_called! assert.spy(b).was_not_called! @@ -151,8 +152,8 @@ describe 'RTNode', -> op = op_with_inputs a: Input.hot a_value s = spy.on op, 'tick' - result = RTNode :op, children: { a_child, b_child } - result\tick! + node = RTNode :op, children: { a_child, b_child } + node\tick! assert.spy(s).was_called_with match.ref op @@ -164,8 +165,8 @@ describe 'RTNode', -> op = op_with_inputs { Input.hot b_value } s = spy.on op, 'tick' - result = RTNode :op, children: { a_child, b_child } - result\tick! + node = RTNode :op, children: { a_child, b_child } + node\tick! assert.spy(s).was_not_called! @@ -174,10 +175,10 @@ describe 'RTNode', -> io = DirtyIO! input = Input.hot io op = op_with_inputs { input } - result = RTNode :op + node = RTNode :op s = spy.on io, 'poll' - assert.is.same { [io]: input }, result.side_inputs - result\poll_io! + assert.is.same { [io]: input }, node.side_inputs + node\poll_io! assert.spy(s).was_called_with match.ref io |
