diff options
| author | s-ol <s+removethis@s-ol.nu> | 2022-02-05 10:11:13 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:24:49 +0000 |
| commit | c484cce5ab1f6acd14ecad30adb586a6d5fa0fd1 (patch) | |
| tree | a45c702a83e150fea5b14b279e5f0cab9b65bc3e /spec/result | |
| parent | examples: more smoothing in love example :) (diff) | |
| download | alive-c484cce5ab1f6acd14ecad30adb586a6d5fa0fd1.tar.gz alive-c484cce5ab1f6acd14ecad30adb586a6d5fa0fd1.zip | |
rearrange spec, fix for Lua 5.1
Diffstat (limited to 'spec/result')
| -rw-r--r-- | spec/result/const_spec.moon | 158 | ||||
| -rw-r--r-- | spec/result/evt_spec.moon | 144 | ||||
| -rw-r--r-- | spec/result/sig_spec.moon | 116 |
3 files changed, 0 insertions, 418 deletions
diff --git a/spec/result/const_spec.moon b/spec/result/const_spec.moon deleted file mode 100644 index 3f31306..0000000 --- a/spec/result/const_spec.moon +++ /dev/null @@ -1,158 +0,0 @@ -import do_setup from require 'spec.test_setup' -import Constant, RTNode, Scope, SimpleRegistry, T from require 'alv' -import Op, Builtin from require 'alv.base' - -class TestOp extends Op - new: (...) => super ... - -class TestBuiltin extends Builtin - new: (...) => - -setup do_setup - -describe 'Constant', -> - it 'requires a value', -> - assert.has.error -> Constant.num! - assert.has.error -> Constant T.num - assert.has.no.error -> Constant T.bool, false - - it 'stringifies well', -> - assert.is.equal "<num= 4>", tostring Constant.num 4 - assert.is.equal "<bool= true>", tostring Constant.bool true - assert.is.equal "<bool= false>", tostring Constant.bool false - - describe '.wrap', -> - it 'wraps numbers', -> - got = Constant.wrap 3 - assert.is.equal T.num, got.type - assert.is.equal 3, got.value - - it 'wraps strings', -> - got = Constant.wrap "im a happy string" - assert.is.equal T.str, got.type - assert.is.equal "im a happy string", got.value - - it 'wraps Constants', -> - pi = Constant.num 3.14 - got = Constant.wrap pi - - assert.is.equal pi, got - - it 'wraps Opdefs', -> - got = Constant.wrap TestOp - - assert.is.equal T.opdef, got.type - assert.is.equal TestOp, got.value - - it 'wraps Bultins', -> - got = Constant.wrap TestBuiltin - - assert.is.equal T.builtin, got.type - assert.is.equal TestBuiltin, got.value - - it 'wraps Scopes', -> - sub = Scope! - got = Constant.wrap sub - - assert.is.equal T.scope, got.type - assert.is.equal sub, got.value - - it 'wraps tables', -> - pi = Constant.num 3.14 - got = Constant.wrap { :pi } - - assert.is.equal T.scope, got.type - assert.is.equal pi, (got.value\get 'pi')\const! - - describe ':unwrap', -> - it 'returns the raw value!', -> - assert.is.equal 3.14, (Constant.num 3.14)\unwrap! - assert.is.equal 'hi', (Constant.str 'hi')\unwrap! - assert.is.equal 'hi', (Constant.sym 'hi')\unwrap! - - test 'can assert the type', -> - assert.is.equal 3.14, (Constant.num 3.14)\unwrap T.num - assert.is.equal 'hi', (Constant.str 'hi')\unwrap T.str - assert.is.equal 'hi', (Constant.sym 'hi')\unwrap T.sym - assert.has_error -> (Constant.num 3.14)\unwrap T.sym - assert.has_error -> (Constant.str 'hi')\unwrap T.num - assert.has_error -> (Constant.sym 'hi')\unwrap T.str - - test 'has __call shorthand', -> - assert.is.equal 3.14, (Constant.num 3.14)! - assert.is.equal 'hi', (Constant.str 'hi')! - assert.is.equal 'hi', (Constant.sym 'hi')! - assert.is.equal 3.14, (Constant.num 3.14) T.num - assert.is.equal 'hi', (Constant.str 'hi') T.str - assert.is.equal 'hi', (Constant.sym 'hi') T.sym - assert.has_error -> (Constant.num 3.14) T.sym - assert.has_error -> (Constant.str 'hi') T.num - assert.has_error -> (Constant.sym 'hi') T.str - - describe 'overrides __eq', -> - it 'compares the type', -> - val = Constant.num 3 - assert.is.equal (Constant.num 3), val - assert.not.equal (Constant.str '3'), val - - val = Constant.str 'hello' - assert.is.equal (Constant.str 'hello'), val - assert.not.equal (Constant.sym 'hello'), val - - it 'compares the value', -> - val = Constant.num 3 - assert.is.equal (Constant.num 3), val - assert.not.equal (Constant.num 4), val - - it ':dirty is always false', -> - val = Constant.num 3 - assert.is.false val\dirty! - - val.value = 4 - assert.is.false val\dirty! - - describe ':eval', -> - it 'turns numbers into consts', -> - assert_noop = (val) -> - assert.is.equal val, val\eval!\const! - - assert_noop Constant.num 2 - assert_noop Constant.str 'hello' - - it 'looks up symbols in the scope', -> - scope = with Scope! - \set 'number', RTNode result: Constant.num 3 - \set 'hello', RTNode result: Constant.str "world" - \set 'goodbye', RTNode result: Constant.sym "again" - - assert_eval = (sym, val) -> - const = Constant.sym sym - assert.is.equal val, (const\eval scope)\const! - - assert_eval 'number', Constant.num 3 - assert_eval 'hello', Constant.str "world" - assert_eval 'goodbye', Constant.sym "again" - - it ':clones literals as themselves', -> - assert_noop = (val) -> assert.is.equal val, val\clone! - - assert_noop Constant.num 2 - assert_noop Constant.str 'hello' - assert_noop Constant.sym 'world' - - describe ':fork', -> - it 'is equal to the original', -> - a = Constant.num 2 - b = Constant.str 'asdf' - c = Constant T.weird, {}, '(raw)' - - aa, bb, cc = a\fork!, b\fork!, c\fork! - assert.is.equal a, aa - assert.is.equal b, bb - assert.is.equal c, cc - - assert.is.false aa\dirty! - assert.is.false bb\dirty! - assert.is.false cc\dirty! - - assert.is.equal c.raw, cc.raw diff --git a/spec/result/evt_spec.moon b/spec/result/evt_spec.moon deleted file mode 100644 index 46d4cec..0000000 --- a/spec/result/evt_spec.moon +++ /dev/null @@ -1,144 +0,0 @@ -import do_setup from require 'spec.test_setup' -import EvtStream, RTNode, Scope, SimpleRegistry, T from require 'alv' -import Op, Builtin from require 'alv.base' - -setup do_setup - -describe 'EvtStream', -> - it 'stringifies well', -> - number = EvtStream T.num - assert.is.equal "<num! nil>", tostring number - - number\set 4 - assert.is.equal "<num! 4>", tostring number - - bool = EvtStream T.bool - bool\set true - assert.is.equal "<bool! true>", tostring bool - - COPILOT\next_tick! - - bool\set false - assert.is.equal "<bool! false>", tostring bool - - describe ':unwrap', -> - it 'returns the set value', -> - stream = EvtStream T.num - assert.is.nil stream\unwrap! - - stream\set 3.14 - assert.is.equal 3.14, stream\unwrap! - - it 'returns nil if not dirty', -> - stream = EvtStream T.num - assert.is.nil stream\unwrap! - - stream\set 3.14 - COPILOT\next_tick! - assert.is.nil stream\unwrap! - - test 'can assert the type', -> - assert.is.nil (EvtStream T.num)\unwrap T.num - assert.is.nil (EvtStream T.str)\unwrap T.str - assert.is.nil (EvtStream T.sym)\unwrap T.sym - assert.has_error -> (EvtStream T.num)\unwrap T.sym - assert.has_error -> (EvtStream T.str)\unwrap T.num - assert.has_error -> (EvtStream T.sym)\unwrap T.str - - test 'has __call shorthand', -> - stream = EvtStream T.num - assert.is.nil stream! - - stream\set 3.14 - assert.is.equal 3.14, stream! - - describe ':set', -> - it 'sets the value', -> - stream = EvtStream T.num - assert.is.false stream\dirty! - - stream\set 4 - assert.is.equal 4, stream\unwrap! - assert.is.true stream\dirty! - - COPILOT\next_tick! - - assert.is.false stream\dirty! - stream\set 3 - 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 - assert.has.error -> stream\set 2 - assert.is.equal 1, stream\unwrap! - - it 'resets on the next tick', -> - stream = EvtStream T.num - stream\set 1 - - COPILOT\next_tick! - - assert.is.false stream\dirty! - stream\set 2 - assert.is.equal 2, stream\unwrap! - assert.is.true stream\dirty! - - describe ':fork', -> - it 'is clean', -> - a = EvtStream T.num - b = EvtStream T.str - b\set 'asdf' - - aa, bb = a\fork!, b\fork! - assert.is.nil aa! - assert.is.nil bb! - assert.is.false aa\dirty! - assert.is.false bb\dirty! - - it 'leaves the original', -> - a = EvtStream T.num - b = EvtStream T.str - b\set 'asdf' - - aa, bb = a\fork!, b\fork! - assert.is.nil a! - assert.is.equal 'asdf', b! - assert.is.false a\dirty! - assert.is.true b\dirty! - - it 'isolates the original from the fork', -> - a = EvtStream T.num - b = EvtStream T.str - - aa, bb = a\fork!, b\fork! - a\set 1 - bb\set 2 - - assert.is.equal 1, a! - assert.is.true a\dirty! - assert.is.nil aa! - assert.is.false aa\dirty! - - assert.is.equal 2, bb! - assert.is.true bb\dirty! - assert.is.nil b! - assert.is.false b\dirty! diff --git a/spec/result/sig_spec.moon b/spec/result/sig_spec.moon deleted file mode 100644 index 65363bc..0000000 --- a/spec/result/sig_spec.moon +++ /dev/null @@ -1,116 +0,0 @@ -import do_setup from require 'spec.test_setup' -import SigStream, Constant, RTNode, Scope, SimpleRegistry, T from require 'alv' -import Op, Builtin from require 'alv.base' - -setup do_setup - -describe 'SigStream', -> - it 'stringifies well', -> - assert.is.equal "<num~ 4>", tostring SigStream T.num, 4 - assert.is.equal "<bool~ true>", tostring SigStream T.bool, true - assert.is.equal "<bool~ false>", tostring SigStream T.bool, false - - describe ':unwrap', -> - it 'returns the raw value!', -> - assert.is.equal 3.14, (SigStream T.num, 3.14)\unwrap! - assert.is.equal 'hi', (SigStream T.str, 'hi')\unwrap! - assert.is.equal 'hi', (SigStream T.sym, 'hi')\unwrap! - - test 'can assert the type', -> - assert.is.equal 3.14, (SigStream T.num, 3.14)\unwrap T.num - assert.is.equal 'hi', (SigStream T.str, 'hi')\unwrap T.str - assert.is.equal 'hi', (SigStream T.sym, 'hi')\unwrap T.sym - assert.has_error -> (SigStream T.num, 3.14)\unwrap T.sym - assert.has_error -> (SigStream T.str, 'hi')\unwrap T.num - assert.has_error -> (SigStream T.sym, 'hi')\unwrap T.str - - test 'has __call shorthand', -> - assert.is.equal 3.14, (SigStream T.num, 3.14)! - assert.is.equal 'hi', (SigStream T.str, 'hi')! - assert.is.equal 'hi', (SigStream T.sym, 'hi')! - assert.is.equal 3.14, (SigStream T.num, 3.14) T.num - assert.is.equal 'hi', (SigStream T.str, 'hi') T.str - assert.is.equal 'hi', (SigStream T.sym, 'hi') T.sym - assert.has_error -> (SigStream T.num, 3.14) T.sym - assert.has_error -> (SigStream T.str, 'hi') T.num - assert.has_error -> (SigStream T.sym, 'hi') T.str - - describe 'overrides __eq', -> - it 'compares the type', -> - val = SigStream T.num, 3 - assert.is.equal (SigStream T.num, 3), val - assert.not.equal (SigStream T.str, '3'), val - - val = SigStream T.str, 'hello' - assert.is.equal (SigStream T.str, 'hello'), val - assert.not.equal (SigStream T.sym, 'hello'), val - - it 'compares the value', -> - val = SigStream T.num, 3 - assert.is.equal (SigStream T.num, 3), val - assert.not.equal (SigStream T.num, 4), val - - it 'can be compared to a Constant', -> - val = SigStream T.num, 3 - assert.is.equal (Constant.num 3), val - assert.not.equal (Constant.num 4), val - - val = SigStream T.str, 'hello' - assert.is.equal (Constant.str 'hello'), val - assert.not.equal (Constant.sym 'hello'), val - - describe ':set', -> - it 'sets the value', -> - val = SigStream T.num, 3 - assert.is.equal (SigStream T.num, 3), val - - val\set 4 - assert.is.equal (SigStream T.num, 4), val - assert.not.equal (SigStream T.num, 3), val - - it 'marks the value dirty', -> - val = SigStream T.num, 3 - assert.is.false val\dirty! - - val\set 4 - assert.is.true val\dirty! - - describe ':fork', -> - it 'is equal to the original', -> - a = SigStream T.num, 2 - b = SigStream T.str, 'asdf' - c = with SigStream T.weird, {}, '(raw)' - \set {} - - aa, bb, cc = a\fork!, b\fork!, c\fork! - assert.is.equal a, aa - assert.is.equal b, bb - assert.is.equal c, cc - - assert.is.false aa\dirty! - assert.is.false bb\dirty! - assert.is.true cc\dirty! - - assert.is.equal c.raw, cc.raw - - it 'isolates the original from the fork', -> - a = SigStream T.num, 3 - b = with SigStream T.weird, {}, '(raw)' - \set {} - - aa, bb = a\fork!, b\fork! - - bb\set {false} - - assert.is.same {}, b! - assert.is.same {false}, bb! - assert.is.true b\dirty! - assert.is.true bb\dirty! - - COPILOT\next_tick! - aa\set 4 - - assert.is.equal 3, a! - assert.is.equal 4, aa! - assert.is.false a\dirty! - assert.is.true aa\dirty! |
