deno.land / std@0.166.0 / encoding / base58_test.ts

base58_test.ts
نووسراو ببینە
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertThrows } from "../testing/asserts.ts";import { decode, encode } from "./base58.ts";
const testSetString = [ ["", ""], ["f", "2m"], ["ß", "FtS"], ["fo", "8o8"], ["foo", "bQbp"], ["foob", "3csAg9"], ["fooba", "CZJRhmz"], ["foobar", "t1Zv2yaZ"], ["Hello World!", "2NEpo7TZRRrLZSi2U"], [new Uint8Array([0, 0, 0, 40, 127, 180, 205]), "111233QC4"],];
const testSetBinary = testSetString.map(([data, b58]) => { if (typeof data === "string") { return [ new TextEncoder().encode(data), b58, ]; }
return [data, b58];}) as Array<[Uint8Array, string]>;
Deno.test("[encoding/base58] testBase58EncodeString", () => { for (const [input, output] of testSetString) { assertEquals(encode(input), output); }});
Deno.test("[encoding/base58] testBase58EncodeBinary", () => { for (const [input, output] of testSetBinary) { assertEquals(encode(input), output); }});
Deno.test("[encoding/base58] testBase58EncodeBinaryBuffer", () => { for (const [input, output] of testSetBinary) { assertEquals(encode(input.buffer), output); }});
Deno.test("[encoding/base58] testBase58DecodeBinary", () => { for (const [input, output] of testSetBinary) { const outputBinary = decode(output); assertEquals(outputBinary, input); }});
Deno.test("[encoding/base58] testBase58DecodeError", () => { assertThrows( () => decode("+2NEpo7TZRRrLZSi2U"), `Invalid base58 char at index 0 with value +`, );});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2447

Version Info

Tagged at
2 months ago