deno.land / std@0.224.0 / bytes / repeat_test.ts

repeat_test.ts
View Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals, assertThrows } from "../assert/mod.ts";import { repeat } from "./repeat.ts";
Deno.test("repeat()", () => { // input / output / count / error message const repeatTestCase = [ ["", "", 0], ["", "", 1], ["", "", 1.1, "Count must be a non-negative integer"], ["", "", 2], ["", "", 0], ["-", "", 0], ["-", "-", -1, "Count must be a non-negative integer"], ["-", "----------", 10], ["abc ", "abc abc abc ", 3], ]; for (const [input, output, count, errMsg] of repeatTestCase) { if (errMsg) { assertThrows( () => { repeat(new TextEncoder().encode(input as string), count as number); }, Error, errMsg as string, ); } else { const newBytes = repeat( new TextEncoder().encode(input as string), count as number, );
assertEquals(new TextDecoder().decode(newBytes), output); } }});
std

Version Info

Tagged at
6 months ago