mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 20:59:10 +00:00
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
This commit is contained in:
parent
07ea145ec4
commit
c337d2c434
6 changed files with 227 additions and 235 deletions
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue