1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

docs(std): add missing jsdoc comments to exported functions (#8442)

includes:
- http/file_server.ts
- testing/_diff.ts
- testing/asserts.ts

Relates to #7487
This commit is contained in:
William Perron 2020-11-19 21:59:45 -05:00 committed by GitHub
parent e582796f42
commit 8a6a2a50f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -112,6 +112,11 @@ function fileLenToString(len: number): string {
return `${(len / base).toFixed(2)}${suffix[suffixIndex]}`;
}
/**
* Returns an HTTP Response with the requested file as the body
* @param req The server request context used to cleanup the file handle
* @param filePath Path of the file to serve
*/
export async function serveFile(
req: ServerRequest,
filePath: string,

View file

@ -36,6 +36,11 @@ function createCommon<T>(A: T[], B: T[], reverse?: boolean): T[] {
return common;
}
/**
* Renders the differences between the actual and expected values
* @param A Actual value
* @param B Expected value
*/
export function diff<T>(A: T[], B: T[]): Array<DiffResult<T>> {
const prefixCommon = createCommon(A, B);
const suffixCommon = createCommon(

View file

@ -19,6 +19,11 @@ export class AssertionError extends Error {
}
}
/**
* Converts the input into a string. Objects, Sets and Maps are sorted so as to
* make tests less flaky
* @param v Value to be formatted
*/
export function _format(v: unknown): string {
return globalThis.Deno
? Deno.inspect(v, {
@ -31,6 +36,10 @@ export function _format(v: unknown): string {
: `"${String(v).replace(/(?=["\\])/g, "\\")}"`;
}
/**
* Colors the output of assertion diffs
* @param diffType Difference type, either added or removed
*/
function createColor(diffType: DiffType): (s: string) => string {
switch (diffType) {
case DiffType.added:
@ -42,6 +51,10 @@ function createColor(diffType: DiffType): (s: string) => string {
}
}
/**
* Prefixes `+` or `-` in diff output
* @param diffType Difference type, either added or removed
*/
function createSign(diffType: DiffType): string {
switch (diffType) {
case DiffType.added:
@ -77,6 +90,11 @@ function isKeyedCollection(x: unknown): x is Set<unknown> {
return [Symbol.iterator, "size"].every((k) => k in (x as Set<unknown>));
}
/**
* Deep equality comparison used in assertions
* @param c actual value
* @param d expected value
*/
export function equal(c: unknown, d: unknown): boolean {
const seen = new Map();
return (function compare(a: unknown, b: unknown): boolean {