aboutsummaryrefslogtreecommitdiffstats
path: root/spec/cell_spec.moon
blob: b31ef997035c3bf6bf8c76e54351bf5dd21ef2d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Cell, RootCell, Const, Scope, globals from require 'core'
import Registry from require 'core.registry'
import Logger from require 'logger'
Logger.init 'silent'

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', ->
  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!
      assert.is.equal Cell, .__class
      assert.is.equal (Const.sym '+'), \head!
      assert.is.same { (Const.num 2), (Const.num 2) }, \tail!


describe 'RootCell', ->
  test 'head is always "do"', ->
    cell = RootCell\parse {}
    assert.is.equal (Const.sym 'do'), cell\head!

    cell = RootCell nil, { hello_world, two_plus_two }
    assert.is.equal (Const.sym 'do'), cell\head!

  test 'tail is all children', ->
    cell = RootCell\parse {}
    assert.is.same {}, cell\tail!

    cell = RootCell nil, { hello_world, two_plus_two }
    assert.is.same { hello_world, two_plus_two },
                   cell\tail!