-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exception if function called with wrong arity (#101)
- Loading branch information
1 parent
78cf16c
commit dd73889
Showing
5 changed files
with
127 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
(ns axel-f.arity-test | ||
(:require #?(:clj [clojure.test :as t] | ||
:cljs [cljs.test :as t :include-macros true]) | ||
[axel-f.excel :as af]) | ||
#?(:clj (:import [clojure.lang ExceptionInfo]))) | ||
|
||
(defn foo-1 [_x _y & _z]) | ||
|
||
(defn foo-2 [_x _y]) | ||
|
||
(t/deftest stdlib | ||
|
||
(t/testing "variadic args" | ||
|
||
(let [f (af/compile "FOO(1,2,3)" {"FOO" #'foo-1})] | ||
(t/is (nil? (f)))) | ||
|
||
(let [f (af/compile "FOO(1)" {"FOO" #'foo-1})] | ||
(t/is | ||
(thrown-with-msg? | ||
ExceptionInfo | ||
#"Wrong number of arguments passed to a function foo-1" | ||
(f))))) | ||
|
||
(t/testing "fixed args" | ||
|
||
(let [f (af/compile "FOO(1)" {"FOO" #'foo-2})] | ||
(t/is | ||
(thrown? | ||
ExceptionInfo | ||
(f)))) | ||
|
||
(let [f (af/compile "FOO(1,2,3,4)" {"FOO" #'foo-2})] | ||
(t/is | ||
(thrown? | ||
ExceptionInfo | ||
(f))))) | ||
|
||
(t/testing "lambda" | ||
|
||
(let [f (af/compile "WITH(FOO, FN(x,y,1), FOO(1))")] | ||
(t/is | ||
(thrown? | ||
ExceptionInfo | ||
(f)))) | ||
|
||
(let [f (af/compile "WITH(FOO, FN(x,y,1), FOO(1,2,3,4))")] | ||
(t/is | ||
(thrown? | ||
ExceptionInfo | ||
(f))))) | ||
|
||
#?(:clj | ||
(t/testing "no meta" | ||
|
||
(let [f (af/compile "FOO(1,2)" {"FOO" (fn [_x])})] | ||
(t/is | ||
(thrown-with-msg? | ||
ExceptionInfo | ||
#"Error during function call" | ||
(f)))))) | ||
|
||
(t/testing "no function" | ||
|
||
(let [f (af/compile "FOO(1,2)")] | ||
(t/is | ||
(thrown-with-msg? | ||
ExceptionInfo | ||
#"Unknown function FOO" | ||
(f)))))) |