[TS] Flexbuffers root vector fix (#8847)

* fix and test

* chatgpt help

* consistent throws in reference.ts
This commit is contained in:
Justin Davis
2025-12-14 16:59:27 -05:00
committed by GitHub
parent e1407e4341
commit 7bfaabc358
2 changed files with 63 additions and 14 deletions

View File

@@ -14,10 +14,31 @@ function main() {
testRoundTripWithBuilder();
testDeduplicationOff();
testBugWhereOffestWereStoredAsIntInsteadOfUInt();
testRootVector();
console.log('FlexBuffers test: completed successfully');
}
function testRootVector() {
// Root vector of strings
const stringVec = ['a', 'b', 'c'];
const bufStr = flexbuffers.encode(stringVec).buffer;
const objStr = flexbuffers.toObject(bufStr);
assert.deepStrictEqual(objStr, stringVec);
// Root vector of numbers
const numVec = [1, 2, 3, 4];
const bufNum = flexbuffers.encode(numVec).buffer;
const objNum = flexbuffers.toObject(bufNum);
assert.deepStrictEqual(objNum, numVec);
// Root vector of mixed types
const mixedVec = ['x', 42, true, null];
const bufMixed = flexbuffers.encode(mixedVec).buffer;
const objMixed = flexbuffers.toObject(bufMixed);
assert.deepStrictEqual(objMixed, mixedVec);
}
function testSingleValueBuffers() {
{
const ref = flexbuffers.toReference(new Uint8Array([0, 0, 1]).buffer);