mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
chore(encoding): improve test coverage (#3971)
* chore(encoding): improve test coverage * fmt * tweak --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
parent
66e8a50e2d
commit
60f7b20c6c
@ -51,4 +51,11 @@ Deno.test("validateBinaryLike with invalid inputs", () => {
|
||||
TypeError,
|
||||
"The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type MyClass.",
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
validateBinaryLike(Object.create(null));
|
||||
},
|
||||
TypeError,
|
||||
"The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type object.",
|
||||
);
|
||||
});
|
||||
|
@ -192,3 +192,21 @@ Deno.test({
|
||||
assertEquals(encoded2, "F)YQ)");
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: `[encoding/ascii85] decode with default standard`,
|
||||
fn() {
|
||||
const tests = [
|
||||
["<~FCfN8Bl7P~>", "testing"],
|
||||
["<~A7]XsCgh3l~>", "denoland"],
|
||||
["<~@<5pmBfIsm@:X:cAH~>", "ascii85 adobe"],
|
||||
];
|
||||
|
||||
for (const [input, expect] of tests) {
|
||||
assertEquals(
|
||||
decodeAscii85(input),
|
||||
utf8encoder.encode(expect),
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Test cases copied from https://github.com/LinusU/base32-encode/blob/master/test.js
|
||||
// Copyright (c) 2016-2017 Linus Unnebäck. MIT license.
|
||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
import { assert, assertEquals } from "../assert/mod.ts";
|
||||
import { decodeBase32, encodeBase32 } from "./base32.ts";
|
||||
import { assert, assertEquals, assertExists } from "../assert/mod.ts";
|
||||
import { byteLength, decodeBase32, encodeBase32 } from "./base32.ts";
|
||||
|
||||
// Lifted from https://stackoverflow.com/questions/38987784
|
||||
const fromHexString = (hexString: string): Uint8Array =>
|
||||
@ -135,3 +135,27 @@ Deno.test({
|
||||
assert(errorCaught);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[encoding.base32] byteLength",
|
||||
fn() {
|
||||
const tests: [string, number][] = [
|
||||
["JBSWY3DPEBLW64TMMQ======", 11],
|
||||
["3X4A5PRBX4NR4EVGJROMNJ2LLWJN2===", 18],
|
||||
["WB2K5C467XQPC7ZXXTFN3YAG2A4ZS62ZZDX3AWW5", 25],
|
||||
["6L6CGGN5FFCXZTIB5DQZJ3U327UXFGFWMEG7JKYPHVN2UCZNPTHWTAU63N2O33Y=", 39],
|
||||
];
|
||||
|
||||
for (const [input, expect] of tests) {
|
||||
assertEquals(byteLength(input), expect);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[encoding.base32] encode very long text",
|
||||
fn() {
|
||||
const data = "a".repeat(16400);
|
||||
assertExists(encodeBase32(data));
|
||||
},
|
||||
});
|
||||
|
@ -54,3 +54,20 @@ Deno.test("[decoding/base64url] base64url.decode throws on invalid input", () =>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("[decoding/base64url] base64url.decode throws on illegal base64url string", () => {
|
||||
const testsetIllegalBase64url = [
|
||||
"w58De",
|
||||
"Zm9vYmFyy",
|
||||
"DPj8-ZD_DnwEg",
|
||||
"SGVsbG8gV29ybGQ-_",
|
||||
];
|
||||
|
||||
for (const illegalBase64url of testsetIllegalBase64url) {
|
||||
assertThrows(
|
||||
() => decodeBase64Url(illegalBase64url),
|
||||
TypeError,
|
||||
"Illegal base64url string!",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -95,8 +95,11 @@ Deno.test("VarInt encode manual", () => {
|
||||
[Uint8Array.of(255, 255, 255, 255, 255, 255, 255, 255, 255, 1), 10],
|
||||
);
|
||||
});
|
||||
Deno.test("VarInt encode overflow uint64", () => {
|
||||
assertThrows(() => encode(1e+30), RangeError, "overflows uint64");
|
||||
});
|
||||
Deno.test("VarInt encode overflow with negative", () => {
|
||||
assertThrows(() => encode(-1), RangeError);
|
||||
assertThrows(() => encode(-1), RangeError, "signed input given");
|
||||
});
|
||||
Deno.test("VarInt encode with offset", () => {
|
||||
let uint = new Uint8Array(3);
|
||||
|
Loading…
Reference in New Issue
Block a user