summaryrefslogtreecommitdiff
path: root/std/testing
diff options
context:
space:
mode:
authorWilliam Perron <hey@wperron.io>2020-11-19 21:59:45 -0500
committerGitHub <noreply@github.com>2020-11-19 21:59:45 -0500
commit8a6a2a50f7ee17deadf8b7de5761c8f156885584 (patch)
tree7ed87bc916a12b9b58765b4ba6d64fdfd43e7a44 /std/testing
parente582796f42b96a940cba757a8a08573bc61aca0c (diff)
docs(std): add missing jsdoc comments to exported functions (#8442)
includes: - http/file_server.ts - testing/_diff.ts - testing/asserts.ts Relates to #7487
Diffstat (limited to 'std/testing')
-rw-r--r--std/testing/_diff.ts5
-rw-r--r--std/testing/asserts.ts18
2 files changed, 23 insertions, 0 deletions
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<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(
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<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 {