summaryrefslogtreecommitdiff
path: root/tests/fn.fnl
diff options
context:
space:
mode:
authorAndrey Listopadov <andreyorst@gmail.com>2021-02-15 21:15:59 +0300
committerAndrey Listopadov <andreyorst@gmail.com>2021-02-15 21:15:59 +0300
commitf3313b3b51c795411a75ec93714110ad1808a8ae (patch)
tree6e272cbd91865d081c9287dc7b4f011705e03a4b /tests/fn.fnl
parent4e1bcfb658f77acc038ba4de00513f0fef4b458b (diff)
fix(macros): correct fn* method definition behavior
fn* now properly defines `self` as its first argument automatically.
Diffstat (limited to 'tests/fn.fnl')
-rw-r--r--tests/fn.fnl16
1 files changed, 12 insertions, 4 deletions
diff --git a/tests/fn.fnl b/tests/fn.fnl
index 40dda8b..5697aab 100644
--- a/tests/fn.fnl
+++ b/tests/fn.fnl
@@ -61,16 +61,24 @@
(testing "fn* methods"
(local ns {:a 1 :b 2})
- (fn* ns:foo [self]
+ (fn* ns:foo []
(+ self.a self.b))
(assert-eq (ns:foo) 3)
(assert-not (pcall #(ns:foo 1)))
(assert-not (pcall #(ns:foo 1 2)))
(fn* ns:bar
- ([self x] (+ self.a x))
- ([self x y] (+ self.b x y)))
+ ([x] (+ self.a x))
+ ([x y] (+ self.b x y)))
(assert-eq (ns:bar -1) 0)
(assert-eq (ns:bar 10 20) 32)
(assert-not (pcall #(ns:bar)))
- (assert-not (pcall #(ns:bar 1 2 3)))))
+ (assert-not (pcall #(ns:bar 1 2 3))))
+
+ (testing "fn* anonymous calls"
+ (assert-eq ((fn* [])) (values))
+ (assert-eq ((fn* [] nil)) nil)
+ (assert-eq ((fn* [x] x) 5) 5)
+ (assert-eq ((fn* [a b c d e] [e d c b a]) 1 2 3 4 5) [5 4 3 2 1])
+ (assert-eq ((fn* ([x] x) ([x y] [y x])) 10) 10)
+ (assert-eq ((fn* ([x] x) ([x y] [y x])) 10 20) [20 10])))