diff options
author | Ali Hasani <a.hassssani@gmail.com> | 2020-05-20 19:02:28 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-20 16:32:28 +0200 |
commit | ef14d62462d7f5bc2f091c3521409b4a16c5f87c (patch) | |
tree | 710cd2f647ffe2e7d013b420a9fde29134eecbc0 /std/bytes/test.ts | |
parent | 91d576aa5aee10f651ff10086aee90bdae659e87 (diff) |
feat(std/bytes): add hasSuffix and contains functions, update docs (#4801)
Diffstat (limited to 'std/bytes/test.ts')
-rw-r--r-- | std/bytes/test.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/std/bytes/test.ts b/std/bytes/test.ts index 13ac7a1fd..8b03de926 100644 --- a/std/bytes/test.ts +++ b/std/bytes/test.ts @@ -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]))); +}); |