[Implement] Buffer.compare by jtenner · Pull Request #7 · AssemblyScript/node
@@ -1,3 +1,10 @@
function createFrom<T>(values: valueof<T>[]): T {
let result = instantiate<T>(values.length);
// @ts-ignore
for (let i = 0; i < values.length; i++) result[i] = values[i];
return result;
}
/** * This is the buffer test suite. For each prototype function, put a single test * function call here. Expand Down Expand Up @@ -43,6 +50,18 @@ describe("buffer", () => { // TODO: expectFn(() => { Buffer.allocUnsafe(BLOCK_MAXSIZE + 1); }).toThrow(); });
test("#compare", () => { let a = createFrom<Buffer>([0x05, 0x06, 0x07, 0x08]); let b = createFrom<Buffer>([0x01, 0x02, 0x03]); let c = createFrom<Buffer>([0x05, 0x06, 0x07]); let d = createFrom<Buffer>([0x04, 0x05, 0x06]);
let actual: Buffer[] = [a, b, c, d]; actual.sort(Buffer.compare); let expected: Buffer[] = [b, d, c, a]; expect<Buffer[]>(actual).toStrictEqual(expected); });
test("#isBuffer", () => { let a = ""; let b = new Uint8Array(0); Expand Down
/** * This is the buffer test suite. For each prototype function, put a single test * function call here. Expand Down Expand Up @@ -43,6 +50,18 @@ describe("buffer", () => { // TODO: expectFn(() => { Buffer.allocUnsafe(BLOCK_MAXSIZE + 1); }).toThrow(); });
test("#compare", () => { let a = createFrom<Buffer>([0x05, 0x06, 0x07, 0x08]); let b = createFrom<Buffer>([0x01, 0x02, 0x03]); let c = createFrom<Buffer>([0x05, 0x06, 0x07]); let d = createFrom<Buffer>([0x04, 0x05, 0x06]);
let actual: Buffer[] = [a, b, c, d]; actual.sort(Buffer.compare); let expected: Buffer[] = [b, d, c, a]; expect<Buffer[]>(actual).toStrictEqual(expected); });
test("#isBuffer", () => { let a = ""; let b = new Uint8Array(0); Expand Down