-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.bot
41 lines (38 loc) · 1.58 KB
/
tests.bot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(define test-results (ref (hashmap)))
(define test-run (lambda () (let (
test (lambda (name fn io-lst)
(do (update! test-results (lambda (v) (assoc v name (reduce
(lambda (acc in out)
(if (equal? (apply fn in) out)
acc
(cons (list in out (apply fn in)) acc)
)) nil (every-other-even io-lst) (every-other-odd io-lst))))
) nil)
))
(do
(; ...tests don't support macros right now... test "docs" docs '((docs) "Built-in macro."))
(test "if" if '((true 1 2) 1 ((< 1 -1) 1 2) 2))
(test "+" + '((1 2 3 4) 10))
(test "-" - '((10 5) 5))
(test "nil?" nil? '((()) true ((3)) false))
(test "car" car '(((1)) 1))
(test "cdr" cdr '(((1 2)) (2)))
(test "cons" cons '((1 (2 3)) (1 2 3)))
(test "list" list '((1 2) (1 2)))
(test "identity" identity '((1) 1 (nil) nil))
(test "string" string (list (list (identity string)) "[Native Function]"))
(; test "Should Fail" identity '((1) 2 (2) 1))
)
)))
(test-run)
(define test-print (lambda (verbose)
(if (and (not verbose) (nil? (filter (lambda (v) (not (nil? (second v)))) ((get test-results)))))
"All tests passed."
(join (cdr (split (join (map (lambda (test)
(if (or verbose (not (nil? (second test)))) (join (list "\n" (car test) ": "
(if (nil? (second test)) "Passed" (join (cons "Failed"
(map (lambda (v) (join (list "\n In:" (string (car v)) " Expected:" (string (second v)) " Received:" (string (nth v 2))) "")) (second test))) ""))
) "") "")
) ((get test-results))) "") "\n")) "\n")
)
))