(include "/usr/local/var/mlisp/terminal.lsp")

(defun ut::assert-equal (expected form) (do 
		(define returned (eval form))
		(if (= expected returned)
			(list 1 expected returned)
			(list nil expected returned))
	))

(defun ut::assert-true (test) (ut::assert-equal 1 test))

(defun ut::assert-false (test) (ut::assert-equal nil test))

(defun ut::assert-nil (test) (ut::assert-false test))

(defun ut::define-test (name exp_list)
    (set! ut::tests_list (push ut::tests_list (list name exp_list)))) 

(defun ut::run-tests () (do 
		(define oks 0)
		(define errs 0)
		(for t ut::tests_list
			(define test_name (index t 0)) 
			(define test_result (eval (index t 1))) 
			(if (index test_result 0) 
				(do (set! oks (+ oks 1)) (print (+ (term-green "OK") "  -> " test_name))) 
				(do (set! errs (+ errs 1))  
											(print (+ (term-red "ERR") " -> " test_name))
											(print " " (index test_result 1) " <> " (index test_result 2))
					))
		)
		(if (= errs 0)
			(print (term-green (+ (string oks) " test(s) OK")))
			(print (term-red (+ (string errs) " test(s) FAILED"))))
		))

(define ut::tests_list '())
; TODO (run-test name)


;; example of usage
;; (ut::define-test "its number 2" '(ut::assert-equal 2 (+ 1 1)))
;; (ut::define-test "tis number 3" '(ut::assert-equal 3 (+ 1 1)))
;; (ut::run-tests)
