diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-05-09 14:49:08 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-02 14:23:21 +0000 |
| commit | 61eb86951287667ca0ee305baa5c3cd6ad29ba36 (patch) | |
| tree | 7551d6b9c8af01c049adab0ee027dbad68f28808 /spec/result | |
| parent | more internal doc fixes (diff) | |
| download | alive-61eb86951287667ca0ee305baa5c3cd6ad29ba36.tar.gz alive-61eb86951287667ca0ee305baa5c3cd6ad29ba36.zip | |
add types.T, fix spec + docs
Diffstat (limited to 'spec/result')
| -rw-r--r-- | spec/result/const_spec.moon | 45 | ||||
| -rw-r--r-- | spec/result/sig_spec.moon | 76 |
2 files changed, 63 insertions, 58 deletions
diff --git a/spec/result/const_spec.moon b/spec/result/const_spec.moon index dfcdafa..a6ab43e 100644 --- a/spec/result/const_spec.moon +++ b/spec/result/const_spec.moon @@ -1,5 +1,5 @@ import do_setup from require 'spec.test_setup' -import Constant, RTNode, Scope, SimpleRegistry, Primitive from require 'alv' +import Constant, RTNode, Scope, SimpleRegistry, T from require 'alv' import Op, Builtin from require 'alv.base' class TestOp extends Op @@ -11,15 +11,20 @@ class TestBuiltin extends Builtin 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 + describe '.wrap', -> it 'wraps numbers', -> got = Constant.wrap 3 - assert.is.equal Primitive.num, got.type + 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 Primitive.str, got.type + assert.is.equal T.str, got.type assert.is.equal "im a happy string", got.value it 'wraps Constants', -> @@ -31,27 +36,27 @@ describe 'Constant', -> it 'wraps Opdefs', -> got = Constant.wrap TestOp - assert.is.equal Primitive.op, got.type + assert.is.equal T.opdef, got.type assert.is.equal TestOp, got.value it 'wraps Bultins', -> got = Constant.wrap TestBuiltin - assert.is.equal Primitive.builtin, got.type + 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 Primitive.scope, got.type + 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 Primitive.scope, got.type + assert.is.equal T.scope, got.type assert.is.equal pi, (got.value\get 'pi')\const! describe ':unwrap', -> @@ -61,23 +66,23 @@ describe 'Constant', -> assert.is.equal 'hi', (Constant.sym 'hi')\unwrap! test 'can assert the type', -> - assert.is.equal 3.14, (Constant.num 3.14)\unwrap Primitive.num - assert.is.equal 'hi', (Constant.str 'hi')\unwrap Primitive.str - assert.is.equal 'hi', (Constant.sym 'hi')\unwrap Primitive.sym - assert.has_error -> (Constant.num 3.14)\unwrap Primitive.sym - assert.has_error -> (Constant.str 'hi')\unwrap Primitive.num - assert.has_error -> (Constant.sym 'hi')\unwrap Primitive.str + 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) Primitive.num - assert.is.equal 'hi', (Constant.str 'hi') Primitive.str - assert.is.equal 'hi', (Constant.sym 'hi') Primitive.sym - assert.has_error -> (Constant.num 3.14) Primitive.sym - assert.has_error -> (Constant.str 'hi') Primitive.num - assert.has_error -> (Constant.sym 'hi') Primitive.str + 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', -> @@ -134,7 +139,7 @@ describe 'Constant', -> it 'is equal to the original', -> a = Constant.num 2 b = Constant.str 'asdf' - c = Constant (Primitive 'weird'), {}, '(raw)' + c = Constant T.weird, {}, '(raw)' aa, bb, cc = a\fork!, b\fork!, c\fork! assert.is.equal a, aa diff --git a/spec/result/sig_spec.moon b/spec/result/sig_spec.moon index 93a9eb4..4d04b9c 100644 --- a/spec/result/sig_spec.moon +++ b/spec/result/sig_spec.moon @@ -1,5 +1,5 @@ import do_setup from require 'spec.test_setup' -import SigStream, RTNode, Scope, SimpleRegistry, Primitive from require 'alv' +import SigStream, RTNode, Scope, SimpleRegistry, T from require 'alv' import Op, Builtin from require 'alv.base' class TestOp extends Op @@ -13,55 +13,55 @@ setup do_setup describe 'SigStream', -> describe ':unwrap', -> it 'returns the raw value!', -> - assert.is.equal 3.14, (SigStream.num 3.14)\unwrap! - assert.is.equal 'hi', (SigStream.str 'hi')\unwrap! - assert.is.equal 'hi', (SigStream.sym 'hi')\unwrap! + 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.num 3.14)\unwrap Primitive 'num' - assert.is.equal 'hi', (SigStream.str 'hi')\unwrap Primitive 'str' - assert.is.equal 'hi', (SigStream.sym 'hi')\unwrap Primitive 'sym' - assert.has_error -> (SigStream.num 3.14)\unwrap Primitive 'sym' - assert.has_error -> (SigStream.str 'hi')\unwrap Primitive 'num' - assert.has_error -> (SigStream.sym 'hi')\unwrap Primitive 'str' + 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.num 3.14)! - assert.is.equal 'hi', (SigStream.str 'hi')! - assert.is.equal 'hi', (SigStream.sym 'hi')! - assert.is.equal 3.14, (SigStream.num 3.14) Primitive 'num' - assert.is.equal 'hi', (SigStream.str 'hi') Primitive 'str' - assert.is.equal 'hi', (SigStream.sym 'hi') Primitive 'sym' - assert.has_error -> (SigStream.num 3.14) Primitive 'sym' - assert.has_error -> (SigStream.str 'hi') Primitive 'num' - assert.has_error -> (SigStream.sym 'hi') Primitive 'str' + 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.num 3 - assert.is.equal (SigStream.num 3), val - assert.not.equal (SigStream.str '3'), val + val = SigStream T.num, 3 + assert.is.equal (SigStream T.num, 3), val + assert.not.equal (SigStream T.str, '3'), val - val = SigStream.str 'hello' - assert.is.equal (SigStream.str 'hello'), val - assert.not.equal (SigStream.sym 'hello'), 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.num 3 - assert.is.equal (SigStream.num 3), val - assert.not.equal (SigStream.num 4), val + val = SigStream T.num, 3 + assert.is.equal (SigStream T.num, 3), val + assert.not.equal (SigStream T.num, 4), val describe ':set', -> it 'sets the value', -> - val = SigStream.num 3 - assert.is.equal (SigStream.num 3), val + val = SigStream T.num, 3 + assert.is.equal (SigStream T.num, 3), val val\set 4 - assert.is.equal (SigStream.num 4), val - assert.not.equal (SigStream.num 3), val + assert.is.equal (SigStream T.num, 4), val + assert.not.equal (SigStream T.num, 3), val it 'marks the value dirty', -> - val = SigStream.num 3 + val = SigStream T.num, 3 assert.is.false val\dirty! val\set 4 @@ -69,9 +69,9 @@ describe 'SigStream', -> describe ':fork', -> it 'is equal to the original', -> - a = SigStream.num 2 - b = SigStream.str 'asdf' - c = with SigStream 'weird', {}, '(raw)' + 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! @@ -86,8 +86,8 @@ describe 'SigStream', -> assert.is.equal c.raw, cc.raw it 'isolates the original from the fork', -> - a = SigStream.num 3 - b = with SigStream 'weird', {}, '(raw)' + a = SigStream T.num, 3 + b = with SigStream T.weird, {}, '(raw)' \set {} aa, bb = a\fork!, b\fork! |
