Skip to content

Commit 847e733

Browse files
committed
chore: update tests to ejson
1 parent 805dfe6 commit 847e733

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

test/node/bson_binary_vector.spec.test.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ type VectorTest = {
1818
type VectorSuite = { description: string; test_key: string; tests: VectorTest[] };
1919

2020
function fixFloats(f: string | number): number {
21+
// Should be nothing to "fix" but validates we didn't get
22+
// an unexpected type so we don't silently fail on it during the test
2123
if (typeof f === 'number') {
2224
return f;
2325
}
24-
if (f === 'inf') {
25-
return Infinity;
26-
}
27-
if (f === '-inf') {
28-
return -Infinity;
29-
}
3026
throw new Error(`test format error: unknown float value: ${f}`);
3127
}
3228

@@ -98,8 +94,6 @@ const invalidTestExpectedError = new Map()
9894
.set('Overflow Vector INT8', false)
9995
.set('Underflow Vector INT8', false)
10096
.set('INT8 with float inputs', false)
101-
// duplicate test! but also skipped.
102-
.set('Vector with float values PACKED_BIT', false)
10397
.set('Vector with float values PACKED_BIT', false);
10498

10599
function testVectorBuilding(test: VectorTest, expectedErrorMessage: string) {
@@ -184,7 +178,7 @@ describe('BSON Binary Vector spec tests', () => {
184178
const tests: Record<string, VectorSuite> = Object.create(null);
185179

186180
for (const file of fs.readdirSync(path.join(__dirname, 'specs/bson-binary-vector'))) {
187-
tests[path.basename(file, '.json')] = JSON.parse(
181+
tests[path.basename(file, '.json')] = EJSON.parse(
188182
fs.readFileSync(path.join(__dirname, 'specs/bson-binary-vector', file), 'utf8')
189183
);
190184
}

test/node/specs/bson-binary-vector/float32.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{
3333
"description": "Infinity Vector FLOAT32",
3434
"valid": true,
35-
"vector": ["-inf", 0.0, "inf"],
35+
"vector": [{"$numberDouble": "-Infinity"}, 0.0, {"$numberDouble": "Infinity"} ],
3636
"dtype_hex": "0x27",
3737
"dtype_alias": "FLOAT32",
3838
"padding": 0,
@@ -48,11 +48,18 @@
4848
"canonical_bson": "1C00000005766563746F72000A0000000927030000FE420000E04000"
4949
},
5050
{
51-
"description": "Insufficient vector data FLOAT32",
51+
"description": "Insufficient vector data with 3 bytes FLOAT32",
5252
"valid": false,
5353
"dtype_hex": "0x27",
5454
"dtype_alias": "FLOAT32",
5555
"canonical_bson": "1700000005766563746F7200050000000927002A2A2A00"
56+
},
57+
{
58+
"description": "Insufficient vector data with 5 bytes FLOAT32",
59+
"valid": false,
60+
"dtype_hex": "0x27",
61+
"dtype_alias": "FLOAT32",
62+
"canonical_bson": "1900000005766563746F7200070000000927002A2A2A2A2A00"
5663
}
5764
]
5865
}

0 commit comments

Comments
 (0)