-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtests.py
80 lines (52 loc) · 2.42 KB
/
tests.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
76
77
78
79
80
import unittest
from tokens import IDENT, QIDENT, STRING, UNSIGNED_INTEGER, UNSIGNED_NUMBER
from base import IncorrectValue, ParseError
class testTokensLoad(unittest.TestCase):
def setUp(self):
pass
def test_ident(self):
self.assertTrue(IDENT.load("algo").value == "algo")
self.assertTrue(IDENT.load("Algo").value == "Algo")
self.assertTrue(IDENT.load("_algo").value == "_algo")
self.assertTrue(IDENT.load(" _algo ").value == "_algo")
self.assertTrue(IDENT.load(" 'algo' ").value == QIDENT("algo"))
self.assertRaises(ParseError, lambda: IDENT.load("1algo"))
def test_qident(self):
self.assertTrue(IDENT.load("'algoas'").value == QIDENT("algoas"))
def test_string(self):
self.assertTrue(STRING.load(""" "algo" """).value == "algo")
self.assertTrue(STRING.load(""" "algo y algo" """).value == "algo y algo")
self.assertTrue(STRING.load(""" "algo es \\"algo\\"" """).value == '''algo es \\"algo\\"''')
self.assertTrue(STRING.load(""" "algo es \\"algo\\"" """).unescape() == '''algo es "algo"''')
def test_integer(self):
self.assertTrue(UNSIGNED_INTEGER.load(" 123 ").value == 123)
def test_number(self):
self.assertEqual(UNSIGNED_NUMBER.load(" 12e-12").dump(), "12e-12")
self.assertEqual(UNSIGNED_NUMBER.load(" 12E+12").dump(), "12e12")
def test_expression(self):
pass
def test_equation(self):
pass
class testTokens(unittest.TestCase):
def setUp(self):
pass
def test_ident(self):
self.assertTrue(isinstance(IDENT("algo"), IDENT))
self.assertTrue(isinstance(IDENT("_algo"), IDENT))
self.assertTrue(isinstance(IDENT("Algo"), IDENT))
self.assertRaises(Exception, lambda: IDENT(" algo asi "))
def test_qident(self):
self.assertTrue(isinstance(QIDENT("'algo'"), QIDENT))
self.assertTrue(isinstance(QIDENT("'_algo'"), QIDENT))
self.assertTrue(isinstance(QIDENT("'Algo'"), QIDENT))
class testTokensDumps(unittest.TestCase):
def setUp(self):
pass
def test_ident(self):
self.assertEqual(IDENT("algo").dump(), "algo")
def test_string(self):
self.assertEqual(STRING("algo y algo").dump(), '''"algo y algo"''')
def test_integer(self):
self.assertEqual(UNSIGNED_INTEGER("12").dump(), '''12''')
if __name__ == '__main__':
unittest.main()