From 03c1ee5726a39bcee72e368c4cbab264452e28cd Mon Sep 17 00:00:00 2001 From: s-ol Date: Tue, 12 May 2020 17:05:26 +0200 Subject: EvtStream:set(nil) doesnt set :dirty --- alv/result/evt.moon | 2 ++ spec/result/evt_spec.moon | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/alv/result/evt.moon b/alv/result/evt.moon index a89aa74..6bd0fee 100644 --- a/alv/result/evt.moon +++ b/alv/result/evt.moon @@ -65,7 +65,9 @@ class EvtStream extends Result --- push an event value into the stream. -- -- Marks this stream as dirty for the remainder of the current tick. + -- If `event` is nil, does nothing. set: (event) => + return if event == nil assert not @dirty!, "#{@} is already dirty!" @updated = COPILOT.T @value = event diff --git a/spec/result/evt_spec.moon b/spec/result/evt_spec.moon index 93c09e0..c9416db 100644 --- a/spec/result/evt_spec.moon +++ b/spec/result/evt_spec.moon @@ -52,6 +52,23 @@ describe 'EvtStream', -> assert.is.equal 3, stream\unwrap! assert.is.true stream\dirty! + it 'ignores nil values', -> + stream = EvtStream T.num + assert.is.nil stream\unwrap! + assert.is.false stream\dirty! + + stream\set! + assert.is.nil stream\unwrap! + assert.is.false stream\dirty! + + stream\set nil + assert.is.nil stream\unwrap! + assert.is.false stream\dirty! + + stream\set false + assert.is.equal false, stream\unwrap! + assert.is.true stream\dirty! + it 'errors when set twice', -> stream = EvtStream T.num stream\set 1 -- cgit v1.2.3