@@ -245,7 +245,7 @@ func TestDecodeUint16(t *testing.T) {
245245 "a1ff" : uint16 (255 ),
246246 "a201f4" : uint16 (500 ),
247247 "a22a78" : uint16 (10872 ),
248- "a2ffff" : uint16 (65535 ), // [cite: 88] - Note: reflection test uses uint64 expected value
248+ "a2ffff" : uint16 (65535 ),
249249 }
250250
251251 for hexStr , expected := range tests {
@@ -337,16 +337,12 @@ func TestDecodeUint128(t *testing.T) {
337337 }
338338}
339339
340- // TestPointers requires a specific data file and structure.
341340func TestPointersInDecoder (t * testing.T ) {
342- // This test requires the 'maps-with-pointers.raw' file used in reflection_test [cite: 92]
343- // It demonstrates how to handle pointers using the basic Decoder.
344- bytes , err := os .ReadFile (testFile ("maps-with-pointers.raw" )) // [cite: 92]
341+ bytes , err := os .ReadFile (testFile ("maps-with-pointers.raw" ))
345342 require .NoError (t , err )
346343 dd := NewDataDecoder (bytes )
347344
348345 expected := map [uint ]map [string ]string {
349- // Offsets and expected values from reflection_test.go [cite: 92]
350346 0 : {"long_key" : "long_value1" },
351347 22 : {"long_key" : "long_value2" },
352348 37 : {"long_key2" : "long_value1" },
@@ -358,12 +354,11 @@ func TestPointersInDecoder(t *testing.T) {
358354 for startOffset , expectedValue := range expected {
359355 t .Run (fmt .Sprintf ("Offset_%d" , startOffset ), func (t * testing.T ) {
360356 decoder := NewDecoder (dd , startOffset ) // Start at the specific offset
361- actualValue := make (map [string ]string )
362357
363358 // Expecting a map at the target offset (may be behind a pointer)
364359 mapIter , size , err := decoder .ReadMap ()
365360 require .NoError (t , err , "ReadMap failed" )
366- _ = size // Use size if needed for pre-allocation
361+ actualValue := make ( map [ string ] string , int ( size ))
367362 for keyBytes , errIter := range mapIter {
368363 require .NoError (t , errIter )
369364 key := string (keyBytes )
@@ -487,28 +482,18 @@ func TestPeekKind(t *testing.T) {
487482// TestPeekKindWithPointer tests that PeekKind correctly follows pointers
488483// to get the actual kind of the pointed-to value.
489484func TestPeekKindWithPointer (t * testing.T ) {
490- // Create a buffer with a pointer that points to a string
491- // This is a simplified test - in real MMDB files pointers are more complex
485+ // Create a buffer with a pointer at offset 0 and a string at offset 5.
492486 buffer := []byte {
493- // Pointer (TypePointer=1, size/pointer encoding)
494- 0x20 , 0x05 , // Simple pointer to offset 5
495- // Target string at offset 5 (but we'll put it at offset 2 for this test)
496- 0x44 , 't' , 'e' , 's' , 't' , // String "test"
487+ 0x20 , 0x05 ,
488+ 0x00 , 0x00 , 0x00 ,
489+ 0x44 , 't' , 'e' , 's' , 't' ,
497490 }
498491
499492 decoder := NewDecoder (NewDataDecoder (buffer ), 0 )
500493
501- // PeekKind should follow the pointer and return KindString
502494 actualType , err := decoder .PeekKind ()
503495 require .NoError (t , err , "PeekKind with pointer failed" )
504-
505- // Note: This test may need adjustment based on actual pointer encoding
506- // The important thing is that PeekKind follows pointers
507- if actualType != KindPointer {
508- // If the implementation follows pointers completely, it should return the target kind
509- // If it just returns KindPointer, that's also acceptable behavior
510- t .Logf ("PeekKind returned %d (this may be expected behavior)" , actualType )
511- }
496+ require .Equal (t , KindString , actualType )
512497}
513498
514499// ExampleDecoder_PeekKind demonstrates how to use PeekKind for
@@ -556,12 +541,21 @@ func ExampleDecoder_PeekKind() {
556541func TestDecoderOptions (t * testing.T ) {
557542 buffer := []byte {0x44 , 't' , 'e' , 's' , 't' } // String "test"
558543 dd := NewDataDecoder (buffer )
544+ optionCalled := false
545+ option := func (* decoderOptions ) {
546+ optionCalled = true
547+ }
559548
560- // Test that options infrastructure works (even with no current options)
549+ // Test that options infrastructure works (even with no current options).
561550 decoder1 := NewDecoder (dd , 0 )
562551 require .NotNil (t , decoder1 )
563552
564- // Test that passing empty options slice works
553+ // Test that passing options invokes each option callback.
554+ decoderWithOption := NewDecoder (dd , 0 , option )
555+ require .NotNil (t , decoderWithOption )
556+ require .True (t , optionCalled )
557+
558+ // Test that passing empty options slice works.
565559 decoder2 := NewDecoder (dd , 0 )
566560 require .NotNil (t , decoder2 )
567561}
0 commit comments