diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2019-11-01 20:04:18 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2019-11-01 20:04:18 +0000 |
| commit | 5934b80f09c1c13fa4698e59a77d0c51b7c7b357 (patch) | |
| tree | 265742939a732b06a224d870026b22e1154add71 /spec | |
| parent | API redesign (diff) | |
| download | watch-cad-5934b80f09c1c13fa4698e59a77d0c51b7c7b357.tar.gz watch-cad-5934b80f09c1c13fa4698e59a77d0c51b7c7b357.zip | |
make things work
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/state_spec.moon | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/state_spec.moon b/spec/state_spec.moon new file mode 100644 index 0000000..b2085c5 --- /dev/null +++ b/spec/state_spec.moon @@ -0,0 +1,62 @@ +import Once, State from require 'state' + +describe "Once", -> + it "stores a value", -> + a = Once 3 + assert.is.equal 3, a.value + + it "can test for itself", -> + assert.is_true Once.is_once Once 3 + assert.is_true Once.is_once Once 2 + assert.is_true Once.is_once Once nil + assert.is_true Once.is_once Once { a: 3 } + + it "can test other types", -> + assert.is_falsy Once.is_once nil + assert.is_falsy Once.is_once 3 + assert.is_falsy Once.is_once "once impostor" + assert.is_falsy Once.is_once { a: 3 } + +describe "State", -> + local S + before_each -> + state = State! + S = state.state + + it "can be indexed infinitely", -> + assert.is_table S.a.b.c.d + + describe ":init", -> + it "stores default until changed", -> + S\init 'test', 2 + assert.is.equal 2, S.test + + S.test = 4 + assert.is.equal 4, S.test + + S\init 'test', 2 + assert.is.equal 4, S.test + + describe ":store", -> + it "stores defaults until changed", -> + S\store 'test', nil, 3 + assert.is.equal 3, S.test + + S\store 'test', nil, 4 + assert.is.equal 3, S.test + + it "follows live inputs", -> + S\store 'test', 3, 'nope' + assert.is.equal 3, S.test + + S\store 'test', 4, 'nope' + assert.is.equal 4, S.test + + it "lets Once() inputs override defaults", -> + S\store 'test', (Once 3), 'nope' + assert.is.equal 3, S.test + + S\store 'test', 'changed' + + S\store 'test', (Once 4), 'nope' + assert.is.equal 'changed', S.test |
