forked from denoland/std
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcat_test.ts
47 lines (43 loc) · 1.46 KB
/
concat_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals } from "@std/assert";
import { concat } from "./concat.ts";
Deno.test("concat()", () => {
const encoder = new TextEncoder();
const u1 = encoder.encode("Hello ");
const u2 = encoder.encode("World");
const joined = concat([u1, u2]);
assertEquals(new TextDecoder().decode(joined), "Hello World");
assert(u1 !== joined);
assert(u2 !== joined);
});
Deno.test("concat() handles empty arrays", () => {
const u1 = new Uint8Array();
const u2 = new Uint8Array();
const joined = concat([u1, u2]);
assertEquals(joined.byteLength, 0);
assert(u1 !== joined);
assert(u2 !== joined);
});
Deno.test("concat() handles multiple Uint8Array", () => {
const encoder = new TextEncoder();
const u1 = encoder.encode("Hello ");
const u2 = encoder.encode("W");
const u3 = encoder.encode("o");
const u4 = encoder.encode("r");
const u5 = encoder.encode("l");
const u6 = encoder.encode("d");
const joined = concat([u1, u2, u3, u4, u5, u6]);
assertEquals(new TextDecoder().decode(joined), "Hello World");
assert(u1 !== joined);
assert(u2 !== joined);
});
Deno.test("concat() handles an array of Uint8Array", () => {
const a = [
new Uint8Array([0, 1, 2, 3]),
new Uint8Array([4, 5, 6]),
new Uint8Array([7, 8, 9]),
];
const joined = concat(a);
const expected = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
assertEquals(joined, expected);
});