diff options
Diffstat (limited to 'spec/core/input_spec.moon')
| -rw-r--r-- | spec/core/input_spec.moon | 264 |
1 files changed, 105 insertions, 159 deletions
diff --git a/spec/core/input_spec.moon b/spec/core/input_spec.moon index e2ec7e3..4b470db 100644 --- a/spec/core/input_spec.moon +++ b/spec/core/input_spec.moon @@ -1,4 +1,4 @@ -import Input, Result, Value, IO from require 'core.base' +import Input, Result, ValueStream, EventStream, IOStream from require 'core.base' import SimpleRegistry from require 'core' import Logger from require 'logger' Logger.init 'silent' @@ -7,198 +7,144 @@ reg = SimpleRegistry! setup -> reg\grab! teardown -> reg\release! -describe 'Input.event', -> - val = Value.num 1 - input = Input.event val - - describe 'at evaltime', -> - it 'follows Value when new', -> - input\setup nil - - val\set 2 - assert.is.true val\dirty! - assert.is.true input\dirty! - - reg\next_tick! - assert.is.false val\dirty! - assert.is.false input\dirty! - - input\finish_setup! - - it 'follows Value when different', -> - new_input = Input.event Value.num 3 - new_input\setup input - - assert.is.false new_input.stream\dirty! - assert.is.false new_input\dirty! - - new_input.stream\set 3 - assert.is.true new_input.stream\dirty! - assert.is.true new_input\dirty! - - reg\next_tick! - new_input\finish_setup! - - it 'follows Value when equal', -> - new_input = Input.event Value.num 2 - new_input\setup input - - assert.is.false new_input.stream\dirty! - assert.is.false new_input\dirty! - - new_input.stream\set 2 - assert.is.true new_input.stream\dirty! - assert.is.true new_input\dirty! - - describe 'at runtime', -> - it 'is dirty when the value is dirty', -> - val\set 3 - assert.is.true val\dirty! - assert.is.true input\dirty! - - reg\next_tick! - assert.is.false val\dirty! - assert.is.false input\dirty! - - it 'unwraps to the lua value', -> - assert.is.equal 3, input\unwrap! - assert.is.equal 3, input! - - it 'gives access to the type string', -> - assert.is.equal 'num', input\type! - - it 'gives access to the Value', -> - assert.is.equal val, input.stream - -describe 'Input.value', -> - val = Value.num 1 - local input - - describe 'at evaltime', -> - it 'is dirty when new', -> - assert.is.false val\dirty! - - input = Input.value val - input\setup nil - assert.is.true input\dirty! - input\finish_setup! - - it 'is dirty when different', -> - newval = Value.num 2 - - assert.is.false newval\dirty! - newinput = Input.value newval - newinput\setup input - assert.is.true newinput\dirty! - newinput\finish_setup! - - it 'is not dirty when equal', -> - newval = Value.num 1 - newval\set 1 - - assert.is.true newval\dirty! - newinput = Input.value newval - newinput\setup input - assert.is.false newinput\dirty! - newinput\finish_setup! - - describe 'at runtime', -> - it 'is dirty when the value is dirty', -> - val\set 3 - assert.is.true val\dirty! - assert.is.true input\dirty! +class MyIO extends IOStream + new: => super 'my-io' + dirty: => @is_dirty - reg\next_tick! - assert.is.false val\dirty! - assert.is.false input\dirty! +basic_tests = (stream, input) -> + it 'gives access to the Stream', -> + assert.is.equal stream, input.stream - it 'unwraps to the lua value', -> - assert.is.equal 3, input\unwrap! - assert.is.equal 3, input! + it 'forwards :unwrap', -> + assert.is.same stream\unwrap!, input\unwrap! + assert.is.same stream\unwrap!, input! it 'gives access to the type string', -> - assert.is.equal 'num', input\type! - - it 'gives access to the Value', -> - assert.is.equal val, input.stream + assert.is.equal stream.type, input\type! describe 'Input.cold', -> - val = Value.num 1 - input = Input.cold val + stream = ValueStream.num 1 + input = Input.cold stream + + basic_tests stream, input it 'is never dirty', -> assert.is.false input\dirty! - val\set 2 + stream\set 2 assert.is.false input\dirty! input\setup nil assert.is.false input\dirty! input\finish_setup! - new_input = Input.cold Value.num 3 + new_input = Input.cold ValueStream.num 3 new_input\setup input assert.is.false new_input\dirty! new_input.stream\set 4 assert.is.false new_input\dirty! input\finish_setup! - it 'unwraps to the lua value', -> - assert.is.equal 2, input\unwrap! - assert.is.equal 2, input! +describe 'Input.hot', -> + describe 'with EventStream', -> + stream = EventStream 'num' + input = Input.hot stream - it 'gives access to the type string', -> - assert.is.equal 'num', input\type! + basic_tests stream, input - it 'gives access to the Value', -> - assert.is.equal val, input.stream + it 'is marked for lifting', -> + assert.is.nil input.io -class MyIO extends IO - dirty: => @is_dirty + it 'is dirty when the EventStream is dirty', -> + assert.is.false input\dirty! + assert.is.false stream\dirty! -describe 'Input.io', -> - io = MyIO! - val = Value 'test-io', io - input = Input.io val + input\setup nil + assert.is.false input\dirty! + input\finish_setup! - it 'is dirty when the IO is dirty', -> - io.is_dirty = false + reg\next_tick! + stream\add 1 - assert.is.false val\dirty! - assert.is.false input\dirty! - assert.is.false io\dirty! + assert.is.true input\dirty! + assert.is.true stream\dirty! - input\setup nil - assert.is.false input\dirty! - input\finish_setup! + input\setup nil + assert.is.true input\dirty! + input\finish_setup! - val\set io - assert.is.true val\dirty! - assert.is.false input\dirty! - assert.is.false io\dirty! + assert.is.true input\dirty! + assert.is.true stream\dirty! - reg\next_tick! + describe 'with IOStream', -> + stream = MyIO! + input = Input.hot stream - io.is_dirty = true + basic_tests stream, input - assert.is.false val\dirty! - assert.is.true input\dirty! - assert.is.true io\dirty! + it 'is marked for lifting', -> + assert.is.true input.io - input\setup nil - assert.is.true input\dirty! - input\finish_setup! + it 'is dirty when the IOStream is dirty', -> + stream.is_dirty = false - val\set io - assert.is.true val\dirty! - assert.is.true input\dirty! - assert.is.true io\dirty! + assert.is.false input\dirty! + assert.is.false stream\dirty! - it 'unwraps to the io value', -> - assert.is.equal io, input\unwrap! - assert.is.equal io, input! + input\setup nil + assert.is.false input\dirty! + input\finish_setup! - it 'gives access to the type string', -> - assert.is.equal 'test-io', input\type! + reg\next_tick! + stream.is_dirty = true + + assert.is.true input\dirty! + assert.is.true stream\dirty! + + input\setup nil + assert.is.true input\dirty! + input\finish_setup! - it 'gives access to the Value', -> - assert.is.equal val, input.stream + assert.is.true input\dirty! + assert.is.true stream\dirty! + + describe 'with ValueStream', -> + stream = ValueStream.num 1 + local input + + describe 'at evaltime', -> + it 'is dirty when new', -> + assert.is.false stream\dirty! + + input = Input.hot stream + input\setup nil + assert.is.true input\dirty! + input\finish_setup! + + it 'is dirty when different', -> + newval = ValueStream.num 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 = ValueStream.num 1 + newval\set 1 + + assert.is.true newval\dirty! + newinput = Input.hot newval + newinput\setup input + assert.is.false newinput\dirty! + newinput\finish_setup! + + describe 'at runtime', -> + it 'is dirty when the stream is dirty', -> + stream\set 3 + assert.is.true stream\dirty! + assert.is.true input\dirty! + + reg\next_tick! + assert.is.false stream\dirty! + assert.is.false input\dirty! |
