From 6afecae50e4faafafbde8dae6bf8f534b8b7f1da Mon Sep 17 00:00:00 2001 From: s-ol Date: Fri, 8 May 2020 12:23:03 +0200 Subject: add alv.type and spec --- spec/input_spec.moon | 7 ++++--- spec/match_spec.moon | 3 +-- spec/result/const_spec.moon | 3 +-- spec/result/sig_spec.moon | 3 +-- spec/rtnode_spec.moon | 3 +-- spec/scope_spec.moon | 3 +-- spec/type_spec.moon | 45 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 spec/type_spec.moon (limited to 'spec') diff --git a/spec/input_spec.moon b/spec/input_spec.moon index a8107ae..371a3ee 100644 --- a/spec/input_spec.moon +++ b/spec/input_spec.moon @@ -1,8 +1,9 @@ -import do_setup from require 'spec.test_setup' -import Input, Result, SigStream, EvtStream, IOStream from require 'alv.base' -import Primitive from require 'alv.types' +import do_setup, do_teardown from require 'spec.test_setup' +import Input, Primitive, Result, SigStream, EvtStream, IOStream + from require 'alv.base' setup do_setup +teardown do_teardown my_io = Primitive 'my-io' diff --git a/spec/match_spec.moon b/spec/match_spec.moon index 91cee02..e3483e3 100644 --- a/spec/match_spec.moon +++ b/spec/match_spec.moon @@ -1,6 +1,5 @@ import val, evt from require 'alv.base.match' -import RTNode, SigStream, EvtStream from require 'alv' -import Primitive from require 'alv.types' +import RTNode, Primitive, SigStream, EvtStream from require 'alv' mk_val = (type, const) -> value = SigStream Primitive type diff --git a/spec/result/const_spec.moon b/spec/result/const_spec.moon index 6bd7999..55d5175 100644 --- a/spec/result/const_spec.moon +++ b/spec/result/const_spec.moon @@ -1,7 +1,6 @@ import do_setup from require 'spec.test_setup' -import Constant, RTNode, Scope, SimpleRegistry from require 'alv' +import Constant, RTNode, Scope, SimpleRegistry, Primitive from require 'alv' import Op, Builtin from require 'alv.base' -import Primitive from require 'alv.types' class TestOp extends Op new: (...) => super ... diff --git a/spec/result/sig_spec.moon b/spec/result/sig_spec.moon index 4bc0a67..93a9eb4 100644 --- a/spec/result/sig_spec.moon +++ b/spec/result/sig_spec.moon @@ -1,7 +1,6 @@ import do_setup from require 'spec.test_setup' -import SigStream, RTNode, Scope, SimpleRegistry from require 'alv' +import SigStream, RTNode, Scope, SimpleRegistry, Primitive from require 'alv' import Op, Builtin from require 'alv.base' -import Primitive from require 'alv.types' class TestOp extends Op new: (...) => super ... diff --git a/spec/rtnode_spec.moon b/spec/rtnode_spec.moon index c4cf4e9..a842a74 100644 --- a/spec/rtnode_spec.moon +++ b/spec/rtnode_spec.moon @@ -1,7 +1,6 @@ import do_setup from require 'spec.test_setup' import RTNode, Scope, SimpleRegistry from require 'alv' -import Input, Op, Constant, EvtStream, IOStream from require 'alv.base' -import Primitive from require 'alv.types' +import Primitive, Input, Op, Constant, EvtStream, IOStream from require 'alv.base' setup do_setup num = Primitive 'num' diff --git a/spec/scope_spec.moon b/spec/scope_spec.moon index 405e9f8..4798391 100644 --- a/spec/scope_spec.moon +++ b/spec/scope_spec.moon @@ -1,5 +1,4 @@ -import Scope, Constant, RTNode from require 'alv' -import Primitive from require 'alv.types' +import Scope, Primitive, Constant, RTNode from require 'alv' import Op from require 'alv.base' import Logger from require 'alv.logger' Logger\init 'silent' diff --git a/spec/type_spec.moon b/spec/type_spec.moon new file mode 100644 index 0000000..14d7894 --- /dev/null +++ b/spec/type_spec.moon @@ -0,0 +1,45 @@ +require 'spec.test_setup' +import Primitive, Array, Struct from require 'alv' + +bool = Primitive 'bool' +num = Primitive 'num' +str = Primitive 'str' + +describe 'Primitive', -> + it 'stringifies well', -> + assert.is.equal 'bool', tostring bool + assert.is.equal 'num', tostring num + assert.is.equal 'str', tostring str + + it 'implements __eq sensibly', -> + assert.is.equal (Primitive 'bool'), bool + assert.is.equal (Primitive 'num'), num + assert.is.equal (Primitive 'str'), str + assert.not.equal num, bool + assert.not.equal str, num + +describe 'Array', -> + vec3 = Array 3, num + + it 'stringifies well', -> + assert.is.equal 'num[3]', tostring vec3 + assert.is.equal 'my-type[3][24]', tostring Array 24, Array 3, 'my-type' + + it 'implements __eq sensibly', -> + assert.is.equal vec3, Array 3, num + assert.not.equal vec3, Array 2, num + assert.not.equal vec3, Array 3, str + +describe 'Struct', -> + play = Struct { note: str, dur: num } + abc = Struct { c: num, b: num, a: num } + + it 'stringifies well', -> + assert.is.equal '{dur: num, note: str}', tostring play + assert.is.equal '{a: num, b: num, c: num}', tostring abc + + it 'implements __eq sensibly', -> + assert.is.equal play, Struct { note: str, dur: num } + assert.not.equal play, Struct { note: str } + assert.not.equal play, Struct { note: str, dur: str } + assert.not.equal play, Struct { note: str, dur: num, extra: num } -- cgit v1.2.3