diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/cell_spec.moon | 18 | ||||
| -rw-r--r-- | spec/input_spec.moon | 25 | ||||
| -rw-r--r-- | spec/match_spec.moon | 11 | ||||
| -rw-r--r-- | spec/parsing_spec.moon | 53 | ||||
| -rw-r--r-- | spec/result/const_spec.moon | 149 | ||||
| -rw-r--r-- | spec/result/sig_spec.moon | 109 | ||||
| -rw-r--r-- | spec/rtnode_spec.moon (renamed from spec/result_spec.moon) | 71 | ||||
| -rw-r--r-- | spec/scope_spec.moon | 46 | ||||
| -rw-r--r-- | spec/value_spec.moon | 180 |
9 files changed, 371 insertions, 291 deletions
diff --git a/spec/cell_spec.moon b/spec/cell_spec.moon index 0b2ff64..de46245 100644 --- a/spec/cell_spec.moon +++ b/spec/cell_spec.moon @@ -1,15 +1,15 @@ import do_setup from require 'spec.test_setup' import Cell, RootCell from require 'alv.cell' -import ValueStream, Scope, Tag, SimpleRegistry, globals from require 'alv' +import Constant, Scope, Tag, SimpleRegistry, globals from require 'alv' import Copilot from require 'alv.copilot' setup do_setup hello_world = Cell.parse Tag.parse('2'), { - '', (ValueStream.sym 'hello'), ' ', (ValueStream.str 'world'), '' + '', (Constant.sym 'hello'), ' ', (Constant.str 'world'), '' } two_plus_two = Cell.parse Tag.parse('3'), { - '', (ValueStream.sym '+'), ' ', (ValueStream.num 2), ' ', (ValueStream.num 2), '' + '', (Constant.sym '+'), ' ', (Constant.num 2), ' ', (Constant.num 2), '' } describe 'Cell', -> @@ -18,8 +18,8 @@ describe 'Cell', -> with hello_world\clone parent it 'keeps children', -> assert.is.equal Cell, .__class - assert.is.equal (ValueStream.sym 'hello'), \head! - assert.is.same { ValueStream.str 'world' }, \tail! + assert.is.equal (Constant.sym 'hello'), \head! + assert.is.same { Constant.str 'world' }, \tail! it 'clones the tag', -> assert.is.equal hello_world.tag, .tag.original @@ -31,8 +31,8 @@ describe 'Cell', -> assert.has.error -> cell\eval globals it 'evaluates its head', -> - head = ValueStream.sym 'trace' - cell = Cell.parse { '', head, ' ', (ValueStream.sym 'true'), '' } + head = Constant.sym 'trace' + cell = Cell.parse { '', head, ' ', (Constant.sym 'true'), '' } s = spy.on head, 'eval' cell\eval globals @@ -45,10 +45,10 @@ describe 'RootCell', -> test 'head is always "do"', -> cell = Cell.parse_root {} - assert.is.equal (ValueStream.sym 'do'), cell\head! + assert.is.equal (Constant.sym 'do'), cell\head! cell = RootCell nil, { hello_world, two_plus_two } - assert.is.equal (ValueStream.sym 'do'), cell\head! + assert.is.equal (Constant.sym 'do'), cell\head! test 'tail is all children', -> cell = Cell.parse_root {} diff --git a/spec/input_spec.moon b/spec/input_spec.moon index 6ab4388..a8107ae 100644 --- a/spec/input_spec.moon +++ b/spec/input_spec.moon @@ -1,10 +1,13 @@ import do_setup from require 'spec.test_setup' -import Input, Result, ValueStream, EventStream, IOStream from require 'alv.base' +import Input, Result, SigStream, EvtStream, IOStream from require 'alv.base' +import Primitive from require 'alv.types' setup do_setup +my_io = Primitive 'my-io' + class MyIO extends IOStream - new: => super 'my-io' + new: => super my_io dirty: => @is_dirty basic_tests = (stream, input) -> @@ -22,7 +25,7 @@ basic_tests = (stream, input) -> assert.is.equal stream.metatype, input\metatype! describe 'Input.cold', -> - stream = ValueStream.num 1 + stream = SigStream.num 1 input = Input.cold stream basic_tests stream, input @@ -36,7 +39,7 @@ describe 'Input.cold', -> assert.is.false input\dirty! input\finish_setup! - new_input = Input.cold ValueStream.num 3 + new_input = Input.cold SigStream.num 3 new_input\setup input assert.is.false new_input\dirty! new_input.stream\set 4 @@ -44,8 +47,8 @@ describe 'Input.cold', -> input\finish_setup! describe 'Input.hot', -> - describe 'with EventStream', -> - stream = EventStream 'num' + describe 'with EvtStream', -> + stream = EvtStream Primitive 'num' input = Input.hot stream basic_tests stream, input @@ -53,7 +56,7 @@ describe 'Input.hot', -> it 'is marked for lifting', -> assert.is.nil input.io - it 'is dirty when the EventStream is dirty', -> + it 'is dirty when the EvtStream is dirty', -> assert.is.false input\dirty! assert.is.false stream\dirty! @@ -106,8 +109,8 @@ describe 'Input.hot', -> assert.is.true input\dirty! assert.is.true stream\dirty! - describe 'with ValueStream', -> - stream = ValueStream.num 1 + describe 'with SigStream', -> + stream = SigStream.num 1 local input describe 'at evaltime', -> @@ -120,7 +123,7 @@ describe 'Input.hot', -> input\finish_setup! it 'is dirty when different', -> - newval = ValueStream.num 2 + newval = SigStream.num 2 assert.is.false newval\dirty! newinput = Input.hot newval @@ -129,7 +132,7 @@ describe 'Input.hot', -> newinput\finish_setup! it 'is not dirty when equal', -> - newval = ValueStream.num! + newval = SigStream.num! newval\set 1 assert.is.true newval\dirty! diff --git a/spec/match_spec.moon b/spec/match_spec.moon index 52911db..91cee02 100644 --- a/spec/match_spec.moon +++ b/spec/match_spec.moon @@ -1,14 +1,15 @@ import val, evt from require 'alv.base.match' -import Result, ValueStream, EventStream from require 'alv' +import RTNode, SigStream, EvtStream from require 'alv' +import Primitive from require 'alv.types' mk_val = (type, const) -> - value = ValueStream type - with Result :value + value = SigStream Primitive type + with RTNode :value .side_inputs = { 'fake' } unless const mk_evt = (type, const) -> - value = EventStream type - with Result :value + value = EvtStream Primitive type + with RTNode :value .side_inputs = { 'fake' } unless const describe 'val and evt', -> diff --git a/spec/parsing_spec.moon b/spec/parsing_spec.moon index ecc8ff3..0486276 100644 --- a/spec/parsing_spec.moon +++ b/spec/parsing_spec.moon @@ -1,64 +1,53 @@ import space, atom, expr, explist, cell, program, comment from require 'alv.parsing' -import ValueStream from require 'alv' +import Constant from require 'alv' import Logger from require 'alv.logger' Logger\init 'silent' -verify_parse = (parser, str) -> - with assert parser\match str - assert.is.equal str, \stringify! +verify_parse = (parser, val) -> + with assert parser\match val + assert.is.equal val, \stringify! -verify_parse_nope = (parser, str) -> - with assert parser\match str - without_nope = str\match '^(.*) nope$' +verify_parse_nope = (parser, val) -> + with assert parser\match val + without_nope = val\match '^(.*) nope$' assert.is.equal without_nope, \stringify! describe 'atom parsing', -> test 'symbols', -> sym = verify_parse_nope atom, 'some-toast nope' - assert.is.equal 'sym', sym.type - assert.is.equal 'some-toast', sym\unwrap! - assert.is.equal 'some-toast', sym\stringify! + assert.is.equal (Constant.sym 'some-toast'), sym describe 'numbers', -> it 'parses ints', -> num = verify_parse_nope atom, '1234 nope' - assert.is.equal 'num', num.type - assert.is.equal 1234, num\unwrap! - assert.is.equal '1234', num\stringify! + assert.is.equal (Constant.num 1234), num it 'parses floats', -> num = verify_parse_nope atom, '0.123 nope' - assert.is.equal 'num', num.type - assert.is.equal 0.123, num\unwrap! + assert.is.equal (Constant.num 0.123), num num = verify_parse_nope atom, '.123 nope' - assert.is.equal 'num', num.type - assert.is.equal 0.123, num\unwrap! + assert.is.equal (Constant.num 0.123), num num = verify_parse_nope atom, '0. nope' - assert.is.equal 'num', num.type - assert.is.equal 0, num\unwrap! + assert.is.equal (Constant.num 0), num describe 'strings', -> it 'parses double-quote strings', -> str = verify_parse_nope atom, '"help some stuff!" nope' - assert.is.equal 'str', str.type - assert.is.equal 'help some stuff!', str\unwrap! + assert.is.equal (Constant.str 'help some stuff!'), str it 'parses single-quote strings', -> str = verify_parse_nope atom, "'help some stuff!' nope" - assert.is.equal 'str', str.type - assert.is.equal "help some stuff!", str\unwrap! + assert.is.equal (Constant.str "help some stuff!"), str it 'handles escapes', -> str = verify_parse_nope atom, '"string with \\"quote\\"s and \\\\" nope' - assert.is.equal 'str', str.type - assert.is.equal 'string with \"quote\"s and \\', str\unwrap! + assert.is.equal (Constant.str 'string with \"quote\"s and \\'), str str = verify_parse_nope atom, "'string with \\'quote\\'s and \\\\' nope" - assert.is.equal 'str', str.type - assert.is.equal "string with \'quote\'s and \\", str\unwrap! + assert.is.equal (Constant.str "string with \'quote\'s and \\"), str describe 'Cell', -> test 'basic parsing', -> @@ -66,9 +55,9 @@ describe 'Cell', -> "friend" )' assert.is.equal 3, #node.children - assert.is.equal (ValueStream.num 3), node.children[1] - assert.is.equal (ValueStream.sym 'ok-yes'), node.children[2] - assert.is.equal (ValueStream.str 'friend'), node.children[3] + assert.is.equal (Constant.num 3), node.children[1] + assert.is.equal (Constant.sym 'ok-yes'), node.children[2] + assert.is.equal (Constant.str 'friend'), node.children[3] test 'tag parsing', -> node = verify_parse cell, '([42]tagged 2)' @@ -89,8 +78,8 @@ describe 'RootCell parsing', -> node = verify_parse program, str assert.is.equal 2, #node.children - assert.is.equal (ValueStream.num 3), node.children[1] - assert.is.equal (ValueStream.sym 'ok-yes'), node.children[2] + assert.is.equal (Constant.num 3), node.children[1] + assert.is.equal (Constant.sym 'ok-yes'), node.children[2] it 'at the front of the string', -> verify ' 3\tok-yes' diff --git a/spec/result/const_spec.moon b/spec/result/const_spec.moon new file mode 100644 index 0000000..6bd7999 --- /dev/null +++ b/spec/result/const_spec.moon @@ -0,0 +1,149 @@ +import do_setup from require 'spec.test_setup' +import Constant, RTNode, Scope, SimpleRegistry from require 'alv' +import Op, Builtin from require 'alv.base' +import Primitive from require 'alv.types' + +class TestOp extends Op + new: (...) => super ... + +class TestBuiltin extends Builtin + new: (...) => + +setup do_setup + +describe 'Constant', -> + describe '.wrap', -> + it 'wraps numbers', -> + got = Constant.wrap 3 + assert.is.equal (Primitive 'num'), got.type + assert.is.equal 3, got.value + + it 'wraps strings', -> + got = Constant.wrap "im a happy string" + assert.is.equal (Primitive 'str'), got.type + assert.is.equal "im a happy string", got.value + + it 'wraps Constants', -> + pi = Constant.num 3.14 + got = Constant.wrap pi + + assert.is.equal pi, got + + it 'wraps Opdefs', -> + got = Constant.wrap TestOp + + assert.is.equal (Primitive 'opdef'), got.type + assert.is.equal TestOp, got.value + + it 'wraps Bultins', -> + got = Constant.wrap TestBuiltin + + assert.is.equal (Primitive 'builtin'), got.type + assert.is.equal TestBuiltin, got.value + + it 'wraps Scopes', -> + sub = Scope! + got = Constant.wrap sub + + assert.is.equal (Primitive 'scope'), got.type + assert.is.equal sub, got.value + + it 'wraps tables', -> + pi = Constant.num 3.14 + got = Constant.wrap { :pi } + + assert.is.equal (Primitive 'scope'), got.type + assert.is.equal pi, (got.value\get 'pi')\const! + + describe ':unwrap', -> + it 'returns the raw value!', -> + assert.is.equal 3.14, (Constant.num 3.14)\unwrap! + assert.is.equal 'hi', (Constant.str 'hi')\unwrap! + assert.is.equal 'hi', (Constant.sym 'hi')\unwrap! + + test 'can assert the type', -> + assert.is.equal 3.14, (Constant.num 3.14)\unwrap Primitive 'num' + assert.is.equal 'hi', (Constant.str 'hi')\unwrap Primitive 'str' + assert.is.equal 'hi', (Constant.sym 'hi')\unwrap Primitive 'sym' + assert.has_error -> (Constant.num 3.14)\unwrap Primitive 'sym' + assert.has_error -> (Constant.str 'hi')\unwrap Primitive 'num' + assert.has_error -> (Constant.sym 'hi')\unwrap Primitive 'str' + + test 'has __call shorthand', -> + assert.is.equal 3.14, (Constant.num 3.14)! + assert.is.equal 'hi', (Constant.str 'hi')! + assert.is.equal 'hi', (Constant.sym 'hi')! + assert.is.equal 3.14, (Constant.num 3.14) Primitive 'num' + assert.is.equal 'hi', (Constant.str 'hi') Primitive 'str' + assert.is.equal 'hi', (Constant.sym 'hi') Primitive 'sym' + assert.has_error -> (Constant.num 3.14) Primitive 'sym' + assert.has_error -> (Constant.str 'hi') Primitive 'num' + assert.has_error -> (Constant.sym 'hi') Primitive 'str' + + describe 'overrides __eq', -> + it 'compares the type', -> + val = Constant.num 3 + assert.is.equal (Constant.num 3), val + assert.not.equal (Constant.str '3'), val + + val = Constant.str 'hello' + assert.is.equal (Constant.str 'hello'), val + assert.not.equal (Constant.sym 'hello'), val + + it 'compares the value', -> + val = Constant.num 3 + assert.is.equal (Constant.num 3), val + assert.not.equal (Constant.num 4), val + + it ':dirty is always false', -> + val = Constant.num 3 + assert.is.false val\dirty! + + val.value = 4 + assert.is.false val\dirty! + + describe ':eval', -> + it 'turns numbers into consts', -> + assert_noop = (val) -> + assert.is.equal val, val\eval!\const! + + assert_noop Constant.num 2 + assert_noop Constant.str 'hello' + + 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" + + assert_eval = (sym, val) -> + const = Constant.sym sym + assert.is.equal val, (const\eval scope)\const! + + assert_eval 'number', Constant.num 3 + assert_eval 'hello', Constant.str "world" + assert_eval 'goodbye', Constant.sym "again" + + it ':clones literals as themselves', -> + assert_noop = (val) -> assert.is.equal val, val\clone! + + assert_noop Constant.num 2 + assert_noop Constant.str 'hello' + assert_noop Constant.sym 'world' + + describe ':fork', -> + it 'is equal to the original', -> + a = Constant.num 2 + b = Constant.str 'asdf' + c = Constant (Primitive 'weird'), {}, '(raw)' + + aa, bb, cc = a\fork!, b\fork!, c\fork! + assert.is.equal a, aa + assert.is.equal b, bb + assert.is.equal c, cc + + assert.is.false aa\dirty! + assert.is.false bb\dirty! + assert.is.false cc\dirty! + + assert.is.equal c.raw, cc.raw diff --git a/spec/result/sig_spec.moon b/spec/result/sig_spec.moon new file mode 100644 index 0000000..4bc0a67 --- /dev/null +++ b/spec/result/sig_spec.moon @@ -0,0 +1,109 @@ +import do_setup from require 'spec.test_setup' +import SigStream, RTNode, Scope, SimpleRegistry from require 'alv' +import Op, Builtin from require 'alv.base' +import Primitive from require 'alv.types' + +class TestOp extends Op + new: (...) => super ... + +class TestBuiltin extends Builtin + new: (...) => + +setup do_setup + +describe 'SigStream', -> + describe ':unwrap', -> + it 'returns the raw value!', -> + assert.is.equal 3.14, (SigStream.num 3.14)\unwrap! + assert.is.equal 'hi', (SigStream.str 'hi')\unwrap! + assert.is.equal 'hi', (SigStream.sym 'hi')\unwrap! + + test 'can assert the type', -> + assert.is.equal 3.14, (SigStream.num 3.14)\unwrap Primitive 'num' + assert.is.equal 'hi', (SigStream.str 'hi')\unwrap Primitive 'str' + assert.is.equal 'hi', (SigStream.sym 'hi')\unwrap Primitive 'sym' + assert.has_error -> (SigStream.num 3.14)\unwrap Primitive 'sym' + assert.has_error -> (SigStream.str 'hi')\unwrap Primitive 'num' + assert.has_error -> (SigStream.sym 'hi')\unwrap Primitive 'str' + + test 'has __call shorthand', -> + assert.is.equal 3.14, (SigStream.num 3.14)! + assert.is.equal 'hi', (SigStream.str 'hi')! + assert.is.equal 'hi', (SigStream.sym 'hi')! + assert.is.equal 3.14, (SigStream.num 3.14) Primitive 'num' + assert.is.equal 'hi', (SigStream.str 'hi') Primitive 'str' + assert.is.equal 'hi', (SigStream.sym 'hi') Primitive 'sym' + assert.has_error -> (SigStream.num 3.14) Primitive 'sym' + assert.has_error -> (SigStream.str 'hi') Primitive 'num' + assert.has_error -> (SigStream.sym 'hi') Primitive 'str' + + describe 'overrides __eq', -> + it 'compares the type', -> + val = SigStream.num 3 + assert.is.equal (SigStream.num 3), val + assert.not.equal (SigStream.str '3'), val + + val = SigStream.str 'hello' + assert.is.equal (SigStream.str 'hello'), val + assert.not.equal (SigStream.sym 'hello'), val + + it 'compares the value', -> + val = SigStream.num 3 + assert.is.equal (SigStream.num 3), val + assert.not.equal (SigStream.num 4), val + + describe ':set', -> + it 'sets the value', -> + val = SigStream.num 3 + assert.is.equal (SigStream.num 3), val + + val\set 4 + assert.is.equal (SigStream.num 4), val + assert.not.equal (SigStream.num 3), val + + it 'marks the value dirty', -> + val = SigStream.num 3 + assert.is.false val\dirty! + + val\set 4 + assert.is.true val\dirty! + + describe ':fork', -> + it 'is equal to the original', -> + a = SigStream.num 2 + b = SigStream.str 'asdf' + c = with SigStream 'weird', {}, '(raw)' + \set {} + + aa, bb, cc = a\fork!, b\fork!, c\fork! + assert.is.equal a, aa + assert.is.equal b, bb + assert.is.equal c, cc + + assert.is.false aa\dirty! + assert.is.false bb\dirty! + assert.is.true cc\dirty! + + assert.is.equal c.raw, cc.raw + + it 'isolates the original from the fork', -> + a = SigStream.num 3 + b = with SigStream 'weird', {}, '(raw)' + \set {} + + aa, bb = a\fork!, b\fork! + + bb\set {false} + + assert.is.same {}, b! + assert.is.same {false}, bb! + assert.is.true b\dirty! + assert.is.true bb\dirty! + + COPILOT\next_tick! + aa\set 4 + + assert.is.equal 3, a! + assert.is.equal 4, aa! + assert.is.false a\dirty! + assert.is.true aa\dirty! diff --git a/spec/result_spec.moon b/spec/rtnode_spec.moon index f7006f1..c4cf4e9 100644 --- a/spec/result_spec.moon +++ b/spec/rtnode_spec.moon @@ -1,44 +1,47 @@ import do_setup from require 'spec.test_setup' -import Result, Scope, SimpleRegistry from require 'alv' -import Input, Op, ValueStream, EventStream, IOStream from require 'alv.base' +import RTNode, Scope, SimpleRegistry from require 'alv' +import Input, Op, Constant, EvtStream, IOStream from require 'alv.base' +import Primitive from require 'alv.types' setup do_setup +num = Primitive 'num' +bang = Primitive 'bang' op_with_inputs = (inputs) -> with Op! \setup inputs if inputs result_with_sideinput = (value, input) -> - with Result :value + with RTNode :value .side_inputs = { [value]: input } class DirtyIO extends IOStream - new: => super 'dirty-io' + new: => super Primitive 'dirty-io' dirty: => true -describe 'Result', -> +describe 'RTNode', -> it 'wraps value, children', -> - value = ValueStream.num 3 + value = Constant.num 3 - a = Result! - b = Result! + a = RTNode! + b = RTNode! children = { a, b } - result = Result :value, :children + result = RTNode :value, :children assert.is.equal value, result.value assert.is.same children, result.children it ':type gets type and assets value', -> - result = Result value: ValueStream.num 2 - assert.is.equal 'num', result\type! + result = RTNode value: Constant.num 2 + assert.is.equal num, result\type! - result = Result! + result = RTNode! assert.has.error -> result\type! it ':is_const', -> - value = ValueStream.num 2 - pure = Result :value + value = Constant.num 2 + pure = RTNode :value impure = result_with_sideinput value, {} assert.is.true pure\is_const! @@ -49,10 +52,10 @@ describe 'Result', -> assert.has.error (-> impure\const 'test'), 'test' it ':make_ref', -> - value = ValueStream.num 2 + value = Constant.num 2 input = Input.hot value op = op_with_inputs { input } - thick = Result :value, :op, children: { Result!, Result! } + thick = RTNode :value, :op, children: { RTNode!, RTNode! } ref = thick\make_ref! assert ref @@ -62,43 +65,43 @@ describe 'Result', -> assert.is.nil ref.op it 'lifts up inputs from op', -> - event = ValueStream 'bang', false + event = Constant bang, false event_input = Input.hot event - value = ValueStream 'num', 4 + value = Constant num, 4 value_input = Input.hot value op = op_with_inputs { event_input, value_input } - result = Result op: op, :value + result = RTNode op: op, :value assert.is.equal op, result.op assert.is.same { [event]: event_input, [value]: value_input }, result.side_inputs it 'does not lift up op inputs that are also child values', -> - event = ValueStream 'bang', false + event = Constant bang, false event_input = Input.hot event - value = ValueStream 'num', 4 + value = Constant num, 4 value_input = Input.hot value op = op_with_inputs { event_input, value_input } - result = Result op: op, :value, children: { Result :value } + result = RTNode op: op, :value, children: { RTNode :value } assert.is.same { [event]: event_input }, result.side_inputs it 'lifts up side_inputs from children', -> - event_value = ValueStream 'bang', false + event_value = Constant bang, false event_input = Input.hot event_value - event = Result op: op_with_inputs { event_input } + event = RTNode op: op_with_inputs { event_input } assert.is.same { [event_value]: event_input }, event.side_inputs - value_value = ValueStream 'num', 4 + value_value = Constant num, 4 value_input = Input.hot value_value - value = Result op: op_with_inputs { value_input } + value = RTNode op: op_with_inputs { value_input } assert.is.same { [value_value]: value_input }, value.side_inputs - result = Result children: { event, value } + result = RTNode children: { event, value } assert.is.same { [event_value]: event_input, [value_value]: value_input }, result.side_inputs @@ -106,11 +109,11 @@ describe 'Result', -> local a_value, a_child, a_input local b_value, b_child, b_input before_each -> - a_value = EventStream 'num' + a_value = EvtStream num a_input = Input.hot a_value a_child = result_with_sideinput a_value, a_input - b_value = EventStream 'num' + b_value = EvtStream num b_input = Input.hot b_value b_child = result_with_sideinput b_value, b_input @@ -122,7 +125,7 @@ describe 'Result', -> a = spy.on a_child, 'tick' b = spy.on b_child, 'tick' - result = Result children: { a_child, b_child } + result = RTNode children: { a_child, b_child } result\tick! assert.spy(a).was_called_with match.ref a_child @@ -135,7 +138,7 @@ describe 'Result', -> a = spy.on a_child, 'tick' b = spy.on b_child, 'tick' - result = Result children: { a_child, b_child } + result = RTNode children: { a_child, b_child } result\tick! assert.spy(a).was_not_called! @@ -149,7 +152,7 @@ describe 'Result', -> op = op_with_inputs a: Input.hot a_value s = spy.on op, 'tick' - result = Result :op, children: { a_child, b_child } + result = RTNode :op, children: { a_child, b_child } result\tick! assert.spy(s).was_called_with match.ref op @@ -162,7 +165,7 @@ describe 'Result', -> op = op_with_inputs { Input.hot b_value } s = spy.on op, 'tick' - result = Result :op, children: { a_child, b_child } + result = RTNode :op, children: { a_child, b_child } result\tick! assert.spy(s).was_not_called! @@ -172,7 +175,7 @@ describe 'Result', -> io = DirtyIO! input = Input.hot io op = op_with_inputs { input } - result = Result :op + result = RTNode :op s = spy.on io, 'poll' assert.is.same { [io]: input }, result.side_inputs diff --git a/spec/scope_spec.moon b/spec/scope_spec.moon index beeeeac..405e9f8 100644 --- a/spec/scope_spec.moon +++ b/spec/scope_spec.moon @@ -1,4 +1,5 @@ -import Scope, ValueStream, Result from require 'alv' +import Scope, Constant, RTNode from require 'alv' +import Primitive from require 'alv.types' import Op from require 'alv.base' import Logger from require 'alv.logger' Logger\init 'silent' @@ -6,7 +7,12 @@ Logger\init 'silent' class TestOp extends Op new: (...) => super ... -wrap_res = (value) -> Result :value +wrap_res = (value) -> RTNode :value + +num = Primitive 'num' +str = Primitive 'str' +opdef = Primitive 'opdef' +scope_t = Primitive 'scope' describe 'Scope', -> describe 'constifies', -> @@ -16,18 +22,18 @@ describe 'Scope', -> scope\set_raw 'num', 3 got = (scope\get 'num')\const! - assert.is.equal 'num', got.type + assert.is.equal num, got.type assert.is.equal 3, got.value test 'strings', -> scope\set_raw 'str', "im a happy string" got = (scope\get 'str')\const! - assert.is.equal 'str', got.type + assert.is.equal str, got.type assert.is.equal "im a happy string", got.value test 'Values', -> - pi = ValueStream 'num', 3.14 + pi = Constant.num 3.14 scope\set_raw 'pi', pi assert.is.equal pi, (scope\get 'pi')\const! @@ -36,7 +42,7 @@ describe 'Scope', -> scope\set_raw 'test', TestOp got = (scope\get 'test')\const! - assert.is.equal 'opdef', got.type + assert.is.equal opdef, got.type assert.is.equal TestOp, got.value test 'Scopes', -> @@ -44,21 +50,21 @@ describe 'Scope', -> scope\set_raw 'sub', sub got = (scope\get 'sub')\const! - assert.is.equal 'scope', got.type + assert.is.equal scope_t, got.type assert.is.equal sub, got.value test 'tables', -> - pi = ValueStream 'num', 3.14 - scope\set_raw 'math', { :pi } + pi = Constant.num 3.14 + scope\set_raw 'math', { :pi } got = (scope\get 'math')\const! - assert.is.equal 'scope', got.type + assert.is.equal scope_t, got.type assert.is.equal Scope, got.value.__class assert.is.equal pi, (got.value\get 'pi')\const! assert.is.equal pi, (scope\get 'math/pi')\const! it 'wraps Values in from_table', -> - pi = ValueStream 'num', 3.14 + pi = Constant.num 3.14 scope = Scope.from_table { num: 3 str: "im a happy string" @@ -68,21 +74,21 @@ describe 'Scope', -> } got = (scope\get 'num')\const! - assert.is.equal 'num', got.type + assert.is.equal num, got.type assert.is.equal 3, got.value got = (scope\get 'str')\const! - assert.is.equal 'str', got.type + assert.is.equal str, got.type assert.is.equal "im a happy string", got.value assert.is.equal pi, (scope\get 'pi')\const! got = (scope\get 'test')\const! - assert.is.equal 'opdef', got.type + assert.is.equal opdef, got.type assert.is.equal TestOp, got.value got = (scope\get 'math')\const! - assert.is.equal 'scope', got.type + assert.is.equal scope_t, got.type assert.is.equal pi, (scope\get 'math/pi')\const! it 'gets from nested scopes', -> @@ -90,7 +96,7 @@ describe 'Scope', -> a = Scope! b = Scope! - pi = ValueStream 'num', 3.14 + pi = Constant.num 3.14 b\set_raw 'test', pi a\set_raw 'child', b root\set_raw 'deep', a @@ -98,8 +104,8 @@ describe 'Scope', -> assert.is.equal pi, (root\get 'deep/child/test')\const! describe 'can set symbols', -> - one = wrap_res ValueStream.num 1 - two = wrap_res ValueStream.num 2 + one = wrap_res Constant.num 1 + two = wrap_res Constant.num 2 scope = Scope! it 'disallows re-setting symbols', -> @@ -119,14 +125,14 @@ describe 'Scope', -> it 'allows access', -> got = (scope\get 'inherited')\const! - assert.is.equal 'str', got.type + assert.is.equal str, got.type assert.is.equal "inherited string", got.value it 'can be shadowed', -> scope\set_raw 'hidden', "overwritten" got = (scope\get 'hidden')\const! - assert.is.equal 'str', got.type + assert.is.equal str, got.type assert.is.equal "overwritten", got.value describe 'dynamic inheritance', -> diff --git a/spec/value_spec.moon b/spec/value_spec.moon deleted file mode 100644 index d81ed40..0000000 --- a/spec/value_spec.moon +++ /dev/null @@ -1,180 +0,0 @@ -import do_setup from require 'spec.test_setup' -import ValueStream, Result, Scope, SimpleRegistry from require 'alv' -import Op, Builtin from require 'alv.base' - -class TestOp extends Op - new: (...) => super ... - -class TestBuiltin extends Builtin - new: (...) => - -setup do_setup - -describe 'ValueStream', -> - describe '.wrap', -> - it 'wraps numbers', -> - got = ValueStream.wrap 3 - assert.is.equal 'num', got.type - assert.is.equal 3, got.value - - it 'wraps strings', -> - got = ValueStream.wrap "im a happy string" - assert.is.equal 'str', got.type - assert.is.equal "im a happy string", got.value - - it 'wraps Values', -> - pi = ValueStream 'num', 3.14 - got = ValueStream.wrap pi - - assert.is.equal pi, got - - it 'wraps Opdefs', -> - got = ValueStream.wrap TestOp - - assert.is.equal 'opdef', got.type - assert.is.equal TestOp, got.value - - it 'wraps Bultins', -> - got = ValueStream.wrap TestBuiltin - - assert.is.equal 'builtin', got.type - assert.is.equal TestBuiltin, got.value - - it 'wraps Scopes', -> - sub = Scope! - got = ValueStream.wrap sub - - assert.is.equal 'scope', got.type - assert.is.equal sub, got.value - - it 'wraps tables', -> - pi = ValueStream 'num', 3.14 - got = ValueStream.wrap { :pi } - - assert.is.equal 'scope', got.type - assert.is.equal pi, (got.value\get 'pi')\const! - - describe ':unwrap', -> - it 'returns the raw value!', -> - assert.is.equal 3.14, (ValueStream.num 3.14)\unwrap! - assert.is.equal 'hi', (ValueStream.str 'hi')\unwrap! - assert.is.equal 'hi', (ValueStream.sym 'hi')\unwrap! - - test 'can assert the type', -> - assert.is.equal 3.14, (ValueStream.num 3.14)\unwrap 'num' - assert.is.equal 'hi', (ValueStream.str 'hi')\unwrap 'str' - assert.is.equal 'hi', (ValueStream.sym 'hi')\unwrap 'sym' - assert.has_error -> (ValueStream.num 3.14)\unwrap 'sym' - assert.has_error -> (ValueStream.str 'hi')\unwrap 'num' - assert.has_error -> (ValueStream.sym 'hi')\unwrap 'str' - - test 'has __call shorthand', -> - assert.is.equal 3.14, (ValueStream.num 3.14)! - assert.is.equal 'hi', (ValueStream.str 'hi')! - assert.is.equal 'hi', (ValueStream.sym 'hi')! - assert.is.equal 3.14, (ValueStream.num 3.14) 'num' - assert.is.equal 'hi', (ValueStream.str 'hi') 'str' - assert.is.equal 'hi', (ValueStream.sym 'hi') 'sym' - assert.has_error -> (ValueStream.num 3.14) 'sym' - assert.has_error -> (ValueStream.str 'hi') 'num' - assert.has_error -> (ValueStream.sym 'hi') 'str' - - describe 'overrides __eq', -> - it 'compares the type', -> - val = ValueStream 'num', 3 - assert.is.equal (ValueStream.num 3), val - assert.not.equal (ValueStream.str '3'), val - - val = ValueStream 'str', 'hello' - assert.is.equal (ValueStream.str 'hello'), val - assert.not.equal (ValueStream.sym 'hello'), val - - it 'compares the value', -> - val = ValueStream 'num', 3 - assert.is.equal (ValueStream.num 3), val - assert.not.equal (ValueStream.num 4), val - - describe ':set', -> - it 'sets the value', -> - val = ValueStream 'num', 3 - assert.is.equal (ValueStream.num 3), val - - val\set 4 - assert.is.equal (ValueStream.num 4), val - assert.not.equal (ValueStream.num 3), val - - it 'marks the value dirty', -> - val = ValueStream 'num', 3 - assert.is.false val\dirty! - - val\set 4 - assert.is.true val\dirty! - - describe ':eval', -> - it 'turns numbers into consts', -> - assert_noop = (val) -> - assert.is.equal val, val\eval!\const! - - assert_noop ValueStream.num 2 - assert_noop ValueStream.str 'hello' - - it 'looks up symbols in the scope', -> - scope = with Scope! - \set 'number', Result value: ValueStream.num 3 - \set 'hello', Result value: ValueStream.str "world" - \set 'goodbye', Result value: ValueStream.sym "again" - - assert_eval = (sym, val) -> - const = ValueStream.sym sym - assert.is.equal val, (const\eval scope)\const! - - assert_eval 'number', ValueStream.num 3 - assert_eval 'hello', ValueStream.str "world" - assert_eval 'goodbye', ValueStream.sym "again" - - it ':clone sliterals as themselves', -> - assert_noop = (val) -> assert.is.equal val, val\clone! - - assert_noop ValueStream.num 2 - assert_noop ValueStream.str 'hello' - assert_noop ValueStream.sym 'world' - - describe ':fork', -> - it 'is equal to the original', -> - a = ValueStream.num 2 - b = ValueStream.str 'asdf' - c = with ValueStream 'weird', {}, '(raw)' - \set {} - - aa, bb, cc = a\fork!, b\fork!, c\fork! - assert.is.equal a, aa - assert.is.equal b, bb - assert.is.equal c, cc - - assert.is.false aa\dirty! - assert.is.false bb\dirty! - assert.is.true cc\dirty! - - assert.is.equal c.raw, cc.raw - - it 'isolates the original from the fork', -> - a = ValueStream.num 3 - b = with ValueStream 'weird', {}, '(raw)' - \set {} - - aa, bb = a\fork!, b\fork! - - bb\set {false} - - assert.is.same {}, b! - assert.is.same {false}, bb! - assert.is.true b\dirty! - assert.is.true bb\dirty! - - COPILOT\next_tick! - aa\set 4 - - assert.is.equal 3, a! - assert.is.equal 4, aa! - assert.is.false a\dirty! - assert.is.true aa\dirty! |
