Suite of AT Protocol TypeScript libraries built on web standards
1/* eslint-env mocha */
2
3import { assert, assertEquals } from "@std/assert";
4import { alloc } from "../alloc.ts";
5import { concat } from "../concat.ts";
6
7Deno.test("concats two Uint8Arrays", () => {
8 const a = Uint8Array.from([0, 1, 2, 3]);
9 const b = Uint8Array.from([4, 5, 6, 7]);
10 const c = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7]);
11
12 assertEquals(concat([a, b]), c);
13});
14
15Deno.test("concats two Uint8Arrays with a length", () => {
16 const a = Uint8Array.from([0, 1, 2, 3]);
17 const b = Uint8Array.from([4, 5, 6, 7]);
18 const c = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7]);
19
20 assertEquals(concat([a, b], 8), c);
21});
22
23Deno.test("concat returns Uint8Array", () => {
24 const a = Uint8Array.from([0, 1, 2, 3]);
25 const b = alloc(10).fill(1);
26 const c = concat([a, b]);
27 const slice = c.slice();
28
29 // node slice is a copy operation, Uint8Array slice is a no-copy operation
30 assert(slice.buffer !== c.buffer);
31});