-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sexpr.py
42 lines (29 loc) · 1.07 KB
/
test_sexpr.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
import unittest
from roots import list
from symbol import *
import sexpr
def interned(L):
return [intern(x) for x in L]
class TestSexpr(unittest.TestCase):
def testsymbol(self):
self.assertEqual(sexpr.str2sexpr('a')[0], Symbol('a'))
def teststring(self):
self.assertEqual(sexpr.str2sexpr('"1"')[0], '1')
def testnum(self):
self.assertEqual(sexpr.str2sexpr('1')[0], 1)
def testfloat(self):
self.assertEqual(sexpr.str2sexpr('0.5')[0], 0.5)
def testescape(self):
self.assertEqual(sexpr.str2sexpr('\\"string\\"')[0], Symbol('"string"'))
def testemptylist(self):
self.assertEqual(sexpr.str2sexpr('()')[0], list())
def testshortlist(self):
self.assertEqual(sexpr.str2sexpr('(1)')[0], list(1))
def testlist(self):
self.assertEqual(sexpr.str2sexpr('(a b c)')[0],
list(Symbol('a'), Symbol('b'), Symbol('c')))
def testfncall(self):
self.assertEqual(sexpr.str2sexpr('((fn (a) a) 1)')[0],
list(list(Symbol('fn'), list(Symbol('a')), Symbol('a')), 1))
if __name__ == '__main__':
unittest.main()