diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-10-25 20:45:42 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-10-25 20:45:42 +0300 |
| commit | f696a71b13d6867bf7168e6314eeaa8663b30e92 (patch) | |
| tree | 3a3793653babbab24a413a374366c84bcf3bc0e3 /test.fnl | |
| parent | 7f6c6a600ec8652bf64d4b343c8d920d71d464c2 (diff) | |
feature: refactoring
Diffstat (limited to 'test.fnl')
| -rw-r--r-- | test.fnl | 21 |
1 files changed, 5 insertions, 16 deletions
@@ -1,10 +1,9 @@ (import-macros {: fn*} :macros.fn) - ;; requires `eq?' from core.fnl to be available at runtime (fn* assert-eq ([expr1 expr2] - (assert-eq expr1 expr2 'nil)) + (assert-eq expr1 expr2 nil)) ([expr1 expr2 msg] `(let [left# ,expr1 right# ,expr2 @@ -15,7 +14,7 @@ (fn* assert-ne ([expr1 expr2] - (assert-ne expr1 expr2 'nil)) + (assert-ne expr1 expr2 nil)) ([expr1 expr2 msg] `(let [left# ,expr1 right# ,expr2 @@ -24,29 +23,19 @@ Left: " (view# left#) " Right: " (view# right#) "\n")))))) -(fn walk-tree [root f custom-iterator] - "Walks a tree (like the AST), invoking f(node, idx, parent) on each node. -When f returns a truthy value, recursively walks the children." - (fn walk [iterfn parent idx node] - (when (f idx node parent) - (each [k v (iterfn node)] - (walk iterfn node k v)))) - (walk (or custom-iterator pairs) nil nil root) - root) - (fn* assert* ([expr] - (assert* expr 'nil)) + (assert* expr nil)) ([expr msg] `(assert ,expr (.. "assertion failed for " (or ,msg ,(tostring expr)))))) (fn* test - ;"define test function, print its name and run it." + "Define test function, print its name and run it." [name docstring & body] (let [test-name (sym (.. (tostring name) "-test"))] `(do (fn ,test-name [] ,(or docstring nil) - ((or table.unpack unpack) ,body)) + ,((or table.unpack _G.unpack) body)) (io.stderr:write (.. "running: " ,(tostring test-name) "\n")) (,test-name)))) |