aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-03-24 11:39:25 +0000
committers-ol <s-ol@users.noreply.github.com>2020-03-24 11:39:25 +0000
commit677c0d2f01e14bbeca1583ec7878d80c71c3aa68 (patch)
treecc20e04697da590b546de370599eeaaef647d20c /spec
parentinternals/plugin-guide: first draft (diff)
downloadalive-677c0d2f01e14bbeca1583ec7878d80c71c3aa68.tar.gz
alive-677c0d2f01e14bbeca1583ec7878d80c71c3aa68.zip
Value -> Value/Event/IO-Stream
Close 12
Diffstat (limited to 'spec')
-rw-r--r--spec/core/cell_spec.moon26
-rw-r--r--spec/core/input_spec.moon264
-rw-r--r--spec/core/parsing_spec.moon12
-rw-r--r--spec/core/pattern_spec.moon20
-rw-r--r--spec/core/result_spec.moon65
-rw-r--r--spec/core/scope_spec.moon14
-rw-r--r--spec/core/value_spec.moon126
7 files changed, 236 insertions, 291 deletions
diff --git a/spec/core/cell_spec.moon b/spec/core/cell_spec.moon
index 710b252..d16c9d8 100644
--- a/spec/core/cell_spec.moon
+++ b/spec/core/cell_spec.moon
@@ -1,10 +1,10 @@
import Cell, RootCell from require 'core.cell'
-import Value, Scope, Tag, SimpleRegistry, globals from require 'core'
+import ValueStream, Scope, Tag, SimpleRegistry, globals from require 'core'
import Logger from require 'logger'
Logger.init 'silent'
-hello_world = Cell.parse (Tag.parse '2'), { '', (Value.sym 'hello'), ' ', (Value.str 'world'), '' }
-two_plus_two = Cell.parse (Tag.parse '3'), { '', (Value.sym '+'), ' ', (Value.num 2), ' ', (Value.num 2), '' }
+hello_world = Cell.parse (Tag.parse '2'), { '', (ValueStream.sym 'hello'), ' ', (ValueStream.str 'world'), '' }
+two_plus_two = Cell.parse (Tag.parse '3'), { '', (ValueStream.sym '+'), ' ', (ValueStream.num 2), ' ', (ValueStream.num 2), '' }
reg = SimpleRegistry!
setup -> reg\grab!
@@ -15,8 +15,8 @@ describe 'Cell', ->
with hello_world\quote!
it 'stays equal', ->
assert.is.equal Cell, .__class
- assert.is.equal (Value.sym 'hello'), \head!
- assert.is.same { Value.str 'world' }, \tail!
+ assert.is.equal (ValueStream.sym 'hello'), \head!
+ assert.is.same { ValueStream.str 'world' }, \tail!
it 'shares the tag', ->
assert.is.equal hello_world.tag, .tag
@@ -24,8 +24,8 @@ describe 'Cell', ->
with two_plus_two\quote!
it 'stays equal', ->
assert.is.equal Cell, .__class
- assert.is.equal (Value.sym '+'), \head!
- assert.is.same { (Value.num 2), (Value.num 2) }, \tail!
+ assert.is.equal (ValueStream.sym '+'), \head!
+ assert.is.same { (ValueStream.num 2), (ValueStream.num 2) }, \tail!
it 'shares the tag', ->
assert.is.equal two_plus_two.tag, .tag
@@ -35,8 +35,8 @@ describe 'Cell', ->
with hello_world\clone parent
it 'keeps children', ->
assert.is.equal Cell, .__class
- assert.is.equal (Value.sym 'hello'), \head!
- assert.is.same { Value.str 'world' }, \tail!
+ assert.is.equal (ValueStream.sym 'hello'), \head!
+ assert.is.same { ValueStream.str 'world' }, \tail!
it 'clones the tag', ->
assert.is.equal hello_world.tag, .tag.original
@@ -48,8 +48,8 @@ describe 'Cell', ->
assert.has.error -> cell\eval globals
it 'evaluates its head', ->
- head = Value.sym 'trace'
- cell = Cell.parse { '', head, ' ', (Value.sym 'true'), '' }
+ head = ValueStream.sym 'trace'
+ cell = Cell.parse { '', head, ' ', (ValueStream.sym 'true'), '' }
s = spy.on head, 'eval'
cell\eval globals
@@ -62,10 +62,10 @@ describe 'RootCell', ->
test 'head is always "do"', ->
cell = Cell.parse_root {}
- assert.is.equal (Value.sym 'do'), cell\head!
+ assert.is.equal (ValueStream.sym 'do'), cell\head!
cell = RootCell nil, { hello_world, two_plus_two }
- assert.is.equal (Value.sym 'do'), cell\head!
+ assert.is.equal (ValueStream.sym 'do'), cell\head!
test 'tail is all children', ->
cell = Cell.parse_root {}
diff --git a/spec/core/input_spec.moon b/spec/core/input_spec.moon
index e2ec7e3..4b470db 100644
--- a/spec/core/input_spec.moon
+++ b/spec/core/input_spec.moon
@@ -1,4 +1,4 @@
-import Input, Result, Value, IO from require 'core.base'
+import Input, Result, ValueStream, EventStream, IOStream from require 'core.base'
import SimpleRegistry from require 'core'
import Logger from require 'logger'
Logger.init 'silent'
@@ -7,198 +7,144 @@ reg = SimpleRegistry!
setup -> reg\grab!
teardown -> reg\release!
-describe 'Input.event', ->
- val = Value.num 1
- input = Input.event val
-
- describe 'at evaltime', ->
- it 'follows Value when new', ->
- input\setup nil
-
- val\set 2
- assert.is.true val\dirty!
- assert.is.true input\dirty!
-
- reg\next_tick!
- assert.is.false val\dirty!
- assert.is.false input\dirty!
-
- input\finish_setup!
-
- it 'follows Value when different', ->
- new_input = Input.event Value.num 3
- new_input\setup input
-
- assert.is.false new_input.stream\dirty!
- assert.is.false new_input\dirty!
-
- new_input.stream\set 3
- assert.is.true new_input.stream\dirty!
- assert.is.true new_input\dirty!
-
- reg\next_tick!
- new_input\finish_setup!
-
- it 'follows Value when equal', ->
- new_input = Input.event Value.num 2
- new_input\setup input
-
- assert.is.false new_input.stream\dirty!
- assert.is.false new_input\dirty!
-
- new_input.stream\set 2
- assert.is.true new_input.stream\dirty!
- assert.is.true new_input\dirty!
-
- describe 'at runtime', ->
- it 'is dirty when the value is dirty', ->
- val\set 3
- assert.is.true val\dirty!
- assert.is.true input\dirty!
-
- reg\next_tick!
- assert.is.false val\dirty!
- assert.is.false input\dirty!
-
- it 'unwraps to the lua value', ->
- assert.is.equal 3, input\unwrap!
- assert.is.equal 3, input!
-
- it 'gives access to the type string', ->
- assert.is.equal 'num', input\type!
-
- it 'gives access to the Value', ->
- assert.is.equal val, input.stream
-
-describe 'Input.value', ->
- val = Value.num 1
- local input
-
- describe 'at evaltime', ->
- it 'is dirty when new', ->
- assert.is.false val\dirty!
-
- input = Input.value val
- input\setup nil
- assert.is.true input\dirty!
- input\finish_setup!
-
- it 'is dirty when different', ->
- newval = Value.num 2
-
- assert.is.false newval\dirty!
- newinput = Input.value newval
- newinput\setup input
- assert.is.true newinput\dirty!
- newinput\finish_setup!
-
- it 'is not dirty when equal', ->
- newval = Value.num 1
- newval\set 1
-
- assert.is.true newval\dirty!
- newinput = Input.value newval
- newinput\setup input
- assert.is.false newinput\dirty!
- newinput\finish_setup!
-
- describe 'at runtime', ->
- it 'is dirty when the value is dirty', ->
- val\set 3
- assert.is.true val\dirty!
- assert.is.true input\dirty!
+class MyIO extends IOStream
+ new: => super 'my-io'
+ dirty: => @is_dirty
- reg\next_tick!
- assert.is.false val\dirty!
- assert.is.false input\dirty!
+basic_tests = (stream, input) ->
+ it 'gives access to the Stream', ->
+ assert.is.equal stream, input.stream
- it 'unwraps to the lua value', ->
- assert.is.equal 3, input\unwrap!
- assert.is.equal 3, input!
+ 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 'num', input\type!
-
- it 'gives access to the Value', ->
- assert.is.equal val, input.stream
+ assert.is.equal stream.type, input\type!
describe 'Input.cold', ->
- val = Value.num 1
- input = Input.cold val
+ stream = ValueStream.num 1
+ input = Input.cold stream
+
+ basic_tests stream, input
it 'is never dirty', ->
assert.is.false input\dirty!
- val\set 2
+ stream\set 2
assert.is.false input\dirty!
input\setup nil
assert.is.false input\dirty!
input\finish_setup!
- new_input = Input.cold Value.num 3
+ 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!
- it 'unwraps to the lua value', ->
- assert.is.equal 2, input\unwrap!
- assert.is.equal 2, input!
+describe 'Input.hot', ->
+ describe 'with EventStream', ->
+ stream = EventStream 'num'
+ input = Input.hot stream
- it 'gives access to the type string', ->
- assert.is.equal 'num', input\type!
+ basic_tests stream, input
- it 'gives access to the Value', ->
- assert.is.equal val, input.stream
+ it 'is marked for lifting', ->
+ assert.is.nil input.io
-class MyIO extends IO
- dirty: => @is_dirty
+ it 'is dirty when the EventStream is dirty', ->
+ assert.is.false input\dirty!
+ assert.is.false stream\dirty!
-describe 'Input.io', ->
- io = MyIO!
- val = Value 'test-io', io
- input = Input.io val
+ input\setup nil
+ assert.is.false input\dirty!
+ input\finish_setup!
- it 'is dirty when the IO is dirty', ->
- io.is_dirty = false
+ reg\next_tick!
+ stream\add 1
- assert.is.false val\dirty!
- assert.is.false input\dirty!
- assert.is.false io\dirty!
+ assert.is.true input\dirty!
+ assert.is.true stream\dirty!
- input\setup nil
- assert.is.false input\dirty!
- input\finish_setup!
+ input\setup nil
+ assert.is.true input\dirty!
+ input\finish_setup!
- val\set io
- assert.is.true val\dirty!
- assert.is.false input\dirty!
- assert.is.false io\dirty!
+ assert.is.true input\dirty!
+ assert.is.true stream\dirty!
- reg\next_tick!
+ describe 'with IOStream', ->
+ stream = MyIO!
+ input = Input.hot stream
- io.is_dirty = true
+ basic_tests stream, input
- assert.is.false val\dirty!
- assert.is.true input\dirty!
- assert.is.true io\dirty!
+ it 'is marked for lifting', ->
+ assert.is.true input.io
- input\setup nil
- assert.is.true input\dirty!
- input\finish_setup!
+ it 'is dirty when the IOStream is dirty', ->
+ stream.is_dirty = false
- val\set io
- assert.is.true val\dirty!
- assert.is.true input\dirty!
- assert.is.true io\dirty!
+ assert.is.false input\dirty!
+ assert.is.false stream\dirty!
- it 'unwraps to the io value', ->
- assert.is.equal io, input\unwrap!
- assert.is.equal io, input!
+ input\setup nil
+ assert.is.false input\dirty!
+ input\finish_setup!
- it 'gives access to the type string', ->
- assert.is.equal 'test-io', input\type!
+ reg\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!
- it 'gives access to the Value', ->
- assert.is.equal val, input.stream
+ 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 1
+ 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!
+
+ reg\next_tick!
+ assert.is.false stream\dirty!
+ assert.is.false input\dirty!
diff --git a/spec/core/parsing_spec.moon b/spec/core/parsing_spec.moon
index 9958e22..32d8530 100644
--- a/spec/core/parsing_spec.moon
+++ b/spec/core/parsing_spec.moon
@@ -1,6 +1,6 @@
import space, atom, expr, explist, cell, program, comment
from require 'core.parsing'
-import Value from require 'core'
+import ValueStream from require 'core'
import Logger from require 'logger'
Logger.init 'silent'
@@ -66,9 +66,9 @@ describe 'Cell', ->
"friend" )'
assert.is.equal 3, #node.children
- assert.is.equal (Value.num 3), node.children[1]
- assert.is.equal (Value.sym 'ok-yes'), node.children[2]
- assert.is.equal (Value.str 'friend'), node.children[3]
+ 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]
test 'tag parsing', ->
node = verify_parse cell, '([42]tagged 2)'
@@ -89,8 +89,8 @@ describe 'RootCell parsing', ->
node = verify_parse program, str
assert.is.equal 2, #node.children
- assert.is.equal (Value.num 3), node.children[1]
- assert.is.equal (Value.sym 'ok-yes'), node.children[2]
+ assert.is.equal (ValueStream.num 3), node.children[1]
+ assert.is.equal (ValueStream.sym 'ok-yes'), node.children[2]
it 'at the front of the string', ->
verify ' 3\tok-yes'
diff --git a/spec/core/pattern_spec.moon b/spec/core/pattern_spec.moon
index 4825dcc..523ce86 100644
--- a/spec/core/pattern_spec.moon
+++ b/spec/core/pattern_spec.moon
@@ -1,5 +1,5 @@
import Pattern, match from require 'core.base.match'
-import Result, Value from require 'core'
+import Result, ValueStream from require 'core'
-- wrap in non-const result
wrap = (value) ->
@@ -10,11 +10,11 @@ wrap = (value) ->
wrap_const = (value) -> Result :value
describe 'Type Pattern', ->
- num = wrap Value.num 1
- str = wrap Value.str 'hello'
- special = wrap Value 'midi/sysex-message'
- c_num = wrap_const Value.num 1
- c_str = wrap_const Value.str 'hello'
+ num = wrap ValueStream.num 1
+ str = wrap ValueStream.str 'hello'
+ special = wrap ValueStream 'midi/sysex-message'
+ c_num = wrap_const ValueStream.num 1
+ c_str = wrap_const ValueStream.str 'hello'
describe 'simple types', ->
it 'matches self type', ->
@@ -151,10 +151,10 @@ describe 'Type Pattern', ->
assert.is.same {str}, stream
describe 'match', ->
- num = wrap Value.num 1
- str = wrap Value.str 'hello'
- c_num = wrap_const Value.num 1
- c_str = wrap_const Value.str 'hello'
+ num = wrap ValueStream.num 1
+ str = wrap ValueStream.str 'hello'
+ c_num = wrap_const ValueStream.num 1
+ c_str = wrap_const ValueStream.str 'hello'
it 'matches lists', ->
assert.is.same {num, num, str}, match 'num num str', {num, num, str}
diff --git a/spec/core/result_spec.moon b/spec/core/result_spec.moon
index cc7cd71..017be58 100644
--- a/spec/core/result_spec.moon
+++ b/spec/core/result_spec.moon
@@ -1,5 +1,5 @@
-import Result, Value, Scope, SimpleRegistry from require 'core'
-import Input, Op, IO from require 'core.base'
+import Result, Scope, SimpleRegistry from require 'core'
+import Input, Op, ValueStream, EventStream, IOStream from require 'core.base'
import Logger from require 'logger'
Logger.init 'silent'
@@ -15,13 +15,13 @@ reg = SimpleRegistry!
setup -> reg\grab!
teardown -> reg\release!
-class DirtyIO extends IO
- tick: =>
+class DirtyIO extends IOStream
+ new: => super 'dirty-io'
dirty: => true
describe 'Result', ->
it 'wraps value, children', ->
- value = Value.num 3
+ value = ValueStream.num 3
a = Result!
b = Result!
@@ -33,14 +33,14 @@ describe 'Result', ->
assert.is.same children, result.children
it ':type gets type and assets value', ->
- result = Result value: Value.num 2
+ result = Result value: ValueStream.num 2
assert.is.equal 'num', result\type!
result = Result!
assert.has.error -> result\type!
it ':is_const', ->
- value = Value.num 2
+ value = ValueStream.num 2
pure = Result :value
impure = result_with_sideinput value, {}
@@ -52,8 +52,8 @@ describe 'Result', ->
assert.has.error (-> impure\const 'test'), 'test'
it ':make_ref', ->
- value = Value.num 2
- input = Input.value value
+ value = ValueStream.num 2
+ input = Input.hot value
op = op_with_inputs { input }
thick = Result :value, :op, children: { Result!, Result! }
ref = thick\make_ref!
@@ -65,11 +65,11 @@ describe 'Result', ->
assert.is.nil ref.op
it 'lifts up inputs from op', ->
- event = Value 'bang', false
- event_input = Input.event event
+ event = ValueStream 'bang', false
+ event_input = Input.hot event
- value = Value 'num', 4
- value_input = Input.value value
+ value = ValueStream 'num', 4
+ value_input = Input.hot value
op = op_with_inputs { event_input, value_input }
result = Result op: op, :value
@@ -79,11 +79,11 @@ describe 'Result', ->
result.side_inputs
it 'does not lift up op inputs that are also child values', ->
- event = Value 'bang', false
- event_input = Input.event event
+ event = ValueStream 'bang', false
+ event_input = Input.hot event
- value = Value 'num', 4
- value_input = Input.value value
+ value = ValueStream 'num', 4
+ value_input = Input.hot value
op = op_with_inputs { event_input, value_input }
result = Result op: op, :value, children: { Result :value }
@@ -91,13 +91,13 @@ describe 'Result', ->
assert.is.same { [event]: event_input }, result.side_inputs
it 'lifts up side_inputs from children', ->
- event_value = Value 'bang', false
- event_input = Input.event event_value
+ event_value = ValueStream 'bang', false
+ event_input = Input.hot event_value
event = Result op: op_with_inputs { event_input }
assert.is.same { [event_value]: event_input }, event.side_inputs
- value_value = Value 'num', 4
- value_input = Input.value value_value
+ value_value = ValueStream 'num', 4
+ value_input = Input.hot value_value
value = Result op: op_with_inputs { value_input }
assert.is.same { [value_value]: value_input }, value.side_inputs
@@ -109,16 +109,16 @@ describe 'Result', ->
local a_value, a_child, a_input
local b_value, b_child, b_input
before_each ->
- a_value = Value 'num'
- a_input = Input.event a_value
+ a_value = EventStream 'num'
+ a_input = Input.hot a_value
a_child = result_with_sideinput a_value, a_input
- b_value = Value 'num'
- b_input = Input.event b_value
+ b_value = EventStream 'num'
+ b_input = Input.hot b_value
b_child = result_with_sideinput b_value, b_input
it 'updates children when a side_input is dirty', ->
- a_value\set 1
+ a_value\add 1
assert.is.true a_input\dirty!
assert.is.false b_input\dirty!
@@ -145,11 +145,11 @@ describe 'Result', ->
assert.spy(b).was_not_called!
it 'updates op when any op-inputs are dirty', ->
- a_value\set 1
+ a_value\add 1
assert.is.true a_input\dirty!
assert.is.false b_input\dirty!
- op = op_with_inputs a: Input.event a_value
+ op = op_with_inputs a: Input.hot a_value
s = spy.on op, 'tick'
result = Result :op, children: { a_child, b_child }
@@ -158,11 +158,11 @@ describe 'Result', ->
assert.spy(s).was_called_with match.ref op
it 'early-outs when no op-inputs are dirty', ->
- a_value\set 1
+ a_value\add 1
assert.is.true a_input\dirty!
assert.is.false b_input\dirty!
- op = op_with_inputs { Input.event b_value }
+ op = op_with_inputs { Input.hot b_value }
s = spy.on op, 'tick'
result = Result :op, children: { a_child, b_child }
@@ -173,13 +173,12 @@ describe 'Result', ->
describe ':tick_io', ->
it 'ticks IOs referenced in side_inputs', ->
io = DirtyIO!
- value = Value 'an_io', io
- input = Input.io value
+ input = Input.hot io
op = op_with_inputs { input }
result = Result :op
s = spy.on io, 'tick'
- assert.is.same { [value]: input }, result.side_inputs
+ assert.is.same { [io]: input }, result.side_inputs
result\tick_io!
assert.spy(s).was_called_with match.ref io
diff --git a/spec/core/scope_spec.moon b/spec/core/scope_spec.moon
index 6d7d754..59c6bd1 100644
--- a/spec/core/scope_spec.moon
+++ b/spec/core/scope_spec.moon
@@ -1,4 +1,4 @@
-import Scope, Value, Result from require 'core'
+import Scope, ValueStream, Result from require 'core'
import Op from require 'core.base'
import Logger from require 'logger'
Logger.init 'silent'
@@ -27,7 +27,7 @@ describe 'Scope', ->
assert.is.equal "im a happy string", got.value
test 'Values', ->
- pi = Value 'num', 3.14
+ pi = ValueStream 'num', 3.14
scope\set_raw 'pi', pi
assert.is.equal pi, (scope\get 'pi')\const!
@@ -48,7 +48,7 @@ describe 'Scope', ->
assert.is.equal sub, got.value
test 'tables', ->
- pi = Value 'num', 3.14
+ pi = ValueStream 'num', 3.14
scope\set_raw 'math', { :pi }
got = (scope\get 'math')\const!
@@ -58,7 +58,7 @@ describe 'Scope', ->
assert.is.equal pi, (scope\get 'math/pi')\const!
it 'wraps Values in from_table', ->
- pi = Value 'num', 3.14
+ pi = ValueStream 'num', 3.14
scope = Scope.from_table {
num: 3
str: "im a happy string"
@@ -90,7 +90,7 @@ describe 'Scope', ->
a = Scope!
b = Scope!
- pi = Value 'num', 3.14
+ pi = ValueStream 'num', 3.14
b\set_raw 'test', pi
a\set_raw 'child', b
root\set_raw 'deep', a
@@ -98,8 +98,8 @@ describe 'Scope', ->
assert.is.equal pi, (root\get 'deep/child/test')\const!
describe 'can set symbols', ->
- one = wrap_res Value.num 1
- two = wrap_res Value.num 2
+ one = wrap_res ValueStream.num 1
+ two = wrap_res ValueStream.num 2
scope = Scope!
it 'disallows re-setting symbols', ->
diff --git a/spec/core/value_spec.moon b/spec/core/value_spec.moon
index eeb3339..b447d32 100644
--- a/spec/core/value_spec.moon
+++ b/spec/core/value_spec.moon
@@ -1,4 +1,4 @@
-import Value, Result, Scope, SimpleRegistry from require 'core'
+import ValueStream, Result, Scope, SimpleRegistry from require 'core'
import Op, Action from require 'core.base'
import Logger from require 'logger'
Logger.init 'silent'
@@ -13,101 +13,101 @@ reg = SimpleRegistry!
setup -> reg\grab!
teardown -> reg\release!
-describe 'Value', ->
+describe 'ValueStream', ->
describe '.wrap', ->
it 'wraps numbers', ->
- got = Value.wrap 3
+ got = ValueStream.wrap 3
assert.is.equal 'num', got.type
assert.is.equal 3, got.value
it 'wraps strings', ->
- got = Value.wrap "im a happy string"
+ 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 = Value 'num', 3.14
- got = Value.wrap pi
+ pi = ValueStream 'num', 3.14
+ got = ValueStream.wrap pi
assert.is.equal pi, got
it 'wraps Opdefs', ->
- got = Value.wrap TestOp
+ got = ValueStream.wrap TestOp
assert.is.equal 'opdef', got.type
assert.is.equal TestOp, got.value
it 'wraps Bultins', ->
- got = Value.wrap TestAction
+ got = ValueStream.wrap TestAction
assert.is.equal 'builtin', got.type
assert.is.equal TestAction, got.value
it 'wraps Scopes', ->
sub = Scope!
- got = Value.wrap sub
+ got = ValueStream.wrap sub
assert.is.equal 'scope', got.type
assert.is.equal sub, got.value
it 'wraps tables', ->
- pi = Value 'num', 3.14
- got = Value.wrap { :pi }
+ 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, (Value.num 3.14)\unwrap!
- assert.is.equal 'hi', (Value.str 'hi')\unwrap!
- assert.is.equal 'hi', (Value.sym 'hi')\unwrap!
+ 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, (Value.num 3.14)\unwrap 'num'
- assert.is.equal 'hi', (Value.str 'hi')\unwrap 'str'
- assert.is.equal 'hi', (Value.sym 'hi')\unwrap 'sym'
- assert.has_error -> (Value.num 3.14)\unwrap 'sym'
- assert.has_error -> (Value.str 'hi')\unwrap 'num'
- assert.has_error -> (Value.sym 'hi')\unwrap 'str'
+ 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, (Value.num 3.14)!
- assert.is.equal 'hi', (Value.str 'hi')!
- assert.is.equal 'hi', (Value.sym 'hi')!
- assert.is.equal 3.14, (Value.num 3.14) 'num'
- assert.is.equal 'hi', (Value.str 'hi') 'str'
- assert.is.equal 'hi', (Value.sym 'hi') 'sym'
- assert.has_error -> (Value.num 3.14) 'sym'
- assert.has_error -> (Value.str 'hi') 'num'
- assert.has_error -> (Value.sym 'hi') 'str'
+ 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 = Value 'num', 3
- assert.is.equal (Value.num 3), val
- assert.not.equal (Value.str '3'), val
+ val = ValueStream 'num', 3
+ assert.is.equal (ValueStream.num 3), val
+ assert.not.equal (ValueStream.str '3'), val
- val = Value 'str', 'hello'
- assert.is.equal (Value.str 'hello'), val
- assert.not.equal (Value.sym 'hello'), val
+ val = ValueStream 'str', 'hello'
+ assert.is.equal (ValueStream.str 'hello'), val
+ assert.not.equal (ValueStream.sym 'hello'), val
it 'compares the value', ->
- val = Value 'num', 3
- assert.is.equal (Value.num 3), val
- assert.not.equal (Value.num 4), val
+ 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 = Value 'num', 3
- assert.is.equal (Value.num 3), val
+ val = ValueStream 'num', 3
+ assert.is.equal (ValueStream.num 3), val
val\set 4
- assert.is.equal (Value.num 4), val
- assert.not.equal (Value.num 3), val
+ assert.is.equal (ValueStream.num 4), val
+ assert.not.equal (ValueStream.num 3), val
it 'marks the value dirty', ->
- val = Value 'num', 3
+ val = ValueStream 'num', 3
assert.is.false val\dirty!
val\set 4
@@ -118,42 +118,42 @@ describe 'Value', ->
assert_noop = (val) ->
assert.is.equal val, val\eval!\const!
- assert_noop Value.num 2
- assert_noop Value.str 'hello'
+ assert_noop ValueStream.num 2
+ assert_noop ValueStream.str 'hello'
it 'looks up symbols in the scope', ->
scope = with Scope!
- \set 'number', Result value: Value.num 3
- \set 'hello', Result value: Value.str "world"
- \set 'goodbye', Result value: Value.sym "again"
+ \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 = Value.sym sym
+ const = ValueStream.sym sym
assert.is.equal val, (const\eval scope)\const!
- assert_eval 'number', Value.num 3
- assert_eval 'hello', Value.str "world"
- assert_eval 'goodbye', Value.sym "again"
+ assert_eval 'number', ValueStream.num 3
+ assert_eval 'hello', ValueStream.str "world"
+ assert_eval 'goodbye', ValueStream.sym "again"
it ':quote s literals as themselves', ->
assert_noop = (val) -> assert.is.equal val, val\quote!
- assert_noop Value.num 2
- assert_noop Value.str 'hello'
- assert_noop Value.sym 'world'
+ assert_noop ValueStream.num 2
+ assert_noop ValueStream.str 'hello'
+ assert_noop ValueStream.sym 'world'
it ':clone sliterals as themselves', ->
assert_noop = (val) -> assert.is.equal val, val\clone!
- assert_noop Value.num 2
- assert_noop Value.str 'hello'
- assert_noop Value.sym 'world'
+ assert_noop ValueStream.num 2
+ assert_noop ValueStream.str 'hello'
+ assert_noop ValueStream.sym 'world'
describe ':fork', ->
it 'is equal to the original', ->
- a = Value.num 2
- b = Value.str 'asdf'
- c = with Value 'weird', {}, '(raw)'
+ a = ValueStream.num 2
+ b = ValueStream.str 'asdf'
+ c = with ValueStream 'weird', {}, '(raw)'
\set {}
aa, bb, cc = a\fork!, b\fork!, c\fork!
@@ -168,8 +168,8 @@ describe 'Value', ->
assert.is.equal c.raw, cc.raw
it 'isolates the original from the fork', ->
- a = Value.num 3
- b = with Value 'weird', {}, '(raw)'
+ a = ValueStream.num 3
+ b = with ValueStream 'weird', {}, '(raw)'
\set {}
aa, bb = a\fork!, b\fork!