Skip to content

Commit

Permalink
Merge pull request #34 from dannystaple/mov_operators
Browse files Browse the repository at this point in the history
Turns out, this dialect supports taking out spaces and the bang mark.
  • Loading branch information
tannewt authored Jan 10, 2022
2 parents 15e45fb + c3fa9b6 commit fbafe00
Showing 1 changed file with 23 additions and 7 deletions.
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])

0 comments on commit fbafe00

Please sign in to comment.