From 8a6a2a50f7ee17deadf8b7de5761c8f156885584 Mon Sep 17 00:00:00 2001 From: William Perron Date: Thu, 19 Nov 2020 21:59:45 -0500 Subject: docs(std): add missing jsdoc comments to exported functions (#8442) includes: - http/file_server.ts - testing/_diff.ts - testing/asserts.ts Relates to #7487 --- std/testing/_diff.ts | 5 +++++ std/testing/asserts.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'std/testing') diff --git a/std/testing/_diff.ts b/std/testing/_diff.ts index 5c84e891f..e6f631002 100644 --- a/std/testing/_diff.ts +++ b/std/testing/_diff.ts @@ -36,6 +36,11 @@ function createCommon(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(A: T[], B: T[]): Array> { const prefixCommon = createCommon(A, B); const suffixCommon = createCommon( diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts index eefa8c4f4..8548fb700 100644 --- a/std/testing/asserts.ts +++ b/std/testing/asserts.ts @@ -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 { return [Symbol.iterator, "size"].every((k) => k in (x as Set)); } +/** + * 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 { -- cgit v1.2.3