aboutsummaryrefslogtreecommitdiffstats
path: root/spec/type_spec.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-05-08 10:23:03 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:23:21 +0000
commitbb0dcb9e55ac39341be4021be35b019a475a8126 (patch)
tree55c78a815e3e72b089b24a1434b11009d6db1ab5 /spec/type_spec.moon
parentwip new type system and refactoring (diff)
downloadalive-bb0dcb9e55ac39341be4021be35b019a475a8126.tar.gz
alive-bb0dcb9e55ac39341be4021be35b019a475a8126.zip
add alv.type and spec
Diffstat (limited to 'spec/type_spec.moon')
-rw-r--r--spec/type_spec.moon45
1 files changed, 45 insertions, 0 deletions
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 }