summaryrefslogtreecommitdiff
path: root/std/bytes/test.ts
diff options
context:
space:
mode:
authorYusuke Sakurai <kerokerokerop@gmail.com>2020-03-23 03:49:09 +0900
committerGitHub <noreply@github.com>2020-03-22 14:49:09 -0400
commitc337d2c4349abd710b1ab0d4de3f1041cd02715c (patch)
treed6677ed54142beb192bbb48b2dfc2a1b3e4690d5 /std/bytes/test.ts
parent07ea145ec4d1defe4481035432bb63234560ba8d (diff)
clean up textproto code in std (#4458)
- moved and renamed append() into bytes from ws and textproto - renamed textproto/readder_tests.ts -> textproto/test.ts
Diffstat (limited to 'std/bytes/test.ts')
-rw-r--r--std/bytes/test.ts44
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);
+});