diff options
author | dozens | 2024-05-29 19:26:41 -0600 |
---|---|---|
committer | dozens | 2024-06-02 21:44:17 -0600 |
commit | 7c07d6e6ececbf73e18a639e00b3690d4827e12a (patch) | |
tree | 7d948da1b634d100feb32215dd5d263c5b01ab8b /lib/test.fnl | |
parent | f265d24c0cacb92c7f7db19f364a155d87938184 (diff) |
tests
Diffstat (limited to 'lib/test.fnl')
-rw-r--r-- | lib/test.fnl | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/test.fnl b/lib/test.fnl new file mode 100644 index 0000000..fbaaf8d --- /dev/null +++ b/lib/test.fnl @@ -0,0 +1,52 @@ +(local {: pprint} (require :lib.tableprint)) +(local {: equal} (require :lib.equal)) + +(var plan 0) + +(fn once [funky] + (var bang false) + (fn [...] + (if (not bang) + (do + (funky ...) + (set bang true))))) + +(fn test [obj] + (let [{: given : should : actual : expected} obj + ok (if (equal actual expected) :ok "not ok") + description (.. "Given " given " should " should) + ] + (set plan (+ 1 plan)) + (print (.. ok " " plan " - " description)) + (if (= "not ok" ok) + (do + (print " ---") + (if (= :table (type expected)) + (do + (print (.. " expected: " )) + (pprint expected)) + (print (.. " expected: " (tostring expected)))) + (if (= :table (type actual)) + (do + (print (.. " actual: " )) + (pprint actual)) + (print (.. " actual: " (tostring actual)))) + (print " ...") + ) + ) + )) + +(local print-header (once (fn [] (print "TAP version 14")))) + +(fn desc [str cb] + (print-header) + (print (.. "#" str)) + (cb test) + ) +(fn end [] + (print (.. 1 ".." plan)) + ) + + +{:describe desc + : end} |