-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.lisp
90 lines (69 loc) · 2.21 KB
/
tests.lisp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(in-package #:cl-user)
(defpackage #:defmacro-enhance-tests
(:use #:cl #:defmacro-enhance #:eos)
(:export #:run-tests))
(in-package #:defmacro-enhance-tests)
(def-suite defmacro-enhance)
(in-suite defmacro-enhance)
(defun run-tests ()
(let ((results (run 'defmacro-enhance)))
(eos:explain! results)
(unless (eos:results-status results)
(error "Tests failed."))))
;; Tests are not direct but rather indirect
(defmacro! aif (test then &optional else)
`(let ((,e!-it ,test))
(if ,e!-it
,then
,else)))
(test externalization
(is (equal 3 (aif (+ 1 2) 3 6)))
(is (equal 3 (macrolet! ((my-aif (test then &optional else)
`(let ((,e!-it ,test))
(if ,e!-it
,then
,else))))
(my-aif (+ 1 2)
3
6))))
)
(defmacro! square (o!-x)
`(* ,o!-x ,o!-x))
(test once-only
(is (equal '(1 1) (let ((x 0))
`(,(square (incf x)) ,x)))))
(defmacro! foo (a b &sample (1 2))
`(+ ,a ,b))
(test sampling
(is (equal '(+ 1 2)
(testing-expansion foo))))
(defmacro! autoflat-progn-list (&rest p!-args)
`(list ,@p!-args))
(defmacro sample-progning-macro ()
`(progn 1 2))
(defmacro! with-environment (&rest p!-args &environment env)
"DEFMACRO! just to test that &ENVIRONMENT is handled correctly."
(declare (ignorable env))
`(list ,@p!-args))
(test auto-progning
(is (equal '(list 1 2)
(macroexpand-1 '(autoflat-progn-list (progn (progn 1) 2)))))
(is (equal '(list 1 (s (progn 2)))
(macroexpand-1 '(autoflat-progn-list (progn (progn 1) (s (progn 2)))))))
(is (equal '(list 1 1 2 2)
(macroexpand-1 '(autoflat-progn-list 1 (sample-progning-macro) 2))))
(is (equal '(1 1 2 2)
(macrolet ((sample-progning-macrolet ()
`(progn 1 2)))
(autoflat-progn-list 1 (sample-progning-macrolet) 2)))))
(defpackage #:defmacro-enhance-tests-internal
(:use #:cl #:defmacro-enhance)
(:export #:foo))
(in-package defmacro-enhance-tests-internal)
(defmacro! foo (str)
(list (intern-def (string-upcase str))
(intern (string-upcase str))))
(in-package defmacro-enhance-tests)
(test intern-def
(let ((it (macroexpand-1 '(defmacro-enhance-tests-internal:foo "asdf"))))
(is (equal '(defmacro-enhance-tests-internal::asdf asdf) it))))