aboutsummaryrefslogtreecommitdiffstats
path: root/spec/cell_spec.moon
diff options
context:
space:
mode:
Diffstat (limited to 'spec/cell_spec.moon')
-rw-r--r--spec/cell_spec.moon73
1 files changed, 10 insertions, 63 deletions
diff --git a/spec/cell_spec.moon b/spec/cell_spec.moon
index f55ab4d..b31ef99 100644
--- a/spec/cell_spec.moon
+++ b/spec/cell_spec.moon
@@ -1,5 +1,5 @@
import Cell, RootCell, Const, Scope, globals from require 'core'
-import Registry from require 'registry'
+import Registry from require 'core.registry'
import Logger from require 'logger'
Logger.init 'silent'
@@ -7,70 +7,17 @@ hello_world = Cell nil, { (Const.sym 'hello'), (Const.str 'world') }
two_plus_two = Cell nil, { (Const.sym '+'), (Const.num 2), (Const.num 2) }
describe 'Cell', ->
- describe 'quoting', ->
- it 'quotes children', ->
- reg = mock register: =>
- with hello_world\quote nil, reg
- assert.is.equal Cell, .__class
- assert.is.equal (Const.sym 'hello'), \head!
- assert.is.same { Const.str 'world' }, \tail!
+ it 'supports quoting', ->
+ with hello_world\quote!
+ assert.is.equal Cell, .__class
+ assert.is.equal (Const.sym 'hello'), \head!
+ assert.is.same { Const.str 'world' }, \tail!
- with two_plus_two\quote nil, reg
- assert.is.equal Cell, .__class
- assert.is.equal (Const.sym '+'), \head!
- assert.is.same { (Const.num 2), (Const.num 2) }, \tail!
+ with two_plus_two\quote!
+ assert.is.equal Cell, .__class
+ assert.is.equal (Const.sym '+'), \head!
+ assert.is.same { (Const.num 2), (Const.num 2) }, \tail!
- it 'registers recursively', ->
- root = Cell nil, { (Const.sym 'out'), hello_world, two_plus_two }
-
- reg = mock register: =>
- root\quote nil, reg
-
- (assert.spy reg.register).was.called_with reg, root, nil
- (assert.spy reg.register).was.called_with reg, hello_world, nil
- (assert.spy reg.register).was.called_with reg, two_plus_two, nil
-
- it 'passes parsed tag', ->
- root = Cell (Const.num 2), { (Const.sym 'out'), hello_world, two_plus_two }
-
- reg = mock register: =>
- root\quote nil, reg
-
- (assert.spy reg.register).was.called!
- (assert.spy reg.register).was.called_with reg, match._, Const.num 2
-
- describe 'evaluation', ->
- globals\use Scope.from_table require 'lib.math'
- registry = Registry!
-
- local op, action
-
- it 'instantiates the op + action', ->
- op = two_plus_two\eval globals, registry
- action = registry.map[two_plus_two.tag.value]
-
- assert.is.equal 'add', op.__class.__name
- assert.is.equal 'op_invoke', action.__class.__name
- registry\step!
-
- it 'calls :setup() when parameters change', ->
- two_plus_two.children[3] = Const.num 3
-
- s = spy.on op, 'setup'
- assert.is.equal op, two_plus_two\eval globals, registry
- assert.is.equal action, registry.map[two_plus_two.tag.value]
- (assert.spy s).was.called_with (match.is_ref op), (Const.num 2), (Const.num 3)
- registry\step!
-
- it 'calls :destroy() when opdef changes', ->
- two_plus_two.children[1] = Const.sym 'sub'
- two_plus_two.children[2] = Const.num 6
-
- s = spy.on op, 'destroy'
- assert.not.equal op, two_plus_two\eval globals, registry
- assert.is.equal action, registry.map[two_plus_two.tag.value]
- assert.is.equal 'sub', action.op.__class.__name
- (assert.spy s).was.called_with match.is_ref op
describe 'RootCell', ->
test 'head is always "do"', ->