From a2b08f721c28b3b56a802031bc35df6a68b219d8 Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Thu, 31 Dec 2020 09:44:57 +0300 Subject: fix(macros): fix bug in try, add tests --- tests/macros.fnl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/macros.fnl') diff --git a/tests/macros.fnl b/tests/macros.fnl index 9ac9d95..e387eb2 100644 --- a/tests/macros.fnl +++ b/tests/macros.fnl @@ -203,3 +203,35 @@ (let [a [:a 1 :b 2]] (assert-eq (empty a) []) (assert-eq (getmetatable (empty a)) {:cljlib/type :seq})))) + +(deftest try + (testing "try" + (assert-eq (try (+ 1 2 3)) 6) + (assert-eq (try (+ 1 2 3) (catch _ 0) (finally 10)) 6) + (assert-eq (try (+ 1 2 3 nil) (catch _ 0) (finally 10)) 0) + (assert-eq (try (+ 1 2 3 nil) (catch _) (finally 10)) nil)) + (testing "catch-all" + (assert-eq (try + (error 10) + (catch _ :pass)) + :pass) + (assert-eq (try + (error 10) + (catch err err)) + 10)) + (testing "finally" + (let [tbl []] + (try + (try + (finally (table.insert tbl 1))) + (try + (error 10) + (catch _ (table.insert tbl 2)) + (finally (table.insert tbl 3))) + (try + (error 20) + (finally (table.insert tbl 4))) + (catch _ (table.insert tbl 5)) + (catch 20 (table.insert tbl 6)) + (finally (table.insert tbl 7))) + (assert-eq tbl [1 2 3 4 5 7])))) -- cgit v1.2.3