flesh/snippets/userlib-tests.rls
Ava Hahn 34e77903a6
Add userlib tests
Document userlib in readme
extend example configuration to include userlib
2023-03-17 13:24:31 -07:00

43 lines
No EOL
1,004 B
Text

;; this file implements unit tests for handwritten userlib functions
(def passed
'prints if a test has passed'
(test)
(echo (concat "PASSED: " test)))
(def failed
'prints if a test has failed'
(test)
(echo (concat "FAILED: " test)))
(def test-cases 'all test cases'
(('set updates var'
(quote
(let ((test-val 0))
(set test-val 3)
(eq? test-val 3))))
('prepend prepends to list'
(quote
(let ((list (2 3 4))
(list (prepend 1 list))
(list-head (head list)))
(eq? (car list-head) 1))))
;; add more test cases here
))
(def test-iter 'iterates over test cases'
(head test-cases))
;; run all test cases, print output
(while (gt? (len (cdr test-iter))
0)
(let ((test (car test-iter))
(remaining (cdr test-iter))
(test-name (car test))
(test-body (cdr test)))
(if (eval test-body)
(passed test-name)
(failed test-name))
(def test-iter '' (head remaining))))