aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-05-08 11:41:56 +0000
committers-ol <s-ol@users.noreply.github.com>2020-05-08 11:45:39 +0000
commitac9bb22732c23ad4f9ff632f3eb2a197ceca7892 (patch)
tree7ef94917067cc38c322d31f5151f38bc092152a7 /spec
parentfix docs (diff)
downloadalive-ac9bb22732c23ad4f9ff632f3eb2a197ceca7892.tar.gz
alive-ac9bb22732c23ad4f9ff632f3eb2a197ceca7892.zip
rename RTNode.value to RTNode.result (to match Result class)
Diffstat (limited to 'spec')
-rw-r--r--spec/input_spec.moon2
-rw-r--r--spec/match_spec.moon21
-rw-r--r--spec/result/const_spec.moon6
-rw-r--r--spec/rtnode_spec.moon97
-rw-r--r--spec/scope_spec.moon40
5 files changed, 82 insertions, 84 deletions
diff --git a/spec/input_spec.moon b/spec/input_spec.moon
index 371a3ee..8a8defe 100644
--- a/spec/input_spec.moon
+++ b/spec/input_spec.moon
@@ -12,7 +12,7 @@ class MyIO extends IOStream
dirty: => @is_dirty
basic_tests = (stream, input) ->
- it 'gives access to the Stream', ->
+ it 'gives access to the Result', ->
assert.is.equal stream, input.stream
it 'forwards :unwrap', ->
diff --git a/spec/match_spec.moon b/spec/match_spec.moon
index e3483e3..1e2ce61 100644
--- a/spec/match_spec.moon
+++ b/spec/match_spec.moon
@@ -1,14 +1,14 @@
import val, evt from require 'alv.base.match'
-import RTNode, Primitive, SigStream, EvtStream from require 'alv'
+import RTNode, Primitive, SigStream, EvtStream, Error from require 'alv'
mk_val = (type, const) ->
- value = SigStream Primitive type
- with RTNode :value
+ result = SigStream Primitive type
+ with RTNode :result
.side_inputs = { 'fake' } unless const
mk_evt = (type, const) ->
- value = EvtStream Primitive type
- with RTNode :value
+ result = EvtStream Primitive type
+ with RTNode :result
.side_inputs = { 'fake' } unless const
describe 'val and evt', ->
@@ -224,11 +224,13 @@ describe 'complex nesting', ->
bang = mk_evt 'bang'
str = mk_val 'str'
num = mk_val 'num'
- pattern = -evt.bang + val.num*4 + (val.str + (val.num / val.str))\named('key', 'val')^0
+ pattern = -evt.bang + val.num*4 +
+ (val.str + (val.num / val.str))\named('key', 'val')^0
it 'just works', ->
assert.is.same { bang, { num, num }, {} }, pattern\match { bang, num, num }
- assert.is.same { nil, { num }, { { key: str, val: num }, { key: str, val: str } } },
+ assert.is.same { nil, { num }, { { key: str, val: num },
+ { key: str, val: str } } },
pattern\match { num, str, num, str, str }
assert.has.error -> pattern\match { num, str }
assert.has.error -> pattern\match { bang, num, num, num, num, num, num }
@@ -238,3 +240,8 @@ describe 'complex nesting', ->
it 'stringifies well', ->
assert.is.equal '(bang!? num{1-4} (str (num | str)){0-*})', tostring pattern
+
+ it 'gives useful error feedback', ->
+ msg = "couldn't match arguments (num~ str~ bool~) against pattern #{pattern}"
+ err = Error 'argument', msg
+ assert.has.error (-> pattern\match { num, str, mk_val 'bool' }), err
diff --git a/spec/result/const_spec.moon b/spec/result/const_spec.moon
index 55d5175..31eec4e 100644
--- a/spec/result/const_spec.moon
+++ b/spec/result/const_spec.moon
@@ -111,9 +111,9 @@ describe 'Constant', ->
it 'looks up symbols in the scope', ->
scope = with Scope!
- \set 'number', RTNode value: Constant.num 3
- \set 'hello', RTNode value: Constant.str "world"
- \set 'goodbye', RTNode value: Constant.sym "again"
+ \set 'number', RTNode result: Constant.num 3
+ \set 'hello', RTNode result: Constant.str "world"
+ \set 'goodbye', RTNode result: Constant.sym "again"
assert_eval = (sym, val) ->
const = Constant.sym sym
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
diff --git a/spec/scope_spec.moon b/spec/scope_spec.moon
index 4798391..7278b9e 100644
--- a/spec/scope_spec.moon
+++ b/spec/scope_spec.moon
@@ -6,7 +6,7 @@ Logger\init 'silent'
class TestOp extends Op
new: (...) => super ...
-wrap_res = (value) -> RTNode :value
+wrap_res = (result) -> RTNode :result
num = Primitive 'num'
str = Primitive 'str'
@@ -21,36 +21,31 @@ describe 'Scope', ->
scope\set_raw 'num', 3
got = (scope\get 'num')\const!
- assert.is.equal num, got.type
- assert.is.equal 3, got.value
+ assert.is.equal (Constant.num 3), got
test 'strings', ->
scope\set_raw 'str', "im a happy string"
got = (scope\get 'str')\const!
- assert.is.equal str, got.type
- assert.is.equal "im a happy string", got.value
+ assert.is.equal (Constant.str "im a happy string"), got
test 'Values', ->
pi = Constant.num 3.14
scope\set_raw 'pi', pi
-
assert.is.equal pi, (scope\get 'pi')\const!
test 'Opdefs', ->
scope\set_raw 'test', TestOp
got = (scope\get 'test')\const!
- assert.is.equal opdef, got.type
- assert.is.equal TestOp, got.value
+ assert.is.equal TestOp, got opdef
test 'Scopes', ->
sub = Scope!
scope\set_raw 'sub', sub
got = (scope\get 'sub')\const!
- assert.is.equal scope_t, got.type
- assert.is.equal sub, got.value
+ assert.is.equal sub, got scope_t
test 'tables', ->
pi = Constant.num 3.14
@@ -73,18 +68,15 @@ describe 'Scope', ->
}
got = (scope\get 'num')\const!
- assert.is.equal num, got.type
- assert.is.equal 3, got.value
+ assert.is.equal 3, got num
got = (scope\get 'str')\const!
- assert.is.equal str, got.type
- assert.is.equal "im a happy string", got.value
+ assert.is.equal "im a happy string", got str
assert.is.equal pi, (scope\get 'pi')\const!
got = (scope\get 'test')\const!
- assert.is.equal opdef, got.type
- assert.is.equal TestOp, got.value
+ assert.is.equal TestOp, got opdef
got = (scope\get 'math')\const!
assert.is.equal scope_t, got.type
@@ -124,15 +116,13 @@ describe 'Scope', ->
it 'allows access', ->
got = (scope\get 'inherited')\const!
- assert.is.equal str, got.type
- assert.is.equal "inherited string", got.value
+ assert.is.equal "inherited string", got str
it 'can be shadowed', ->
scope\set_raw 'hidden', "overwritten"
got = (scope\get 'hidden')\const!
- assert.is.equal str, got.type
- assert.is.equal "overwritten", got.value
+ assert.is.equal "overwritten", got str
describe 'dynamic inheritance', ->
root = Scope!
@@ -147,18 +137,18 @@ describe 'Scope', ->
it 'follows a different parent', ->
merged = Scope root, dyn_root
- assert.is.equal 'normal', (merged\get 'normal').value!
- assert.is.equal 'dynamic', (merged\get '*dynamic*').value!
+ assert.is.equal 'normal', (merged\get 'normal').result!
+ assert.is.equal 'dynamic', (merged\get '*dynamic*').result!
it 'falls back to the immediate parent', ->
merged = Scope root
- assert.is.equal 'normal', (merged\get '*dynamic*').value!
+ assert.is.equal 'normal', (merged\get '*dynamic*').result!
it 'looks in self first', ->
merged = Scope root
merged\set_raw '*dynamic*', 'merged'
- assert.is.equal 'merged', (merged\get '*dynamic*').value!
+ assert.is.equal 'merged', (merged\get '*dynamic*').result!
it 'can resolve nested', ->
merged = Scope root, dyn_root
- assert.is.equal 3, (merged\get '*nested*/value').value!
+ assert.is.equal 3, (merged\get '*nested*/value').result!