Skip to content
Snippets Groups Projects
Commit c5a80c31 authored by Jayke Meijer's avatar Jayke Meijer
Browse files

Added unit tests for writer.

parent 191e1bf2
No related branches found
No related tags found
No related merge requests found
import unittest
from src.writer import write_statements
from src.statement import Statement as S, Block as B
class TestWriter(unittest.TestCase):
def setUp(self):
self.foo = S('command', 'move', '$regA', '$regB')
self.bar = S('command', 'addu', '$regC', '$regA', '$regB')
def tearDown(self):
del self.foo
del self.bar
def test_writer_one(self):
output = write_statements([self.foo])
expect = "\tmove\t$regA,$regB\n"
self.assertEqual(output, expect)
def test_writer_longname(self):
command = S('command', 'movemovemove', '$regA', '$regB')
output = write_statements([command])
expect = "\tmovemovemove $regA,$regB\n"
self.assertEqual(output, expect)
def test_writer_several(self):
output = write_statements([self.foo, self.bar, self.foo])
expect = "\tmove\t$regA,$regB\n" \
+ "\taddu\t$regC,$regA,$regB\n" \
+ "\tmove\t$regA,$regB\n"
self.assertEqual(output, expect)
def test_writer_with_label(self):
label = S('label', '$L1')
output = write_statements([self.foo, label, self.bar])
expect = "\tmove\t$regA,$regB\n" \
+ "$L1:\n" \
+ "\taddu\t$regC,$regA,$regB\n"
self.assertEqual(output, expect)
def test_writer_with_comment(self):
comment = S('comment', 'tralala')
output = write_statements([self.foo, comment, self.bar])
expect = "\tmove\t$regA,$regB\n" \
+ "\n#tralala\n\n" \
+ "\taddu\t$regC,$regA,$regB\n"
self.assertEqual(output, expect)
def test_writer_with_comment_non_tabbed(self):
directive = S('comment', 'tralala')
output = write_statements([directive, self.foo, self.bar])
expect = "\n#tralala\n\n" \
+ "\tmove\t$regA,$regB\n" \
+ "\taddu\t$regC,$regA,$regB\n"
self.assertEqual(output, expect)
def test_writer_with_inlinecomment(self):
self.foo.options['comment'] = 'tralala'
output = write_statements([self.foo, self.bar])
expect = "\tmove\t$regA,$regB" \
+ "\t\t#tralala\n" \
+ "\taddu\t$regC,$regA,$regB\n"
self.assertEqual(output, expect)
def test_writer_with_directive(self):
directive = S('directive', '.tralala trololo')
output = write_statements([self.foo, directive, self.bar])
expect = "\tmove\t$regA,$regB\n" \
+ "\t.tralala trololo\n" \
+ "\taddu\t$regC,$regA,$regB\n"
self.assertEqual(output, expect)
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