+describe("get8BitSignedIntegralItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = Int8Array.from([0, -1, 0]).buffer;
+ assertStrictEquals(get8BitSignedIntegralItem(buffer, 1), -1n);
+ assertStrictEquals(
+ get8BitSignedIntegralItem(new DataView(buffer), 1),
+ -1n,
+ );
+ assertStrictEquals(
+ get8BitSignedIntegralItem(new Uint8Array(buffer), 1),
+ -1n,
+ );
+ });
+});
+
+describe("get8BitUnsignedIntegralItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = Int8Array.from([0, -1, 0]).buffer;
+ assertStrictEquals(get8BitUnsignedIntegralItem(buffer, 1), 255n);
+ assertStrictEquals(
+ get8BitUnsignedIntegralItem(new DataView(buffer), 1),
+ 255n,
+ );
+ assertStrictEquals(
+ get8BitUnsignedIntegralItem(new Int8Array(buffer), 1),
+ 255n,
+ );
+ });
+});
+
+describe("get16BitSignedIntegralItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = Int8Array.from([0, 0, -1, -1, 0, 0]).buffer;
+ assertStrictEquals(get16BitSignedIntegralItem(buffer, 2), -1n);
+ assertStrictEquals(
+ get16BitSignedIntegralItem(new DataView(buffer), 2),
+ -1n,
+ );
+ assertStrictEquals(
+ get16BitSignedIntegralItem(new Uint16Array(buffer), 2),
+ -1n,
+ );
+ });
+});
+
+describe("get16BitUnsignedIntegralItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = Int8Array.from([0, 0, -1, -1, 0, 0]).buffer;
+ assertStrictEquals(
+ get16BitUnsignedIntegralItem(buffer, 2),
+ (1n << 16n) - 1n,
+ );
+ assertStrictEquals(
+ get16BitUnsignedIntegralItem(new DataView(buffer), 2),
+ (1n << 16n) - 1n,
+ );
+ assertStrictEquals(
+ get16BitUnsignedIntegralItem(new Int16Array(buffer), 2),
+ (1n << 16n) - 1n,
+ );
+ });
+});
+
+describe("get32BitFloatingPointItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = new ArrayBuffer(12);
+ const view = new DataView(buffer);
+ view.setFloat32(0, NaN);
+ view.setFloat32(4, -Infinity);
+ view.setFloat32(8, -0);
+ assertStrictEquals(get32BitFloatingPointItem(buffer, 0), NaN);
+ assertStrictEquals(
+ get32BitFloatingPointItem(buffer, 4),
+ -Infinity,
+ );
+ assertStrictEquals(get32BitFloatingPointItem(buffer, 8), -0);
+ assertStrictEquals(
+ get32BitFloatingPointItem(new DataView(buffer), 4),
+ -Infinity,
+ );
+ assertStrictEquals(
+ get32BitFloatingPointItem(new Uint32Array(buffer), 4),
+ -Infinity,
+ );
+ });
+});
+
+describe("get32BitSignedIntegralItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = Int8Array.from(
+ [0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0],
+ ).buffer;
+ assertStrictEquals(get32BitSignedIntegralItem(buffer, 4), -1n);
+ assertStrictEquals(
+ get32BitSignedIntegralItem(new DataView(buffer), 4),
+ -1n,
+ );
+ assertStrictEquals(
+ get32BitSignedIntegralItem(new Uint32Array(buffer), 4),
+ -1n,
+ );
+ });
+});
+
+describe("get32BitUnsignedIntegralItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = Int8Array.from(
+ [0, 0, 0, 0, -1, -1, -1, -1, 0, 0, 0, 0],
+ ).buffer;
+ assertStrictEquals(
+ get32BitUnsignedIntegralItem(buffer, 4),
+ (1n << 32n) - 1n,
+ );
+ assertStrictEquals(
+ get32BitUnsignedIntegralItem(new DataView(buffer), 4),
+ (1n << 32n) - 1n,
+ );
+ assertStrictEquals(
+ get32BitUnsignedIntegralItem(new Int32Array(buffer), 4),
+ (1n << 32n) - 1n,
+ );
+ });
+});
+
+describe("get64BitFloatingPointItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = new ArrayBuffer(24);
+ const view = new DataView(buffer);
+ view.setFloat64(0, NaN);
+ view.setFloat64(8, -Infinity);
+ view.setFloat64(16, -0);
+ assertStrictEquals(get64BitFloatingPointItem(buffer, 0), NaN);
+ assertStrictEquals(
+ get64BitFloatingPointItem(buffer, 8),
+ -Infinity,
+ );
+ assertStrictEquals(get64BitFloatingPointItem(buffer, 16), -0);
+ assertStrictEquals(
+ get64BitFloatingPointItem(new DataView(buffer), 8),
+ -Infinity,
+ );
+ assertStrictEquals(
+ get64BitFloatingPointItem(new BigUint64Array(buffer), 8),
+ -Infinity,
+ );
+ });
+});
+
+describe("get64BitSignedIntegralItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = Int8Array.from(
+ [0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1],
+ ).buffer;
+ assertStrictEquals(get64BitSignedIntegralItem(buffer, 8), -1n);
+ assertStrictEquals(
+ get64BitSignedIntegralItem(new DataView(buffer), 8),
+ -1n,
+ );
+ assertStrictEquals(
+ get64BitSignedIntegralItem(new BigUint64Array(buffer), 8),
+ -1n,
+ );
+ });
+});
+
+describe("get64BitUnsignedIntegralItem", () => {
+ it("[[Call]] gets the item", () => {
+ const buffer = Int8Array.from(
+ [0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1],
+ ).buffer;
+ assertStrictEquals(
+ get64BitUnsignedIntegralItem(buffer, 8),
+ (1n << 64n) - 1n,
+ );
+ assertStrictEquals(
+ get64BitUnsignedIntegralItem(new DataView(buffer), 8),
+ (1n << 64n) - 1n,
+ );
+ assertStrictEquals(
+ get64BitUnsignedIntegralItem(new BigInt64Array(buffer), 8),
+ (1n << 64n) - 1n,
+ );
+ });
+});
+
+describe("isArrayBuffer", () => {
+ it("[[Call]] returns true for array buffers", () => {
+ assertStrictEquals(
+ isArrayBuffer(new ArrayBuffer()),
+ true,
+ );
+ assertStrictEquals(
+ isArrayBuffer(new SharedArrayBuffer()),
+ true,
+ );
+ });
+
+ it("[[Call]] returns false for others", () => {
+ [
+ undefined,
+ null,
+ true,
+ Symbol(),
+ 27,
+ 98n,
+ {},
+ [],
+ () => {},
+ new Proxy({}, {}),
+ "string",
+ new DataView(new ArrayBuffer()),
+ new Uint8Array(),
+ ].forEach((value) =>
+ assertStrictEquals(isArrayBuffer(value), false)
+ );
+ });
+});
+