-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(bytes): document the cases being tested for equals/startsWith/en…
…dsWith (#6163)
- Loading branch information
1 parent
6637a20
commit 689fb69
Showing
3 changed files
with
105 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
|
||
import { assert } from "@std/assert"; | ||
import { endsWith } from "./ends_with.ts"; | ||
|
||
Deno.test("endsWith()", () => { | ||
const v = endsWith(new Uint8Array([0, 1, 2]), new Uint8Array([1, 2])); | ||
const v2 = endsWith(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1])); | ||
const v3 = endsWith(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1, 2, 3])); | ||
assert(v); | ||
assert(!v2); | ||
assert(!v3); | ||
Deno.test("endsWith()", async (t) => { | ||
await t.step("`true` where `source` and `suffix` are identical", () => { | ||
assert(endsWith( | ||
new Uint8Array([0, 1, 2, 3]), | ||
new Uint8Array([0, 1, 2, 3]), | ||
)); | ||
}); | ||
await t.step("`true` where `source` ends with `suffix`", () => { | ||
assert(endsWith( | ||
new Uint8Array([0, 1, 2]), | ||
new Uint8Array([1, 2]), | ||
)); | ||
}); | ||
await t.step("`false` with a common but only partial suffix", () => { | ||
assert( | ||
!endsWith( | ||
new Uint8Array([0, 1, 2]), | ||
new Uint8Array([0, 2]), | ||
), | ||
); | ||
}); | ||
await t.step("`false` where `suffix` is longer", () => { | ||
assert( | ||
!endsWith( | ||
new Uint8Array([0, 1, 2]), | ||
new Uint8Array([0, 2, 3, 4]), | ||
), | ||
); | ||
}); | ||
await t.step("`false` where `suffix` ends with `source`", () => { | ||
assert( | ||
!endsWith( | ||
new Uint8Array([1, 2]), | ||
new Uint8Array([0, 1, 2]), | ||
), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters