diff options
Diffstat (limited to 'spec/lib/builtins')
| -rw-r--r-- | spec/lib/builtins/fn_spec.moon | 20 |
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 |
