diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-09-14 10:12:13 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-09-14 15:36:21 +0000 |
| commit | 06c239e4f44849a3e4c8317194caacbcc47fc2d4 (patch) | |
| tree | 491c8c5f9e3ad4351aa55951a0d7c70cd8686087 /spec | |
| parent | expose Tag to Ops (diff) | |
| download | alive-06c239e4f44849a3e4c8317194caacbcc47fc2d4.tar.gz alive-06c239e4f44849a3e4c8317194caacbcc47fc2d4.zip | |
de/fn, loop parameter lists use square brackets
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/lib/array_spec.moon | 23 | ||||
| -rw-r--r-- | spec/lib/builtins/fn_spec.moon | 20 | ||||
| -rw-r--r-- | spec/lib/struct_spec.moon | 9 |
3 files changed, 38 insertions, 14 deletions
diff --git a/spec/lib/array_spec.moon b/spec/lib/array_spec.moon index 130138c..dcad2ad 100644 --- a/spec/lib/array_spec.moon +++ b/spec/lib/array_spec.moon @@ -6,15 +6,20 @@ describe "array", -> svec3 = Array 3, T.str - it "can contain any type", -> - COPILOT\eval_once '[1 2 3]' - COPILOT\eval_once '[true false]' - COPILOT\eval_once '["a"]' - COPILOT\eval_once '[[1 2] [3 4]]' - - it "cannot contain mixed types", -> - err = assert.has.error -> COPILOT\eval_once '[1 false]' - assert.matches "argument error: couldn't match arguments", err + describe "literal", -> + it "can't be empty", -> + err = assert.has.error -> COPILOT\eval_once '[]' + assert.matches "syntax error: array literal can't be empty", err + + it "can contain any type", -> + COPILOT\eval_once '[1 2 3]' + COPILOT\eval_once '[true false]' + COPILOT\eval_once '["a"]' + COPILOT\eval_once '[[1 2] [3 4]]' + + it "cannot contain mixed types", -> + err = assert.has.error -> COPILOT\eval_once '[1 false]' + assert.matches "argument error: couldn't match arguments", err describe "(set)", -> it "can swap values", -> diff --git a/spec/lib/builtins/fn_spec.moon b/spec/lib/builtins/fn_spec.moon index af27cf3..337a427 100644 --- a/spec/lib/builtins/fn_spec.moon +++ b/spec/lib/builtins/fn_spec.moon @@ -8,18 +8,28 @@ describe "function", -> rt = COPILOT\eval_once ' (import* math) - (defn my-plus (a b) + (defn my-plus [a b] (+ a b)) (my-plus 2 3)' assert.is.true rt\is_const! assert.is.equal (Constant.num 5), rt.result + it "can have empty arguments", -> + rt = COPILOT\eval_once ' + (import* math) + + (defn my-plus [] + (+ 1 2)) + + (my-plus)' + assert.is.equal (Constant.num 3), rt.result + it "checks argument arity when invoked", -> err = assert.has.error -> COPILOT\eval_once ' ([1]import* math) - ([2]defn my-plus (a b) + ([2]defn my-plus [a b] ([4]+ a b)) ([3]my-plus 2)' @@ -29,7 +39,7 @@ describe "function", -> err = assert.has.error -> COPILOT\eval_once ' ([1]import* math) - ([2]defn my-plus (a b) + ([2]defn my-plus [a b] ([4]+ a b)) ([3]my-plus 2 3 4)' @@ -39,13 +49,13 @@ describe "function", -> it "can be anonymously invoked", -> rt = COPILOT\eval_once ' ([1] - ([2]fn (a b) b) + ([2]fn [a b] b) 3 4)' assert.is.equal (Constant.num 4), rt\const! err = assert.has.error -> COPILOT\eval_once ' ([1] - ([2]fn (a b) b) + ([2]fn [a b] b) 3)' assert.matches "argument error: expected 2 arguments, found 1", err assert.matches "while invoking function %(unnamed%) at %[1%]", err diff --git a/spec/lib/struct_spec.moon b/spec/lib/struct_spec.moon index 94dcc5a..6f740ec 100644 --- a/spec/lib/struct_spec.moon +++ b/spec/lib/struct_spec.moon @@ -6,6 +6,15 @@ describe "struct", -> ab = Struct { a: T.num, b: T.bool } + describe "literal", -> + it "can't be empty", -> + err = assert.has.error -> COPILOT\eval_once '{}' + assert.matches "syntax error: struct literal can't be empty", err + + it "can't have uneven args", -> + err = assert.has.error -> COPILOT\eval_once '{3}' + assert.matches "syntax error: struct literal must have even number of values", err + describe "(set)", -> it "can update values", -> rt = COPILOT\eval_once '(set {"a" 1 "b" false} "a" 2)' |
