lib.data: improve reset value handling for Union.
* Reject union initialization with more than one reset value. * Replace the reset value specified in the class definition with the one provided during initalization instead of merging.
This commit is contained in:
parent
c7ef05c894
commit
35561ea11a
2 changed files with 24 additions and 1 deletions
|
|
@ -669,6 +669,24 @@ class UnionTestCase(FHDLTestCase):
|
|||
self.assertEqual(s.attrs, {"debug": 1})
|
||||
self.assertEqual(s.decoder, decoder)
|
||||
|
||||
def test_construct_reset_two_wrong(self):
|
||||
class U(Union):
|
||||
a: unsigned(1)
|
||||
b: unsigned(2)
|
||||
|
||||
with self.assertRaisesRegex(ValueError,
|
||||
r"^Reset value for at most one field can be provided for a union class "
|
||||
r"\(specified: a, b\)$"):
|
||||
U(reset=dict(a=1, b=2))
|
||||
|
||||
def test_construct_reset_override(self):
|
||||
class U(Union):
|
||||
a: unsigned(1) = 1
|
||||
b: unsigned(2)
|
||||
|
||||
self.assertEqual(U().as_value().reset, 0b01)
|
||||
self.assertEqual(U(reset=dict(b=0b10)).as_value().reset, 0b10)
|
||||
|
||||
|
||||
# Examples from https://github.com/amaranth-lang/amaranth/issues/693
|
||||
class RFCExamplesTestCase(TestCase):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue