summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrey Listopadov <andreyorst@gmail.com>2021-07-13 05:42:37 +0000
committerAndrey Listopadov <andreyorst@gmail.com>2021-07-13 05:42:37 +0000
commite8351c4a47ea0472151b3f5a5ac06a70f86f0d02 (patch)
treeca1b8b870eeee9d1ffe13cf2cd65d6da0c17e2fd /tests
parente1bafba9201e818d7aa3a51d8dd30654c55c7ff3 (diff)
parentf9fb932e6c1f5b916162fb5a50907a1fada646f3 (diff)
Merge branch 'loop-macro' into 'master'
FEATURE: Added Clojure-like loop macro! See merge request andreyorst/fennel-cljlib!12
Diffstat (limited to 'tests')
-rw-r--r--tests/macros.fnl18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/macros.fnl b/tests/macros.fnl
index bef0390..cf5c09b 100644
--- a/tests/macros.fnl
+++ b/tests/macros.fnl
@@ -247,3 +247,21 @@
(assert-eq 3 (select :# (try (values 1 2 3))))
(assert-eq [1 2 3] [(try (values 1 2 3))])
(assert-eq 6 (select :# (try (values 1 nil 3 nil nil nil))))))
+
+(deftest loop
+ (testing "loop macro"
+ (assert-eq
+ (loop [[first & rest] [1 2 3 4 5]
+ acc 0]
+ (if (= nil first)
+ acc
+ (recur rest (+ acc first))))
+ 15)
+
+ (assert-eq
+ (loop [a 2
+ b (+ a 3)]
+ (if (= b 5)
+ (recur a (+ 1 b))
+ b))
+ 6)))