From 06c239e4f44849a3e4c8317194caacbcc47fc2d4 Mon Sep 17 00:00:00 2001 From: s-ol Date: Sun, 14 Sep 2025 12:12:13 +0200 Subject: de/fn, loop parameter lists use square brackets --- spec/lib/builtins/fn_spec.moon | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'spec/lib/builtins') 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 -- cgit v1.2.3