diff options
Diffstat (limited to 'std/bytes/test.ts')
-rw-r--r-- | std/bytes/test.ts | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/std/bytes/test.ts b/std/bytes/test.ts index c1609ebdc..3ded0cd85 100644 --- a/std/bytes/test.ts +++ b/std/bytes/test.ts @@ -1,9 +1,17 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { findIndex, findLastIndex, equal, hasPrefix, repeat } from "./mod.ts"; -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { + findIndex, + findLastIndex, + equal, + hasPrefix, + repeat, + concat +} from "./mod.ts"; +import { assertEquals, assertThrows, assert } from "../testing/asserts.ts"; +import { encode, decode } from "../strings/mod.ts"; -Deno.test(function bytesfindIndex1(): void { +Deno.test("[bytes] findIndex1", () => { const i = findIndex( new Uint8Array([1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 3]), new Uint8Array([0, 1, 2]) @@ -11,12 +19,12 @@ Deno.test(function bytesfindIndex1(): void { assertEquals(i, 2); }); -Deno.test(function bytesfindIndex2(): void { +Deno.test("[bytes] findIndex2", () => { const i = findIndex(new Uint8Array([0, 0, 1]), new Uint8Array([0, 1])); assertEquals(i, 1); }); -Deno.test(function bytesfindLastIndex1(): void { +Deno.test("[bytes] findLastIndex1", () => { const i = findLastIndex( new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 3]), new Uint8Array([0, 1, 2]) @@ -24,22 +32,22 @@ Deno.test(function bytesfindLastIndex1(): void { assertEquals(i, 3); }); -Deno.test(function bytesfindLastIndex2(): void { +Deno.test("[bytes] findLastIndex2", () => { const i = findLastIndex(new Uint8Array([0, 1, 1]), new Uint8Array([0, 1])); assertEquals(i, 0); }); -Deno.test(function bytesBytesequal(): void { +Deno.test("[bytes] equal", () => { const v = equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3])); assertEquals(v, true); }); -Deno.test(function byteshasPrefix(): void { +Deno.test("[bytes] hasPrefix", () => { const v = hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1])); assertEquals(v, true); }); -Deno.test(function bytesrepeat(): void { +Deno.test("[bytes] repeat", () => { // input / output / count / error message const repeatTestCase = [ ["", "", 0], @@ -71,3 +79,21 @@ Deno.test(function bytesrepeat(): void { } } }); + +Deno.test("[bytes] concat", () => { + const u1 = encode("Hello "); + const u2 = encode("World"); + const joined = concat(u1, u2); + assertEquals(decode(joined), "Hello World"); + assert(u1 !== joined); + assert(u2 !== joined); +}); + +Deno.test("[bytes] concat 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); +}); |