37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import { createUint8ArraySlice } from "./uint8-slice.js";
|
|
|
|
describe("createUint8ArraySlice", () => {
|
|
it("returns a slice of the given range", { timeout: 5000 }, () => {
|
|
const src = new Uint8Array([10, 20, 30, 40, 50]);
|
|
const out = createUint8ArraySlice(src, 1, 4);
|
|
expect(Array.from(out)).toEqual([20, 30, 40]);
|
|
});
|
|
|
|
it("produces an independent copy (no shared memory)", {
|
|
timeout: 5000,
|
|
}, () => {
|
|
const src = new Uint8Array([1, 2, 3, 4]);
|
|
const out = createUint8ArraySlice(src, 0, 4);
|
|
out[0] = 99;
|
|
expect(src[0]).toBe(1);
|
|
});
|
|
|
|
it("returns empty when start === end", { timeout: 5000 }, () => {
|
|
const src = new Uint8Array([1, 2, 3]);
|
|
expect(createUint8ArraySlice(src, 1, 1).byteLength).toBe(0);
|
|
});
|
|
|
|
it("clamps end past length", { timeout: 5000 }, () => {
|
|
const src = new Uint8Array([1, 2, 3]);
|
|
expect(Array.from(createUint8ArraySlice(src, 0, 99))).toEqual([
|
|
1, 2, 3,
|
|
]);
|
|
});
|
|
|
|
it("supports zero-length input", { timeout: 5000 }, () => {
|
|
const src = new Uint8Array(0);
|
|
expect(createUint8ArraySlice(src, 0, 0).byteLength).toBe(0);
|
|
});
|
|
});
|