@@ -205,43 +205,69 @@ func TestNewHeaderHasExpectedValues(t *testing.T) {
205205 assert .Equal (t , want , got , "NewHeader got = %v, want = %v" , got , want )
206206}
207207
208- func TestCharacteristics_StoreIdentityCIDs (t * testing.T ) {
209- subject := carv2.Characteristics {}
210- require .False (t , subject .IsFullyIndexed ())
211-
212- subject .SetFullyIndexed (true )
213- require .True (t , subject .IsFullyIndexed ())
214-
215- var buf bytes.Buffer
216- written , err := subject .WriteTo (& buf )
217- require .NoError (t , err )
218- require .Equal (t , int64 (16 ), written )
219- require .Equal (t , []byte {
220- 0x80 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
221- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
222- }, buf .Bytes ())
223-
224- var decodedSubject carv2.Characteristics
225- read , err := decodedSubject .ReadFrom (& buf )
226- require .NoError (t , err )
227- require .Equal (t , int64 (16 ), read )
228- require .True (t , decodedSubject .IsFullyIndexed ())
229-
230- buf .Reset ()
231- subject .SetFullyIndexed (false )
232- require .False (t , subject .IsFullyIndexed ())
233-
234- written , err = subject .WriteTo (& buf )
235- require .NoError (t , err )
236- require .Equal (t , int64 (16 ), written )
237- require .Equal (t , []byte {
238- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
239- 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
240- }, buf .Bytes ())
241-
242- var decodedSubjectAgain carv2.Characteristics
243- read , err = decodedSubjectAgain .ReadFrom (& buf )
244- require .NoError (t , err )
245- require .Equal (t , int64 (16 ), read )
246- require .False (t , decodedSubjectAgain .IsFullyIndexed ())
208+ func TestCharacteristics (t * testing.T ) {
209+ tests := []struct {
210+ name string
211+ isset func (carv2.Characteristics ) bool
212+ set func (* carv2.Characteristics , bool )
213+ expectBytes []byte
214+ }{
215+ {
216+ "FullyIndexed" ,
217+ func (c carv2.Characteristics ) bool { return c .IsFullyIndexed () },
218+ func (c * carv2.Characteristics , s bool ) { c .SetFullyIndexed (s ) },
219+ []byte {
220+ 0x80 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
221+ 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
222+ },
223+ },
224+ {
225+ "MessageAfterHeader" ,
226+ func (c carv2.Characteristics ) bool { return c .IsMessageAfterHeader () },
227+ func (c * carv2.Characteristics , s bool ) { c .SetMessageAfterHeader (s ) },
228+ []byte {
229+ 0x40 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
230+ 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
231+ },
232+ },
233+ }
234+ for _ , tt := range tests {
235+ tt := tt
236+ t .Run (tt .name , func (t * testing.T ) {
237+ subject := carv2.Characteristics {}
238+ require .False (t , tt .isset (subject ))
239+ tt .set (& subject , true )
240+ require .True (t , tt .isset (subject ))
241+
242+ var buf bytes.Buffer
243+ written , err := subject .WriteTo (& buf )
244+ require .NoError (t , err )
245+ require .Equal (t , int64 (16 ), written )
246+ require .Equal (t , tt .expectBytes , buf .Bytes ())
247+
248+ var decodedSubject carv2.Characteristics
249+ read , err := decodedSubject .ReadFrom (& buf )
250+ require .NoError (t , err )
251+ require .Equal (t , int64 (16 ), read )
252+ require .True (t , tt .isset (decodedSubject ))
253+
254+ buf .Reset ()
255+ tt .set (& subject , false )
256+ require .False (t , tt .isset (subject ))
257+
258+ written , err = subject .WriteTo (& buf )
259+ require .NoError (t , err )
260+ require .Equal (t , int64 (16 ), written )
261+ require .Equal (t , []byte {
262+ 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
263+ 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ,
264+ }, buf .Bytes ())
265+
266+ var decodedSubjectAgain carv2.Characteristics
267+ read , err = decodedSubjectAgain .ReadFrom (& buf )
268+ require .NoError (t , err )
269+ require .Equal (t , int64 (16 ), read )
270+ require .False (t , tt .isset (decodedSubjectAgain ))
271+ })
272+ }
247273}
0 commit comments