@@ -166,6 +166,41 @@ class Bitlist8(BaseBitlist):
166166 with pytest .raises (ValidationError ):
167167 model (value = invalid_value )
168168
169+ def test_add_with_list (self ) -> None :
170+ """Tests concatenating a Bitlist with a regular list."""
171+
172+ class Bitlist8 (BaseBitlist ):
173+ LIMIT = 8
174+
175+ bitlist = Bitlist8 (data = [True , False , True ])
176+ result = bitlist + [False , True ]
177+ assert len (result ) == 5
178+ assert list (result .data ) == [True , False , True , False , True ]
179+ assert isinstance (result , Bitlist8 )
180+
181+ def test_add_with_bitlist (self ) -> None :
182+ """Tests concatenating two Bitlists of the same type."""
183+
184+ class Bitlist8 (BaseBitlist ):
185+ LIMIT = 8
186+
187+ bitlist1 = Bitlist8 (data = [True , False ])
188+ bitlist2 = Bitlist8 (data = [True , True ])
189+ result = bitlist1 + bitlist2
190+ assert len (result ) == 4
191+ assert list (result .data ) == [True , False , True , True ]
192+ assert isinstance (result , Bitlist8 )
193+
194+ def test_add_exceeding_limit_raises_error (self ) -> None :
195+ """Tests that concatenating beyond the limit raises an error."""
196+
197+ class Bitlist4 (BaseBitlist ):
198+ LIMIT = 4
199+
200+ bitlist = Bitlist4 (data = [True , False , True ])
201+ with pytest .raises (ValueError , match = "cannot contain more than 4 bits" ):
202+ bitlist + [False , True ]
203+
169204
170205class TestBitfieldSerialization :
171206 """Tests the `encode_bytes` and `decode_bytes` methods for bitfields."""
0 commit comments