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

base64url_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
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertThrows } from "../testing/asserts.ts";import { decode, encode } from "./base64url.ts";
const testsetString = [ ["", ""], ["ß", "w58"], ["f", "Zg"], ["fo", "Zm8"], ["foo", "Zm9v"], ["foob", "Zm9vYg"], ["fooba", "Zm9vYmE"], ["foobar", "Zm9vYmFy"], [">?>d?ß", "Pj8-ZD_Dnw"],];
const testsetBinary = testsetString.map(([str, b64]) => [ new TextEncoder().encode(str), b64,]) as Array<[Uint8Array, string]>;
const testsetInvalid = [ "Pj8/ZD+Dnw", "PDw/Pz8+Pg", "Pj8/ZD+Dnw==", "PDw/Pz8+Pg==",];
Deno.test("[encoding/base64url] testBase64urlEncodeString", () => { for (const [input, output] of testsetString) { assertEquals(encode(input), output); }});
Deno.test("[encoding/base64url] testBase64urlEncodeBinary", () => { for (const [input, output] of testsetBinary) { assertEquals(encode(input), output); }});
Deno.test("[decoding/base64url] testBase64urlDecodeBinary", () => { for (const [input, output] of testsetBinary) { assertEquals(decode(output), input); }});
Deno.test("[decoding/base64url] base64url.decode throws on invalid input", () => { for (const invalidb64url of testsetInvalid) { assertThrows( () => decode(invalidb64url), TypeError, "invalid character", ); }});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2447

Version Info

Tagged at
2 months ago