Initial commit
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 02 Mar 2021 21:42:58 -0500 |
parents |
(none) |
children |
87674bc4c220 |
(ql:quickload '(:1am :losh :alexandria))
(load (compile-file "iacc.lisp"))
(defpackage :iacc/test
(:use :cl :losh)
(:use :iacc))
(in-package :iacc/test)
(defun run (program)
(iacc:compile-program program)
(losh:sh '("make" "prog"))
(string-trim '(#\newline) (losh:sh "./prog" :result-type 'string)))
(defmacro define-test (name &body body)
`(1am:test ,(intern (concatenate 'string (symbol-name 'test-) (symbol-name name)))
(let ((*package* ,*package*))
,@body)))
(defmacro check (program expected)
`(1am:is (string= ,expected (run ,program))))
(define-test fixnums
(check 0 "0")
(check 1 "1")
(check -1 "-1")
(check 10 "10")
(check -10 "-10")
(check 2736 "2736")
(check -2736 "-2736")
(check 536870911 "536870911")
(check -536870912 "-536870912"))
(define-test booleans
(check :true "#t")
(check :false "#f"))
(define-test null
(check nil "()"))
(define-test characters
(check #\a "#\\a")
(check #\A "#\\A")
(check #\space "#\\ "))
(define-test primitives/fxadd1
(check '(fxadd1 0) "1")
(check '(fxadd1 99) "100")
(check '(fxadd1 (fxadd1 202)) "204")
(check '(fxadd1 (fxadd1 -6)) "-4"))
(define-test primitives/fxsub1
(check '(fxsub1 1) "0")
(check '(fxsub1 0) "-1")
(check '(fxsub1 99) "98")
(check '(fxsub1 (fxsub1 202)) "200")
(check '(fxsub1 (fxadd1 -6)) "-6"))
(define-test primitives/char-fixnum-conversion
(check '(char->fixnum #\A) "65")
(check '(fixnum->char 65) "#\\A")
(check '(fixnum->char (fxadd1 (char->fixnum #\A))) "#\\B"))
(define-test primitives/fixnum?
(check '(fixnum? 1) "#t")
(check '(fixnum? 0) "#t")
(check '(fixnum? -1) "#t")
(check '(fixnum? nil) "#f")
(check '(fixnum? :true) "#f")
(check '(fixnum? :false) "#f")
(check '(fixnum? #\A) "#f"))
(define-test primitives/boolean?
(check '(boolean? 1) "#f")
(check '(boolean? 0) "#f")
(check '(boolean? -1) "#f")
(check '(boolean? nil) "#f")
(check '(boolean? :true) "#t")
(check '(boolean? :false) "#t")
(check '(boolean? #\A) "#f"))
(define-test primitives/simple-combos
(check '(boolean? (fixnum? 1)) "#t")
(check '(boolean? (boolean? 1)) "#t")
(check '(fixnum? (char->fixnum #\A)) "#t"))