aboutsummaryrefslogtreecommitdiffstats
path: root/spec/input_spec.moon
blob: 04cf16effc018492b5ac37c47b57d3f5b45213f1 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import do_setup, do_teardown from require 'spec.test_setup'
import Input, T, Result from require 'alv.base'

setup do_setup
teardown do_teardown

basic_tests = (result, input) ->
  it 'gives access to the Result', ->
    assert.is.equal result, input.result

  it 'forwards :unwrap', ->
    assert.is.equal result\unwrap!, input\unwrap!, nil
    assert.is.equal result\unwrap!, input!, nil

  it 'gives access to the type string', ->
    assert.is.equal result.type, input\type!

  it 'gives access to the metatype string', ->
    assert.is.equal result.metatype, input\metatype!

describe 'Input.cold', ->
  result = T.num\mk_sig 1
  input = Input.cold result

  basic_tests result, input

  it 'is marked cold', ->
    assert.is.equal 'cold', input.mode

  it 'is never dirty', ->
    assert.is.false input\dirty!
    result\set 2
    assert.is.false input\dirty!

    input\setup nil
    assert.is.false input\dirty!
    input\finish_setup!

    new_input = Input.cold T.num\mk_sig 3
    new_input\setup input
    assert.is.false new_input\dirty!
    new_input.result\set 4
    assert.is.false new_input\dirty!
    input\finish_setup!

describe 'Input.hot', ->
  describe 'with Constant', ->
    result = T.num\mk_const 1
    input = Input.hot result

    basic_tests result, input

    it 'is marked cold', ->
      assert.is.equal 'cold', input.mode

    describe 'at evaltime', ->
      it 'is dirty when new', ->
        assert.is.false result\dirty!

        newinput = Input.hot result
        newinput\setup nil
        assert.is.true newinput\dirty!
        newinput\finish_setup!

      it 'is dirty when different', ->
        newval = T.num\mk_const 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 = T.num\mk_const 1

        assert.is.false newval\dirty!
        newinput = Input.hot newval
        newinput\setup input
        assert.is.false newinput\dirty!
        newinput\finish_setup!

  describe 'with EvtStream', ->
    result = T.num\mk_evt!
    input = Input.hot result

    basic_tests result, input

    it 'is marked hot', ->
      assert.is.equal 'hot', input.mode

    it 'is dirty when the EvtStream is dirty', ->
      assert.is.false input\dirty!
      assert.is.false result\dirty!

      input\setup nil
      assert.is.false input\dirty!
      input\finish_setup!

      COPILOT\next_tick!
      result\set 1

      assert.is.true input\dirty!
      assert.is.true result\dirty!

      input\setup nil
      assert.is.true input\dirty!
      input\finish_setup!

      assert.is.true input\dirty!
      assert.is.true result\dirty!

  describe 'with SigStream', ->
    result = T.num\mk_sig 1
    local input

    describe 'at evaltime', ->
      it 'is dirty when new', ->
        assert.is.false result\dirty!

        input = Input.hot result
        input\setup nil
        assert.is.true input\dirty!
        input\finish_setup!

      it 'is dirty when different', ->
        newval = T.num\mk_sig 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 = T.num\mk_sig!
        newval\set 1

        assert.is.true newval\dirty!
        newinput = Input.hot newval
        newinput\setup input
        assert.is.false newinput\dirty!
        newinput\finish_setup!

    it 'is marked hot', ->
      assert.is.equal 'hot', input.mode

    describe 'at runtime', ->
      it 'is dirty when the result is dirty', ->
        result\set 3
        assert.is.true result\dirty!
        assert.is.true input\dirty!

        COPILOT\next_tick!
        assert.is.false result\dirty!
        assert.is.false input\dirty!