aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lang/do_spec.moon
blob: 67b7b338006241a54774758e2b9b6675f74ea149 (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
import TestPilot from require 'spec.test_setup'
import T, Struct, Array, Constant from require 'alv'

describe "do", ->
  COPILOT = TestPilot ''

  it "can be empty", ->
    rt = COPILOT\eval_once '(do)'
    assert.is.true rt\is_const!
    assert.is.nil rt.result

  it "returns the last result, if any", ->
    rt = COPILOT\eval_once '(do 1 2 3)'
    assert.is.true rt\is_const!
    assert.is.equal (Constant.num 3), rt.result

    rt = COPILOT\eval_once '(do 1 2 (trace 3))'
    assert.is.true rt\is_const!
    assert.is.nil rt.result

  it "passes through side-effects", ->
    rt = COPILOT\eval_once '
      (import* time)
      (do
        (every 0.5 "bang! side-effect")
        3)'
    assert.is.false rt\is_const!
    assert.is.equal (Constant.num 3), rt.result