describe macro supports tests inline in code

convert existing asserts to use it
This commit is contained in:
2024-09-10 22:41:28 +01:00
parent 8ed87c7d53
commit ee4a8d28b6
6 changed files with 55 additions and 12 deletions
+14 -10
View File
@@ -1,7 +1,7 @@
(local { : Gdk } (require :lgi))
(local { : view } (require :fennel))
(local lume (require :lume))
(import-macros {: trace} :macros)
(import-macros {: trace : describe : expect : expect=} :macros)
(local modifier-keyvals
;; we need to detect and discard modifier-only key events when
@@ -73,11 +73,13 @@
(table.insert chars (Gdk.keyval_name keyval))
(table.concat chars "-")))
(let [v (index->string "103:0")] (assert (= v "g") v))
(let [v (index->string "65:0")] (assert (= v "A") v))
(let [v (index->string "120:4")] (assert (= v "C-x") v))
(let [v (index->string "100:8")] (assert (= v "M-d") v))
(let [v (index->string "100:12")] (assert (= v "C-M-d") v))
(describe
index->string
(expect= (index->string "103:0") "g")
(expect= (index->string "65:0") "A")
(expect= (index->string "120:4") "C-x")
(expect= (index->string "100:8") "M-d")
(expect= (index->string "100:12") "C-M-d"))
(fn command? [tbl]
;; a keymap entry has a string as key, a command
@@ -101,10 +103,12 @@
[k1] (. tbl k1)
x tbl)))
(let [v (ref {:a 1} [:a])] (assert (= v 1) v))
(let [v (ref {:a {:c 7}} [:a :c])] (assert (= v 7) v))
(let [v (ref {:a {:c 7}} [:a ])] (assert (match v {:c 7} true) (view v)))
(let [v (ref {:a {:c 7}} [:z :d])] (assert (not v) v))
(describe
ref
(let [v (ref {:a 1} [:a])] (expect= v 1))
(let [v (ref {:a {:c 7}} [:a :c])] (expect= v 7))
(let [v (ref {:a {:c 7}} [:a ])] (expect= v {:c 7}))
(let [v (ref {:a {:c 7}} [:z :d])] (expect (not v))))
(fn recogniser [source-keymap]