From 7c07d6e6ececbf73e18a639e00b3690d4827e12a Mon Sep 17 00:00:00 2001 From: dozens Date: Wed, 29 May 2024 19:26:41 -0600 Subject: tests --- lib/test.fnl | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/test.fnl (limited to 'lib/test.fnl') 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} -- cgit 1.4.1-2-gfad0