summary refs log tree commit diff
path: root/lib/test.fnl
diff options
context:
space:
mode:
authordozens2024-06-20 09:17:06 -0600
committerdozens2024-06-20 09:17:06 -0600
commitc7b2c982004e350f5e3032321baadfc9021b6bad (patch)
tree3f8883c94bed5a1f847cf60cb11207ca53946c67 /lib/test.fnl
parentce09973e7cacccdc779f91b8e6e48a520b9f9f4d (diff)
🗄️ big tidy up
- isolate core game logic and move it to src/game.fnl
- main.fnl should be just the ui now
- move all table funcs into lib/table
- move all (1) string funcs into lib/string
- move all game funcs into lib/game/
Diffstat (limited to 'lib/test.fnl')
-rw-r--r--lib/test.fnl42
1 files changed, 31 insertions, 11 deletions
diff --git a/lib/test.fnl b/lib/test.fnl
index fbaaf8d..737275f 100644
--- a/lib/test.fnl
+++ b/lib/test.fnl
@@ -1,5 +1,25 @@
-(local {: pprint} (require :lib.tableprint))
-(local {: equal} (require :lib.equal))
+(local {:print pprint} (require :lib.table))
+
+;; thanks:
+;; https://gist.github.com/sapphyrus/fd9aeb871e3ce966cc4b0b969f62f539
+;; and antifennel
+(fn deep-equals [o1 o2 ignore-mt]
+  (when (= o1 o2) (lua "return true"))
+  (local o1-type (type o1))
+  (local o2-type (type o2))
+  (when (not= o1-type o2-type) (lua "return false"))
+  (when (not= o1-type :table) (lua "return false"))
+  (when (not ignore-mt)
+    (local mt1 (getmetatable o1))
+    (when (and mt1 mt1.__eq)
+      (let [___antifnl_rtn_1___ (= o1 o2)] (lua "return ___antifnl_rtn_1___"))))
+  (each [key1 value1 (pairs o1)]
+    (local value2 (. o2 key1))
+    (when (or (= value2 nil) (= (deep-equals value1 value2 ignore-mt) false))
+      (lua "return false")))
+  (each [key2 _ (pairs o2)]
+    (when (= (. o1 key2) nil) (lua "return false")))
+  true)	
 
 (var plan 0)
 
@@ -13,7 +33,7 @@
 
 (fn test [obj]
   (let [{: given : should : actual : expected} obj
-        ok (if (equal actual expected) :ok "not ok")
+        ok (if (deep-equals actual expected) :ok "not ok")
         description (.. "Given " given " should " should)
         ]
     (set plan (+ 1 plan))
@@ -38,15 +58,15 @@
 
 (local print-header (once (fn [] (print "TAP version 14"))))
 
-(fn desc [str cb]
+(fn describe [str cb]
   (print-header)
   (print (.. "#" str))
-  (cb test)
-  )
-(fn end []
-  (print (.. 1 ".." plan))
-  )
+  (cb test))
+
+(fn test-end []
+  (print (.. 1 ".." plan)))
 
 
-{:describe desc
- : end}
+{: describe
+ : deep-equals
+ : test-end}