@@ -58,34 +58,11 @@ typedef struct vector_json_test_case_t {
58
58
bool * test_valid ;
59
59
} vector_json_test_case_t ;
60
60
61
- static void
62
- translate_json_test_vector (bson_t * array_in , bson_t * array_out )
63
- {
64
- // Patches JSON tests until DRIVERS-3095 is resolved:
65
- // - convert "inf" to a double +Infinity
66
- // - convert "-inf" to a double -Infinity
67
-
68
- bson_iter_t iter_in ;
69
- ASSERT (bson_iter_init (& iter_in , array_in ));
70
- bson_array_builder_t * builder = bson_array_builder_new ();
71
- while (bson_iter_next (& iter_in )) {
72
- if (BSON_ITER_HOLDS_UTF8 (& iter_in ) && 0 == strcmp ("inf" , bson_iter_utf8 (& iter_in , NULL ))) {
73
- ASSERT (bson_array_builder_append_double (builder , (double ) INFINITY ));
74
- } else if (BSON_ITER_HOLDS_UTF8 (& iter_in ) && 0 == strcmp ("-inf" , bson_iter_utf8 (& iter_in , NULL ))) {
75
- ASSERT (bson_array_builder_append_double (builder , (double ) - INFINITY ));
76
- } else {
77
- ASSERT (bson_array_builder_append_iter (builder , & iter_in ));
78
- }
79
- }
80
- ASSERT (bson_array_builder_build (builder , array_out ));
81
- bson_array_builder_destroy (builder );
82
- }
83
-
84
61
static bool
85
62
append_vector_packed_bit_from_packed_array (
86
63
bson_t * bson , const char * key , int key_length , const bson_iter_t * iter , int64_t padding , bson_error_t * error )
87
64
{
88
- // (TODO for DRIVERS-3095, DRIVERS-3097 ) This implements something the test covers that our API doesn't. If the test
65
+ // (Spec test improvement TODO ) This implements something the test covers that our API doesn't. If the test
89
66
// were modified to cover element-by-element conversion, this can be replaced with
90
67
// bson_append_vector_packed_bit_from_array.
91
68
@@ -182,7 +159,7 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
182
159
bson_error_t vector_from_array_error ;
183
160
bool vector_from_array_ok ;
184
161
185
- // (TODO for DRIVERS-3095, DRIVERS-3097 ) Patch test cases that have unused bits set to '1' when '0' is required.
162
+ // (Spec test improvement TODO ) Patch test cases that have unused bits set to '1' when '0' is required.
186
163
if (0 == strcmp ("PACKED_BIT with padding" , test_case -> test_description )) {
187
164
bson_iter_t iter ;
188
165
ASSERT (bson_iter_init_find (& iter , & expected_bson , test_case -> scenario_test_key ));
@@ -205,26 +182,20 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
205
182
& vector_from_array , test_case -> scenario_test_key , & iter , & vector_from_array_error );
206
183
} else if (0 == strcmp ("0x27" , test_case -> test_dtype_hex_str )) {
207
184
// float32 vector from float64 array
208
- // (TODO for DRIVERS-3095) Convert the unusual numeric array format to a standard array
209
- bson_t converted = BSON_INITIALIZER ;
185
+ bson_iter_t iter ;
210
186
bool padding_ok = !test_case -> test_padding || * test_case -> test_padding == 0 ;
211
- if (test_case -> test_vector_array && padding_ok ) {
212
- bson_iter_t iter ;
213
- translate_json_test_vector (test_case -> test_vector_array , & converted );
214
- vector_from_array_ok = bson_iter_init (& iter , & converted ) &&
215
- BSON_APPEND_VECTOR_FLOAT32_FROM_ARRAY (
216
- & vector_from_array , test_case -> scenario_test_key , & iter , & vector_from_array_error );
217
- } else {
218
- vector_from_array_ok = false;
219
- }
220
- bson_destroy (& converted );
187
+ vector_from_array_ok = test_case -> test_vector_array && padding_ok &&
188
+ bson_iter_init (& iter , test_case -> test_vector_array ) &&
189
+ BSON_APPEND_VECTOR_FLOAT32_FROM_ARRAY (
190
+ & vector_from_array , test_case -> scenario_test_key , & iter , & vector_from_array_error );
221
191
} else if (0 == strcmp ("0x10" , test_case -> test_dtype_hex_str )) {
222
192
// packed_bit from packed bytes in an int array, with "padding" parameter supplied separately.
223
- // TODO for DRIVERS-3095, DRIVERS-3097 :
193
+ // Suggested changes to reduce the special cases here :
224
194
// - Array-to-Vector should be defined as an element-by-element conversion. This test shouldn't operate on packed
225
195
// representations.
226
196
// - Include additional JSON tests for packed access, distinct from Array conversion.
227
197
// - Tests should keep the unused bits zeroed as required.
198
+ // (Spec test improvement TODO)
228
199
bson_iter_t iter ;
229
200
if (!test_case -> test_padding ) {
230
201
test_error ("test '%s' is missing required 'padding' field" , test_case -> test_description );
@@ -286,12 +257,9 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
286
257
bson_array_builder_destroy (array_builder );
287
258
}
288
259
289
- // (TODO for DRIVERS-3095, DRIVERS-3097) Due to loosely defined element types and rounding behavior in the test
290
- // vectors, this comparison can't be exact. Temporary special cases are needed for float32 and packed_bit.
291
-
292
260
if (BSON_ITER_HOLDS_VECTOR_FLOAT32 (& iter )) {
293
- // float32 special case: We need to handle the nonstandard "inf" and "-inf" forms, and
294
- // due to underspecified rounding and conversion rules we compare value inexactly.
261
+ // float32 special case: Due to underspecified rounding and conversion rules we compare value inexactly.
262
+ // (Spec test improvement TODO)
295
263
296
264
bson_iter_t actual_iter , expected_iter ;
297
265
ASSERT (bson_iter_init (& actual_iter , & array_from_vector ));
@@ -314,12 +282,7 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
314
282
double actual_double = bson_iter_double (& actual_iter );
315
283
316
284
double expected_double ;
317
- if (BSON_ITER_HOLDS_UTF8 (& expected_iter ) && 0 == strcmp ("inf" , bson_iter_utf8 (& expected_iter , NULL ))) {
318
- expected_double = (double ) INFINITY ;
319
- } else if (BSON_ITER_HOLDS_UTF8 (& expected_iter ) &&
320
- 0 == strcmp ("-inf" , bson_iter_utf8 (& expected_iter , NULL ))) {
321
- expected_double = (double ) - INFINITY ;
322
- } else if (BSON_ITER_HOLDS_DOUBLE (& expected_iter )) {
285
+ if (BSON_ITER_HOLDS_DOUBLE (& expected_iter )) {
323
286
expected_double = bson_iter_double (& expected_iter );
324
287
} else {
325
288
test_error ("test-vector array element %d has unexpected type, should be double, 'inf', or '-inf'." ,
@@ -357,6 +320,7 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
357
320
// understand it, they're operating on bytes rather than elements. This is the inverse of
358
321
// append_vector_packed_bit_from_packed_array() above, and it bypasses the vector-to-array conversion.
359
322
// 'array_from_vector' is ignored on this path.
323
+ // (Spec test improvement TODO)
360
324
361
325
bson_iter_t expected_iter ;
362
326
ASSERT (bson_iter_init (& expected_iter , test_case -> test_vector_array ));
@@ -372,7 +336,7 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
372
336
test_error ("test-vector array element %d has unexpected type, should be int." , (int ) byte_count );
373
337
}
374
338
375
- // (TODO for DRIVERS-3095, DRIVERS-3097 ) Packed writes can't set unused bits to '1' in libbson, but the spec
339
+ // (Spec test improvement TODO ) Packed writes can't set unused bits to '1' in libbson, but the spec
376
340
// tests allow padding bits to take on undefined values. Modify the expected values to keep padding bits
377
341
// zeroed.
378
342
if (0 == strcmp ("PACKED_BIT with padding" , test_case -> test_description ) &&
0 commit comments