diff options
Diffstat (limited to 'spec/result')
| -rw-r--r-- | spec/result/evt_spec.moon | 111 | ||||
| -rw-r--r-- | spec/result/sig_spec.moon | 6 |
2 files changed, 111 insertions, 6 deletions
diff --git a/spec/result/evt_spec.moon b/spec/result/evt_spec.moon new file mode 100644 index 0000000..93c09e0 --- /dev/null +++ b/spec/result/evt_spec.moon @@ -0,0 +1,111 @@ +import do_setup from require 'spec.test_setup' +import EvtStream, RTNode, Scope, SimpleRegistry, T from require 'alv' +import Op, Builtin from require 'alv.base' + +setup do_setup + +describe 'EvtStream', -> + describe ':unwrap', -> + it 'returns the set value', -> + stream = EvtStream T.num + assert.is.nil stream\unwrap! + + stream\set 3.14 + assert.is.equal 3.14, stream\unwrap! + + it 'returns nil if not dirty', -> + stream = EvtStream T.num + assert.is.nil stream\unwrap! + + stream\set 3.14 + COPILOT\next_tick! + assert.is.nil stream\unwrap! + + test 'can assert the type', -> + assert.is.nil (EvtStream T.num)\unwrap T.num + assert.is.nil (EvtStream T.str)\unwrap T.str + assert.is.nil (EvtStream T.sym)\unwrap T.sym + assert.has_error -> (EvtStream T.num)\unwrap T.sym + assert.has_error -> (EvtStream T.str)\unwrap T.num + assert.has_error -> (EvtStream T.sym)\unwrap T.str + + test 'has __call shorthand', -> + stream = EvtStream T.num + assert.is.nil stream! + + stream\set 3.14 + assert.is.equal 3.14, stream! + + describe ':set', -> + it 'sets the value', -> + stream = EvtStream T.num + assert.is.false stream\dirty! + + stream\set 4 + assert.is.equal 4, stream\unwrap! + assert.is.true stream\dirty! + + COPILOT\next_tick! + + assert.is.false stream\dirty! + stream\set 3 + assert.is.equal 3, stream\unwrap! + assert.is.true stream\dirty! + + it 'errors when set twice', -> + stream = EvtStream T.num + stream\set 1 + assert.has.error -> stream\set 2 + assert.is.equal 1, stream\unwrap! + + it 'resets on the next tick', -> + stream = EvtStream T.num + stream\set 1 + + COPILOT\next_tick! + + assert.is.false stream\dirty! + stream\set 2 + assert.is.equal 2, stream\unwrap! + assert.is.true stream\dirty! + + describe ':fork', -> + it 'is clean', -> + a = EvtStream T.num + b = EvtStream T.str + b\set 'asdf' + + aa, bb = a\fork!, b\fork! + assert.is.nil aa! + assert.is.nil bb! + assert.is.false aa\dirty! + assert.is.false bb\dirty! + + it 'leaves the original', -> + a = EvtStream T.num + b = EvtStream T.str + b\set 'asdf' + + aa, bb = a\fork!, b\fork! + assert.is.nil a! + assert.is.equal 'asdf', b! + assert.is.false a\dirty! + assert.is.true b\dirty! + + it 'isolates the original from the fork', -> + a = EvtStream T.num + b = EvtStream T.str + + aa, bb = a\fork!, b\fork! + a\set 1 + bb\set 2 + + assert.is.equal 1, a! + assert.is.true a\dirty! + assert.is.nil aa! + assert.is.false aa\dirty! + + assert.is.equal 2, bb! + assert.is.true bb\dirty! + assert.is.nil b! + assert.is.false b\dirty! diff --git a/spec/result/sig_spec.moon b/spec/result/sig_spec.moon index 6e9a11c..1a92bdc 100644 --- a/spec/result/sig_spec.moon +++ b/spec/result/sig_spec.moon @@ -2,12 +2,6 @@ import do_setup from require 'spec.test_setup' import SigStream, Constant, RTNode, Scope, SimpleRegistry, T 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 'SigStream', -> |
