@@ -36,7 +36,7 @@ type bsonBinaryVectorTestCase struct {
3636	CanonicalBson  string         `json:"canonical_bson"` 
3737}
3838
39- func  Test_BsonBinaryVector (t  * testing.T ) {
39+ func  TestBsonBinaryVector (t  * testing.T ) {
4040	t .Parallel ()
4141
4242	jsonFiles , err  :=  findJSONFilesInDir (bsonBinaryVectorDir )
@@ -91,6 +91,36 @@ func Test_BsonBinaryVector(t *testing.T) {
9191		}
9292	})
9393
94+ 	t .Run ("FLOAT32 with padding" , func (t  * testing.T ) {
95+ 		t .Parallel ()
96+ 
97+ 		t .Run ("Unmarshaling" , func (t  * testing.T ) {
98+ 			val  :=  D {{"vector" , Binary {Subtype : TypeBinaryVector , Data : []byte {byte (Float32Vector ), 3 }}}}
99+ 			b , err  :=  Marshal (val )
100+ 			require .NoError (t , err , "marshaling test BSON" )
101+ 			var  got  struct  {
102+ 				Vector  Vector 
103+ 			}
104+ 			err  =  Unmarshal (b , & got )
105+ 			require .ErrorContains (t , err , errNonZeroVectorPadding .Error ())
106+ 		})
107+ 	})
108+ 
109+ 	t .Run ("INT8 with padding" , func (t  * testing.T ) {
110+ 		t .Parallel ()
111+ 
112+ 		t .Run ("Unmarshaling" , func (t  * testing.T ) {
113+ 			val  :=  D {{"vector" , Binary {Subtype : TypeBinaryVector , Data : []byte {byte (Int8Vector ), 3 }}}}
114+ 			b , err  :=  Marshal (val )
115+ 			require .NoError (t , err , "marshaling test BSON" )
116+ 			var  got  struct  {
117+ 				Vector  Vector 
118+ 			}
119+ 			err  =  Unmarshal (b , & got )
120+ 			require .ErrorContains (t , err , errNonZeroVectorPadding .Error ())
121+ 		})
122+ 	})
123+ 
94124	t .Run ("Padding specified with no vector data PACKED_BIT" , func (t  * testing.T ) {
95125		t .Parallel ()
96126
@@ -134,13 +164,13 @@ func convertSlice[T int8 | float32 | byte](s []interface{}) []T {
134164	v  :=  make ([]T , len (s ))
135165	for  i , e  :=  range  s  {
136166		f  :=  math .NaN ()
137- 		switch  v  :=  e .(type ) {
167+ 		switch  val  :=  e .(type ) {
138168		case  float64 :
139- 			f  =  v 
169+ 			f  =  val 
140170		case  string :
141- 			if  v  ==  "inf"  {
171+ 			if  val  ==  "inf"  {
142172				f  =  math .Inf (0 )
143- 			} else  if  v  ==  "-inf"  {
173+ 			} else  if  val  ==  "-inf"  {
144174				f  =  math .Inf (- 1 )
145175			}
146176		}
@@ -150,10 +180,6 @@ func convertSlice[T int8 | float32 | byte](s []interface{}) []T {
150180}
151181
152182func  runBsonBinaryVectorTest (t  * testing.T , testKey  string , test  bsonBinaryVectorTestCase ) {
153- 	if  ! test .Valid  {
154- 		t .Skipf ("skip invalid case %s" , test .Description )
155- 	}
156- 
157183	testVector  :=  make (map [string ]Vector )
158184	switch  alias  :=  test .DtypeHex ; alias  {
159185	case  "0x03" :
@@ -180,6 +206,23 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector
180206	require .NoError (t , err , "decoding canonical BSON" )
181207
182208	t .Run ("Unmarshaling" , func (t  * testing.T ) {
209+ 		skipCases  :=  map [string ]string {
210+ 			"FLOAT32 with padding" :                             "run in alternative case" ,
211+ 			"Overflow Vector INT8" :                             "compile-time restriction" ,
212+ 			"Underflow Vector INT8" :                            "compile-time restriction" ,
213+ 			"INT8 with padding" :                                "run in alternative case" ,
214+ 			"INT8 with float inputs" :                           "compile-time restriction" ,
215+ 			"Overflow Vector PACKED_BIT" :                       "compile-time restriction" ,
216+ 			"Underflow Vector PACKED_BIT" :                      "compile-time restriction" ,
217+ 			"Vector with float values PACKED_BIT" :              "compile-time restriction" ,
218+ 			"Padding specified with no vector data PACKED_BIT" : "run in alternative case" ,
219+ 			"Exceeding maximum padding PACKED_BIT" :             "run in alternative case" ,
220+ 			"Negative padding PACKED_BIT" :                      "compile-time restriction" ,
221+ 		}
222+ 		if  reason , ok  :=  skipCases [test .Description ]; ok  {
223+ 			t .Skipf ("skip test case %s: %s" , test .Description , reason )
224+ 		}
225+ 
183226		t .Parallel ()
184227
185228		var  got  map [string ]Vector 
@@ -189,6 +232,23 @@ func runBsonBinaryVectorTest(t *testing.T, testKey string, test bsonBinaryVector
189232	})
190233
191234	t .Run ("Marshaling" , func (t  * testing.T ) {
235+ 		skipCases  :=  map [string ]string {
236+ 			"FLOAT32 with padding" :                             "private padding field" ,
237+ 			"Overflow Vector INT8" :                             "compile-time restriction" ,
238+ 			"Underflow Vector INT8" :                            "compile-time restriction" ,
239+ 			"INT8 with padding" :                                "private padding field" ,
240+ 			"INT8 with float inputs" :                           "compile-time restriction" ,
241+ 			"Overflow Vector PACKED_BIT" :                       "compile-time restriction" ,
242+ 			"Underflow Vector PACKED_BIT" :                      "compile-time restriction" ,
243+ 			"Vector with float values PACKED_BIT" :              "compile-time restriction" ,
244+ 			"Padding specified with no vector data PACKED_BIT" : "run in alternative case" ,
245+ 			"Exceeding maximum padding PACKED_BIT" :             "run in alternative case" ,
246+ 			"Negative padding PACKED_BIT" :                      "compile-time restriction" ,
247+ 		}
248+ 		if  reason , ok  :=  skipCases [test .Description ]; ok  {
249+ 			t .Skipf ("skip test case %s: %s" , test .Description , reason )
250+ 		}
251+ 
192252		t .Parallel ()
193253
194254		got , err  :=  Marshal (testVector )
0 commit comments