tuned the liability of the license.
[muis.git] / muis / test_reader.py
blob65bf63901c983d07a31264b26715eea90724de10
1 #!/usr/bin/env python
2 # Code released under a free software compatible license. See LICENSE for more
3 # details.
4 # Original author: Nido Media
5 # Code patches by:
6 # ...
9 import re
10 import sys
11 import unittest
13 import basic_block
14 import instruction
15 import reader
17 import convenience
19 whitespace = re.compile("^\s*$")
20 entscan = re.compile(".*\.ent.*")
21 endscan = re.compile(".*\.end.*")
23 class testReader(unittest.TestCase):
24 def setUp(self):
25 self.testfile = "../code/basic_file.s"
27 def testReading(self):
28 nonjumping_blocks = 0
29 block_structure = reader.reader(self.testfile)
31 used_labels = []
32 for tuple in block_structure:
33 if tuple[0] == "block":
34 block_list = tuple[2]
36 for block in block_list:
37 self.assertTrue(block.label not in used_labels, "No double labels!")
38 used_labels.append(block.label)
40 self.assertTrue(block.jump, "This block has no jump! Not even a fake one")
42 # only test blocks which have instructions
43 if len(block.instructions) > 0:
44 for line in block.instructions:
45 line = line.regex_match.group()
47 # There shall be no .ent and .end in the code
48 self.assertFalse( entscan.match(line), "Found .ent!")
49 self.assertFalse( endscan.match(line), "Found .end!")
52 if __name__ == '__main__':
53 unittest.main()