diff python/testpyy.py @ 191:6b2bec5653f1

Added assembler testset
author Windel Bouwman
date Sun, 26 May 2013 15:28:07 +0200
parents 51a6440d6398
children 6cd6260789a1
line wrap: on
line diff
--- a/python/testpyy.py	Sat May 25 15:15:42 2013 +0200
+++ b/python/testpyy.py	Sun May 26 15:28:07 2013 +0200
@@ -1,6 +1,10 @@
 import unittest, pprint
 from pyyacc import Grammar, Item, EOF 
+from ppci import Token
 
+def genTokens(lst):
+    for t in lst:
+        yield Token(t, t, 0)
 
 class testLR(unittest.TestCase):
     def setUp(self):
@@ -18,7 +22,7 @@
         g.add_production('factor', ['identifier'])
         g.start_symbol = 'input'
         # 2. define input:
-        tokens = ['identifier', '+', 'identifier', '+', 'identifier', 'EOF']
+        tokens = genTokens(['identifier', '+', 'identifier', '+', 'identifier'])
         # 3. build parser:
         p = g.genParser()
         # 4. feed input:
@@ -108,14 +112,14 @@
         self.assertIn(Item(p4, 0, '('), s0)
 
     def testParser(self):
-        tokens = ['(', '(', ')', ')', '(', ')', EOF]
+        tokens = ['(', '(', ')', ')', '(', ')']
         # 3. build parser:
         p = self.g.genParser()
         self.assertEqual(len(p.goto_table), 5)
         self.assertEqual(len(p.action_table), 19)
 
         # 4. feed input:
-        p.parse(tokens)
+        p.parse(genTokens(tokens))
 
 if __name__ == '__main__':
     unittest.main()