add test= macro for prettier assertions

This commit is contained in:
Daniel Barlow 2022-09-16 10:27:40 +01:00
parent ff83e03e0c
commit a78cba0a3f
1 changed files with 12 additions and 5 deletions

17
sms.fnl
View File

@ -11,6 +11,15 @@
(local gsm-char (require :unicode-to-gsm))
(macro test= [expr expected]
`(let [a# ,expr
e# ,expected]
(if (not (= a# e#))
(assert false (.. "expected " ,(view expr) " = " e#
", actual " a#)))))
(test= (+ 5 4) 9)
(fn escape-for-logging [s]
(s:gsub "%c" (fn [x] (.. "{" (string.byte x) "}"))))
@ -51,8 +60,8 @@
(let [n (if (even? (# number)) number (.. number "F"))]
(n:gsub ".." (fn [s] (.. (s:sub 2 2) (s:sub 1 1))))))
(assert (= (phone-number->hex "447000123456") "440700214365"))
(assert (= (phone-number->hex "85291234567") "5892214365F7"))
(test= (phone-number->hex "85291234567") "5892214365F7")
(test= (phone-number->hex "447785016005") "447758100650")
(fn mask [start end]
(let [width (+ 1 (- end start))]
@ -123,7 +132,7 @@
;; per worked example at https://www.developershome.com/sms/cmgsCommand4.asp
(assert (= (message->pdu "85291234567" "It is easy to send text messages.") "01000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E"))
(test= (message->pdu "85291234567" "It is easy to send text messages.") "01000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E")
(fn command [fd s]
@ -160,6 +169,4 @@
(tx "\026\r\n")
(expect "OK")))))
;(send-sms "447000123456" "It is never {easy} to [send] text messages.")
{ :send send-sms }