-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_read.py
75 lines (61 loc) · 2.02 KB
/
test_read.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
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
import unittest
import visp
class TestRead(unittest.TestCase):
def test_integer(self):
self.assertEqual(
visp.read("1"),
1)
def test_symbol(self):
self.assertEqual(
visp.read("hello!").name,
'hello!')
def test_nil(self):
self.assertEqual(
visp.read("()"),
visp.nil)
def test_dotted(self):
self.assertEqual(
visp.read("(1 . hello)").cdr.name,
'hello')
self.assertEqual(
visp.read("(1 . hello)").car,
1)
def test_nested(self):
self.assertEqual(
visp.read("((1 . 2) . (3 . 4))"),
visp.cons(visp.cons(1, 2), visp.cons(3, 4)))
def test_list_of_pairs(self):
self.assertEqual(
visp.read("((1 . 2) (3 . 4) (5 . 6))"),
visp.cons(visp.cons(1, 2),
visp.cons(visp.cons(3, 4),
visp.cons(visp.cons(5, 6), visp.nil))))
def test_integers(self):
self.assertEqual(
visp.read("(1 2 3)"),
visp.cons(1, visp.cons(2, visp.cons(3, visp.nil))))
def test_integers_dot_nil(self):
self.assertEqual(
visp.read("(1 2 3 . ())"),
visp.cons(1, visp.cons(2, visp.cons(3, visp.nil))))
def test_quote(self):
self.assertEqual(
visp.read("'(1 2 3)"),
visp.read("(quote (1 2 3))"))
def test_exact(self):
self.assertEqual(
visp.read("#e100"),
visp.read('(exact-number 100)'))
def test_inexact(self):
self.assertEqual(
visp.read("#i100"),
visp.read('(inexact-number 100)'))
def test_unexpected_token(self):
with self.assertRaises(RuntimeError):
visp.read(")")
def test_unexpected_readermacro(self):
with self.assertRaises(RuntimeError):
visp.read("#oblong")
def test_unmet_token_requirement(self):
with self.assertRaises(StopIteration):
visp.read("(1 2")