aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib/builtins
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-09-14 10:12:13 +0000
committers-ol <s+removethis@s-ol.nu>2025-09-14 15:36:21 +0000
commit06c239e4f44849a3e4c8317194caacbcc47fc2d4 (patch)
tree491c8c5f9e3ad4351aa55951a0d7c70cd8686087 /spec/lib/builtins
parentexpose Tag to Ops (diff)
downloadalive-06c239e4f44849a3e4c8317194caacbcc47fc2d4.tar.gz
alive-06c239e4f44849a3e4c8317194caacbcc47fc2d4.zip
de/fn, loop parameter lists use square brackets
Diffstat (limited to 'spec/lib/builtins')
-rw-r--r--spec/lib/builtins/fn_spec.moon20
1 files changed, 15 insertions, 5 deletions
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