@@ -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 )
@@ -70,13 +70,13 @@ func Test_BsonBinaryVector(t *testing.T) {
7070 val := Binary {Subtype : TypeBinaryVector }
7171
7272 for _ , tc := range [][]byte {
73- {byte ( Float32Vector ) , 0 , 42 },
74- {byte ( Float32Vector ) , 0 , 42 , 42 },
75- {byte ( Float32Vector ) , 0 , 42 , 42 , 42 },
73+ {Float32Vector , 0 , 42 },
74+ {Float32Vector , 0 , 42 , 42 },
75+ {Float32Vector , 0 , 42 , 42 , 42 },
7676
77- {byte ( Float32Vector ) , 0 , 42 , 42 , 42 , 42 , 42 },
78- {byte ( Float32Vector ) , 0 , 42 , 42 , 42 , 42 , 42 , 42 },
79- {byte ( Float32Vector ) , 0 , 42 , 42 , 42 , 42 , 42 , 42 , 42 },
77+ {Float32Vector , 0 , 42 , 42 , 42 , 42 , 42 },
78+ {Float32Vector , 0 , 42 , 42 , 42 , 42 , 42 , 42 },
79+ {Float32Vector , 0 , 42 , 42 , 42 , 42 , 42 , 42 , 42 },
8080 } {
8181 t .Run (fmt .Sprintf ("marshaling %d bytes" , len (tc )- 2 ), func (t * testing.T ) {
8282 val .Data = tc
@@ -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 {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 {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
@@ -99,7 +129,7 @@ func Test_BsonBinaryVector(t *testing.T) {
99129 require .EqualError (t , err , errNonZeroVectorPadding .Error ())
100130 })
101131 t .Run ("Unmarshaling" , func (t * testing.T ) {
102- val := D {{"vector" , Binary {Subtype : TypeBinaryVector , Data : []byte {byte ( PackedBitVector ) , 1 }}}}
132+ val := D {{"vector" , Binary {Subtype : TypeBinaryVector , Data : []byte {PackedBitVector , 1 }}}}
103133 b , err := Marshal (val )
104134 require .NoError (t , err , "marshaling test BSON" )
105135 var got struct {
@@ -118,7 +148,7 @@ func Test_BsonBinaryVector(t *testing.T) {
118148 require .EqualError (t , err , errVectorPaddingTooLarge .Error ())
119149 })
120150 t .Run ("Unmarshaling" , func (t * testing.T ) {
121- val := D {{"vector" , Binary {Subtype : TypeBinaryVector , Data : []byte {byte ( PackedBitVector ) , 8 }}}}
151+ val := D {{"vector" , Binary {Subtype : TypeBinaryVector , Data : []byte {PackedBitVector , 8 }}}}
122152 b , err := Marshal (val )
123153 require .NoError (t , err , "marshaling test BSON" )
124154 var got struct {
@@ -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