fix repr (0x prefix) and add repr test for selectable int
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 5 Apr 2020 18:16:05 +0000 (19:16 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 5 Apr 2020 18:16:21 +0000 (19:16 +0100)
src/soc/decoder/selectable_int.py

index 28e48f2e8d08315da3bf52a72aed6ddd94bfbbb6..ccdac9f5b92f822a8826addc6a1b25b1d0e8de1b 100644 (file)
@@ -167,7 +167,7 @@ class SelectableInt:
         return self.value != 0
 
     def __repr__(self):
-        return "SelectableInt(value={:x}, bits={})".format(self.value,
+        return "SelectableInt(value=0x{:x}, bits={})".format(self.value,
                                                            self.bits)
 
 def onebit(bit):
@@ -278,6 +278,11 @@ class SelectableIntTestCase(unittest.TestCase):
         self.assertEqual(c, 0x00)
         self.assertEqual(c.bits, 8)
 
+    def test_repr(self):
+        for i in range(65536):
+            a = SelectableInt(i, 16)
+            b = eval(repr(a))
+            self.assertEqual(a, b)
 
 if __name__ == "__main__":
     unittest.main()