-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
47 lines (36 loc) · 1.11 KB
/
test.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
47
import unittest
import logging
from ika.parser import parser
from ika.evaluator import evaluator_maker
from ika.struct import Function
from ika.utils import id
eval_ = evaluator_maker(id)
def e(string):
v = None
for expr in parser(string):
v = eval_(expr)
return v
class InterpreterTestCase(unittest.TestCase):
def log(self, string):
logging.info(string)
def test_lambda(self):
assert isinstance(e('(lambda (a b c) a)'), Function)
def test_apply(self):
assert e('((lambda (x) x) 42)') == 42
assert e('((lambda (a b c) b) 1 2 3)') == 2
assert e('((lambda (a b c) (a b c)) (lambda (a b) a) 42 43)') == 42
assert e('((lambda a a) 1 2 3)')[0] == 1
def test_closure(self):
assert e('(((lambda (x) (lambda () 42)) 42))') == 42
def test_callcc(self):
e('''
(define a 0)
(define b 0)
(set! a (call/cc (lambda (cc) (set! b cc))))
''')
assert e('a') is ()
e('(b 42)')
assert e('a') == 42
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
unittest.main()