-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_macro.py
46 lines (42 loc) · 1.53 KB
/
test_macro.py
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
import unittest
import visp
import test_visp
class TestMacro(test_visp.TestCase):
def test_simple_macro(self):
self.assertEqual(
visp.evaluate_many(visp.read_many(
"""(defmacro foo (x)
(list '+ '1 '2 x))
(foo 3)"""), self.base_env),
visp.read("6"))
def test_simple_macroexpand(self):
self.assertEqual(
visp.evaluate_many(visp.read_many(
"""(defmacro foo (x)
(list '+ '1 '2 x))
(macroexpand (foo 3))"""), self.base_env),
visp.read("(+ 1 2 3)"))
def test_debug_macro(self):
self.assertEqual(
visp.evaluate_many(visp.read_many(
"""(defmacro debug (a)
(list 'let (list (list 'x a))
(list 'print 'x)
'x))
(debug "hello")"""), self.base_env),
visp.evaluate(visp.read(
"""(let ((x "hello"))
(print x)
x)"""), self.base_env))
def test_debug_macroexpand(self):
self.assertEqual(
visp.evaluate_many(visp.read_many(
"""(defmacro debug (a)
(list 'let (list (list 'x a))
(list 'print 'x)
'x))
(macroexpand (debug "hello"))"""), self.base_env),
visp.read(
"""(let ((x "hello"))
(print x)
x)"""))