From c3fa9b65bd7c7454c10243629e555066e29670dc Mon Sep 17 00:00:00 2001 From: Danny Staple Date: Sat, 8 Jan 2022 15:50:28 +0000 Subject: [PATCH] Turns out, this dialect supports taking out spaces and the bang mark. --- tests/testpioasm.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/testpioasm.py b/tests/testpioasm.py index 3ef3be5..8a3743f 100644 --- a/tests/testpioasm.py +++ b/tests/testpioasm.py @@ -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] @@ -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") @@ -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( @@ -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])