Skip to content

Commit 9240148

Browse files
committed
fix: use reproducible code and add tests
1 parent d93774d commit 9240148

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

packages/service-provider-core/src/printable-bson.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,34 @@ describe('BSON printers', function () {
9595
).to.equal("MD5('0123456789abcdef0123456789abcdef')");
9696
});
9797

98+
describe('with Vector types', function () {
99+
it('formats Int8Array correctly', function () {
100+
expect(
101+
inspect(bson.Binary.fromInt8Array(new Int8Array([1, 2, 3])))
102+
).to.equal('Binary.fromInt8Array(new Int8Array([ 1, 2, 3 ]))');
103+
});
104+
105+
it('formats PackedBits correctly', function () {
106+
expect(
107+
inspect(bson.Binary.fromPackedBits(new Uint8Array([1, 2, 3])))
108+
).to.equal('Binary.fromPackedBits(new Uint8Array([ 1, 2, 3 ]))');
109+
});
110+
111+
it('formats Float32Array correctly', function () {
112+
expect(
113+
inspect(
114+
bson.Binary.fromFloat32Array(
115+
new Float32Array([1.1111, 2.2222, 3.3333])
116+
),
117+
{ compact: true }
118+
)
119+
).matches(
120+
// Precision is lost because of float handling, so we use regex to match
121+
/Binary.fromFloat32Array\(new Float32Array\(\[ 1\.1\d*, 2\.2\d*, 3\.3\d* \]\)\)/
122+
);
123+
});
124+
});
125+
98126
it('formats any other value with the new format using createfromBase64', function () {
99127
expect(
100128
inspect(bson.Binary.createFromBase64('SGVsbG8sIFdvcmxkIQo='))

packages/service-provider-core/src/printable-bson.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const binaryVectorInspect = function (
4949
// These arrays can be very large, so would prefer to use the default options instead.
5050
maxArrayLength: utilInspect.defaultOptions.maxArrayLength,
5151
})
52-
)})`;
52+
)}))`;
5353
case BSON.Binary.VECTOR_TYPE.Float32:
5454
return `Binary.fromFloat32Array(new Float32Array(${removeTypedArrayPrefixFromInspectResult(
5555
utilInspect(this.toFloat32Array(), {
@@ -58,16 +58,16 @@ const binaryVectorInspect = function (
5858
// These arrays can be very large, so would prefer to use the default options instead.
5959
maxArrayLength: utilInspect.defaultOptions.maxArrayLength,
6060
})
61-
)})`;
61+
)}))`;
6262
case BSON.Binary.VECTOR_TYPE.PackedBit:
63-
return `Binary.fromPackedBitArray(new Uint8Array(${removeTypedArrayPrefixFromInspectResult(
63+
return `Binary.fromPackedBits(new Uint8Array(${removeTypedArrayPrefixFromInspectResult(
6464
utilInspect(this.toPackedBits(), {
6565
depth,
6666
...options,
6767
// These arrays can be very large, so would prefer to use the default options instead.
6868
maxArrayLength: utilInspect.defaultOptions.maxArrayLength,
6969
})
70-
)})`;
70+
)}))`;
7171
default:
7272
return binaryInspect.call(this, depth, options);
7373
}

0 commit comments

Comments
 (0)