Skip to content
Snippets Groups Projects
Commit 094a99f1 authored by Taddeus Kroes's avatar Taddeus Kroes
Browse files

Added some unit tests for utils.

parent 26727767
No related branches found
No related tags found
No related merge requests found
*.swp *.swp
*.pdf *.pdf
*.pyc
*~ *~
.coverage .coverage
coverage/ coverage/
......
...@@ -51,10 +51,10 @@ class Statement: ...@@ -51,10 +51,10 @@ class Statement:
return self.is_command() \ return self.is_command() \
and re.match('^(add|sub|mult|div|abs|neg)(u|\.d)?$', self.name) 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.""" """Get the jump target of this statement."""
if re.match('^beq|bne|blez|bgtz|bltz|bgez|bct|bcf$', self.name): if self.is_jump():
return self[1] return self[-1]
else: else:
raise Exception('Command "%s" has no jump target' % self.name) raise Exception('Command "%s" has no jump target' % self.name)
...@@ -66,7 +66,7 @@ class Statement: ...@@ -66,7 +66,7 @@ class Statement:
if self.is_load() or self.is_arith(): if self.is_load() or self.is_arith():
return [self[0]] return [self[0]]
def get_use(self, arg): def get_use(self):
"""Get the use[S] of this statement.""" """Get the use[S] of this statement."""
return [] return []
...@@ -157,10 +157,3 @@ def find_basic_blocks(statements): ...@@ -157,10 +157,3 @@ def find_basic_blocks(statements):
blocks.append(Block(statements[leaders[-1]:])) blocks.append(Block(statements[leaders[-1]:]))
return blocks 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): ...@@ -20,3 +20,26 @@ class TestUtils(unittest.TestCase):
self.assertEqual(map(lambda b: b.statements, find_basic_blocks(s)), \ self.assertEqual(map(lambda b: b.statements, find_basic_blocks(s)), \
[B(s[:2]).statements, B(s[2:4]).statements, \ [B(s[:2]).statements, B(s[2:4]).statements, \
B(s[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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment