mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 12:49:10 +00:00
feat(std/bytes): add hasSuffix and contains functions, update docs (#4801)
This commit is contained in:
parent
91d576aa5a
commit
ef14d62462
2 changed files with 86 additions and 29 deletions
|
@ -5,8 +5,10 @@ import {
|
|||
findLastIndex,
|
||||
equal,
|
||||
hasPrefix,
|
||||
hasSuffix,
|
||||
repeat,
|
||||
concat,
|
||||
contains,
|
||||
} from "./mod.ts";
|
||||
import { assertEquals, assertThrows, assert } from "../testing/asserts.ts";
|
||||
import { encode, decode } from "../encoding/utf8.ts";
|
||||
|
@ -24,6 +26,11 @@ Deno.test("[bytes] findIndex2", () => {
|
|||
assertEquals(i, 1);
|
||||
});
|
||||
|
||||
Deno.test("[bytes] findIndex3", () => {
|
||||
const i = findIndex(encode("Deno"), encode("D"));
|
||||
assertEquals(i, 0);
|
||||
});
|
||||
|
||||
Deno.test("[bytes] findLastIndex1", () => {
|
||||
const i = findLastIndex(
|
||||
new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 3]),
|
||||
|
@ -47,6 +54,11 @@ Deno.test("[bytes] hasPrefix", () => {
|
|||
assertEquals(v, true);
|
||||
});
|
||||
|
||||
Deno.test("[bytes] hasSuffix", () => {
|
||||
const v = hasSuffix(new Uint8Array([0, 1, 2]), new Uint8Array([1, 2]));
|
||||
assertEquals(v, true);
|
||||
});
|
||||
|
||||
Deno.test("[bytes] repeat", () => {
|
||||
// input / output / count / error message
|
||||
const repeatTestCase = [
|
||||
|
@ -97,3 +109,11 @@ Deno.test("[bytes] concat empty arrays", () => {
|
|||
assert(u1 !== joined);
|
||||
assert(u2 !== joined);
|
||||
});
|
||||
|
||||
Deno.test("[bytes] contain", () => {
|
||||
const source = encode("deno.land");
|
||||
const pattern = encode("deno");
|
||||
assert(contains(source, pattern));
|
||||
|
||||
assert(contains(new Uint8Array([0, 1, 2, 3]), new Uint8Array([2, 3])));
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue