aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-05-21 15:36:48 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commit0a568f9a7e7ded43811e1a13189a6c09fcccdbac (patch)
tree1c7483f0c7ae1377158c8c0980093d227672974c /spec
parentadd trigseq to lib/rhythm (diff)
downloadalive-0a568f9a7e7ded43811e1a13189a6c09fcccdbac.tar.gz
alive-0a568f9a7e7ded43811e1a13189a6c09fcccdbac.zip
indexing into types
Diffstat (limited to 'spec')
-rw-r--r--spec/type_spec.moon24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/type_spec.moon b/spec/type_spec.moon
index b6315f1..2ffdb49 100644
--- a/spec/type_spec.moon
+++ b/spec/type_spec.moon
@@ -36,6 +36,11 @@ describe 'Primitive', ->
assert.is.true num\eq a, a
assert.is.false num\eq a, b
+ it ':get errors', ->
+ assert.has.error -> bool\get 'hello'
+ assert.has.error -> bool\get 2
+ assert.has.error -> bool\get!
+
describe 'Array', ->
vec3 = Array 3, num
str32 = Array 2, Array 3, str
@@ -69,6 +74,18 @@ describe 'Array', ->
assert.is.false str32\eq { {'a', 'b', 'c'}, {'d', 'e', 'f'} },
{ {'a', 'b', 'c'}, {'d', 'e', 'g'} }
+ it ':get verifies size range', ->
+ assert.has.error -> vec3\get -1
+ assert.is.equal num, vec3\get 0
+ assert.is.equal num, vec3\get 1
+ assert.is.equal num, vec3\get 2
+ assert.has.error -> vec3\get 3
+
+ assert.is.equal (Array 3, str), str32\get 1
+
+ assert.has.error -> vec3\get!
+ assert.has.error -> vec3\get 'fail'
+
describe 'Struct', ->
play = Struct { note: str, dur: num }
abc = Struct { c: num, b: num, a: num }
@@ -98,6 +115,13 @@ describe 'Struct', ->
assert.is.true play\eq { dur: 0.5, note: c }, { dur: 0.5, note: c }
assert.is.false play\eq { dur: 0.5, note: c }, { dur: 0.5, note: {} }
+ it ':get verifies key exists', ->
+ assert.is.equal str, play\get 'note'
+ assert.is.equal num, play\get 'dur'
+ assert.has.error -> play\get!
+ assert.has.error -> play\get ''
+ assert.has.error -> play\get 'something'
+
describe 'T', ->
it 'provides shorthand for Primitives', ->
assert.is.equal num, T.num