Commit 094a99f1 authored by Taddeus Kroes's avatar Taddeus Kroes

Added some unit tests for utils.

parent 26727767
*.swp
*.pdf
*.pyc
*~
.coverage
coverage/
......
......@@ -51,10 +51,10 @@ class Statement:
return self.is_command() \
and re.match('^(add|sub|mult|div|abs|neg)(u|\.d)?$', self.name)
def jump_target(self, arg):
def jump_target(self):
"""Get the jump target of this statement."""
if re.match('^beq|bne|blez|bgtz|bltz|bgez|bct|bcf$', self.name):
return self[1]
if self.is_jump():
return self[-1]
else:
raise Exception('Command "%s" has no jump target' % self.name)
......@@ -66,7 +66,7 @@ class Statement:
if self.is_load() or self.is_arith():
return [self[0]]
def get_use(self, arg):
def get_use(self):
"""Get the use[S] of this statement."""
return []
......@@ -157,10 +157,3 @@ def find_basic_blocks(statements):
blocks.append(Block(statements[leaders[-1]:]))
return blocks
#while not block.end():
# i, s = block.read()
#
# if block.peek():
# block.replace(i, i + 3, [nieuwe statements])
......@@ -20,3 +20,26 @@ class TestUtils(unittest.TestCase):
self.assertEqual(map(lambda b: b.statements, find_basic_blocks(s)), \
[B(s[:2]).statements, B(s[2:4]).statements, \
B(s[4:]).statements])
def test_eq(self):
self.assertTrue(S('command', 'foo') == S('command', 'foo'))
self.assertFalse(S('command', 'foo') == S('command', 'bar'))
def test_stype(self):
self.assertTrue(S('comment', 'foo', inline=False).is_comment())
self.assertTrue(S('directive', 'foo').is_directive())
self.assertTrue(S('label', 'foo').is_label())
self.assertTrue(S('command', 'foo').is_command())
self.assertFalse(S('command', 'foo').is_comment())
self.assertFalse(S('label', 'foo').is_directive())
self.assertFalse(S('comment', 'foo', inline=False).is_label())
self.assertFalse(S('directive', 'foo').is_command())
def test_is_inline_comment(self):
self.assertTrue(S('comment', 'foo', inline=True).is_inline_comment())
self.assertFalse(S('comment', 'foo', inline=False).is_inline_comment())
def test_jump_target(self):
self.assertEqual(S('command', 'j', 'foo').jump_target(), 'foo')
self.assertRaises(Exception, S('command', 'foo').jump_target)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment