Skip to content

Turns out, this dialect supports taking out spaces and the bang mark. #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions tests/testpioasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def nice_opcode(o):
return o[:3] + "_" + o[3:8] + "_" + o[8:]


class TestNop(unittest.TestCase):
class AssembleChecks(unittest.TestCase):
def assertAssemblesTo(self, source, expected):
actual = adafruit_pioasm.assemble(source)
expected_bin = [nice_opcode(x) for x in expected]
Expand All @@ -35,6 +35,8 @@ def assertAssemblyFails(self, source, match=None, errtype=RuntimeError):
else:
self.assertRaises(errtype, adafruit_pioasm.assemble, source)


class TestNop(AssembleChecks):
def testNonsense(self):
self.assertAssemblyFails("nope")

Expand All @@ -55,12 +57,6 @@ def testSidesetOpt(self):
)
self.assertAssemblesTo(".side_set 1 opt\nnop [1]", [0b101_00001_010_00_010])

def testMov(self):
# non happy path
self.assertAssemblyFails(
"mov x, blah", match="Invalid mov source 'blah'", errtype=ValueError
)

def testSet(self):
# non happy path
self.assertAssemblyFails(
Expand Down Expand Up @@ -94,3 +90,23 @@ def testWait(self):
self.assertAssemblesTo("wait 0 irq 0 rel", [0b001_00000_0_10_10000])
self.assertAssemblesTo("wait 1 irq 0", [0b001_00000_1_10_00000])
self.assertAssemblesTo("wait 0 irq 1 rel", [0b001_00000_0_10_10001])


class TestMov(AssembleChecks):
def testMovNonHappy(self):
# non happy path
self.assertAssemblyFails(
"mov x, blah", match="Invalid mov source 'blah'", errtype=ValueError
)

def testMovInvert(self):
# test moving and inverting
self.assertAssemblesTo("mov x, ~ x", [0b101_00000_001_01_001])
self.assertAssemblesTo("mov x, ~ x", [0b101_00000_001_01_001])
self.assertAssemblesTo("mov x, ~x", [0b101_00000_001_01_001])
self.assertAssemblesTo("mov x, !x", [0b101_00000_001_01_001])

def testMovReverse(self):
# test moving and reversing bits
self.assertAssemblesTo("mov x, :: x", [0b101_00000_001_10_001])
self.assertAssemblesTo("mov x, ::x", [0b101_00000_001_10_001])