diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7ff001e003b..37594934abc3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,9 +94,6 @@ jobs: - name: Check Import paths in Docs run: "deno task lint:doc-imports" - - name: Check non-test assertions - run: deno task lint:check-assertions - - name: Spell-check uses: crate-ci/typos@master with: diff --git a/README.md b/README.md index 3e80320945fb..8fefb3aa6871 100644 --- a/README.md +++ b/README.md @@ -106,13 +106,6 @@ _For maintainers_: To release a new version a tag in the form of `x.y.z` should be added. -### Internal Assertions - -All internal non-test code, that is files that do not have `test` or `bench` in -the name, must use the assertion functions within `_utils/asserts.ts` and not -`testing/asserts.ts`. This is to create a separation of concerns between -internal and testing assertions. - ### Types Deno is moving away from non-native IO functions and interfaces in favor of the diff --git a/_tools/check_assertions.ts b/_tools/check_assertions.ts deleted file mode 100644 index 0efa3452cdcc..000000000000 --- a/_tools/check_assertions.ts +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { - createGraph, - Module, -} from "https://deno.land/x/deno_graph@0.37.1/mod.ts"; -import { walk } from "../fs/walk.ts"; - -const ROOT = new URL("../", import.meta.url); -const EXTS = [".mjs", ".ts"]; -const SKIP = [/(test|bench)/]; -const BAD_IMPORT = new URL("../testing/asserts.ts", import.meta.url); - -async function getFilePaths(): Promise { - const paths: string[] = []; - for await (const { path } of walk(ROOT, { exts: EXTS, skip: SKIP })) { - paths.push("file://" + path); - } - return paths; -} - -function hasBadImports({ dependencies }: Module): boolean { - return Object.values(dependencies!) - .some(({ code }) => code?.specifier?.includes(BAD_IMPORT.href)); -} - -async function getFilePathsWithBadImports(): Promise { - const paths = await getFilePaths(); - const { modules } = await createGraph(paths); - return modules.filter(hasBadImports) - .map(({ specifier }: Module) => specifier); -} - -const paths = await getFilePathsWithBadImports(); -if (paths.length > 0) { - console.error( - "Non-test code must use `_util/assert.ts` for assertions. Please fix:", - ); - paths.forEach((path) => console.error("- " + path)); - Deno.exit(1); -} diff --git a/_util/asserts.ts b/_util/asserts.ts deleted file mode 100644 index 3c5c346fe606..000000000000 --- a/_util/asserts.ts +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// This module is browser compatible. - -/** - * All internal non-test code, that is files that do not have `test` or `bench` in the name, must use the assertion functions within `_utils/asserts.ts` and not `testing/asserts.ts`. This is to create a separation of concerns between internal and testing assertions. - */ - -export class DenoStdInternalError extends Error { - constructor(message: string) { - super(message); - this.name = "DenoStdInternalError"; - } -} - -/** Make an assertion, if not `true`, then throw. */ -export function assert(expr: unknown, msg = ""): asserts expr { - if (!expr) { - throw new DenoStdInternalError(msg); - } -} - -/** Use this to assert unreachable code. */ -export function unreachable(): never { - throw new DenoStdInternalError("unreachable"); -} diff --git a/_util/asserts_test.ts b/_util/asserts_test.ts deleted file mode 100644 index 7f7c96d74f0d..000000000000 --- a/_util/asserts_test.ts +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, DenoStdInternalError, unreachable } from "./asserts.ts"; -import { assertThrows } from "../testing/asserts.ts"; - -Deno.test({ - name: "assert valid scenario", - fn() { - assert(true); - }, -}); - -Deno.test({ - name: "assert invalid scenario, no message", - fn() { - assertThrows(() => { - assert(false); - }, DenoStdInternalError); - }, -}); -Deno.test({ - name: "assert invalid scenario, with message", - fn() { - assertThrows( - () => { - assert(false, "Oops! Should be true"); - }, - DenoStdInternalError, - "Oops! Should be true", - ); - }, -}); - -Deno.test("assert unreachable", function () { - let didThrow = false; - try { - unreachable(); - } catch (e) { - assert(e instanceof DenoStdInternalError); - assert(e.message === "unreachable"); - didThrow = true; - } - assert(didThrow); -}); diff --git a/testing/_diff.ts b/_util/diff.ts similarity index 100% rename from testing/_diff.ts rename to _util/diff.ts diff --git a/testing/_diff_test.ts b/_util/diff_test.ts similarity index 98% rename from testing/_diff_test.ts rename to _util/diff_test.ts index b14194577d8c..d5117fd0c959 100644 --- a/testing/_diff_test.ts +++ b/_util/diff_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { diff, diffstr, DiffType } from "./_diff.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { diff, diffstr, DiffType } from "./diff.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test({ name: "empty", diff --git a/archive/tar.ts b/archive/tar.ts index d4ffaf934d91..f038c7d46520 100644 --- a/archive/tar.ts +++ b/archive/tar.ts @@ -42,7 +42,7 @@ export { type TarInfo, type TarMeta, type TarOptions }; import { MultiReader } from "../io/multi_reader.ts"; import { Buffer } from "../io/buffer.ts"; -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import { recordSize } from "./_common.ts"; const ustar = "ustar\u000000"; diff --git a/archive/tar_test.ts b/archive/tar_test.ts index 4d79b5b6d458..d269c577f9d6 100644 --- a/archive/tar_test.ts +++ b/archive/tar_test.ts @@ -9,7 +9,7 @@ * **to run this test** * deno run --allow-read archive/tar_test.ts */ -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { resolve } from "../path/mod.ts"; import { Tar } from "./tar.ts"; import { Untar } from "./untar.ts"; diff --git a/archive/untar_test.ts b/archive/untar_test.ts index 083f4c674239..b97063955807 100644 --- a/archive/untar_test.ts +++ b/archive/untar_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertExists } from "../testing/asserts.ts"; +import { assert, assertEquals, assertExists } from "../assert/mod.ts"; import { resolve } from "../path/mod.ts"; import { Tar, type TarMeta } from "./tar.ts"; import { TarEntry, type TarHeader, Untar } from "./untar.ts"; diff --git a/assert/_constants.ts b/assert/_constants.ts new file mode 100644 index 000000000000..1482010ee3fc --- /dev/null +++ b/assert/_constants.ts @@ -0,0 +1,2 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +export const CAN_NOT_DISPLAY = "[Cannot display]"; diff --git a/testing/_format.ts b/assert/_format.ts similarity index 100% rename from testing/_format.ts rename to assert/_format.ts diff --git a/testing/_format_test.ts b/assert/_format_test.ts similarity index 95% rename from testing/_format_test.ts rename to assert/_format_test.ts index 0b24edd9b325..747955596adf 100644 --- a/testing/_format_test.ts +++ b/assert/_format_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { green, red, stripColor } from "../fmt/colors.ts"; -import { assertEquals, assertThrows } from "./asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { format } from "./_format.ts"; Deno.test("assert diff formatting (strings)", () => { diff --git a/assert/assert.ts b/assert/assert.ts new file mode 100644 index 000000000000..3f868f4e0d2d --- /dev/null +++ b/assert/assert.ts @@ -0,0 +1,9 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +/** Make an assertion, error will be thrown if `expr` does not have truthy value. */ +export function assert(expr: unknown, msg = ""): asserts expr { + if (!expr) { + throw new AssertionError(msg); + } +} diff --git a/assert/assert_almost_equals.ts b/assert/assert_almost_equals.ts new file mode 100644 index 000000000000..4292730959a5 --- /dev/null +++ b/assert/assert_almost_equals.ts @@ -0,0 +1,41 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +/** + * Make an assertion that `actual` and `expected` are almost equal numbers through + * a given tolerance. It can be used to take into account IEEE-754 double-precision + * floating-point representation limitations. + * If the values are not almost equal then throw. + * + * @example + * ```ts + * import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/assert/mod.ts"; + * + * assertAlmostEquals(0.1, 0.2); + * + * // Using a custom tolerance value + * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); + * assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17)); + * ``` + */ +export function assertAlmostEquals( + actual: number, + expected: number, + tolerance = 1e-7, + msg?: string, +) { + if (Object.is(actual, expected)) { + return; + } + const delta = Math.abs(expected - actual); + if (delta <= tolerance) { + return; + } + + const msgSuffix = msg ? `: ${msg}` : "."; + const f = (n: number) => Number.isInteger(n) ? n : n.toExponential(); + throw new AssertionError( + `Expected actual: "${f(actual)}" to be close to "${f(expected)}": \ +delta "${f(delta)}" is greater than "${f(tolerance)}"${msgSuffix}`, + ); +} diff --git a/assert/assert_almost_equals_test.ts b/assert/assert_almost_equals_test.ts new file mode 100644 index 000000000000..940f8d1a4fcf --- /dev/null +++ b/assert/assert_almost_equals_test.ts @@ -0,0 +1,43 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertAlmostEquals, AssertionError, assertThrows } from "./mod.ts"; + +Deno.test("assert almost equals number", () => { + //Default precision + assertAlmostEquals(-0, +0); + assertAlmostEquals(Math.PI, Math.PI); + assertAlmostEquals(0.1 + 0.2, 0.3); + assertAlmostEquals(NaN, NaN); + assertAlmostEquals(Number.NaN, Number.NaN); + assertThrows(() => assertAlmostEquals(1, 2)); + assertThrows(() => assertAlmostEquals(1, 1.1)); + + //Higher precision + assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); + assertThrows( + () => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17), + AssertionError, + `Expected actual: "${ + ( + 0.1 + 0.2 + ).toExponential() + }" to be close to "${(0.3).toExponential()}"`, + ); + + //Special cases + assertAlmostEquals(Infinity, Infinity); + assertThrows( + () => assertAlmostEquals(0, Infinity), + AssertionError, + 'Expected actual: "0" to be close to "Infinity"', + ); + assertThrows( + () => assertAlmostEquals(-Infinity, +Infinity), + AssertionError, + 'Expected actual: "-Infinity" to be close to "Infinity"', + ); + assertThrows( + () => assertAlmostEquals(Infinity, NaN), + AssertionError, + 'Expected actual: "Infinity" to be close to "NaN"', + ); +}); diff --git a/assert/assert_array_includes.ts b/assert/assert_array_includes.ts new file mode 100644 index 000000000000..dd459482aece --- /dev/null +++ b/assert/assert_array_includes.ts @@ -0,0 +1,46 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { equal } from "./equal.ts"; +import { format } from "./_format.ts"; +import { AssertionError } from "./assertion_error.ts"; + +/** + * Make an assertion that `actual` includes the `expected` values. + * If not then an error will be thrown. + * + * Type parameter can be specified to ensure values under comparison have the same type. + * + * @example + * ```ts + * import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/assert/assert_array_includes.ts"; + * + * assertArrayIncludes([1, 2], [2]) + * ``` + */ +export function assertArrayIncludes( + actual: ArrayLike, + expected: ArrayLike, + msg?: string, +) { + const missing: unknown[] = []; + for (let i = 0; i < expected.length; i++) { + let found = false; + for (let j = 0; j < actual.length; j++) { + if (equal(expected[i], actual[j])) { + found = true; + break; + } + } + if (!found) { + missing.push(expected[i]); + } + } + if (missing.length === 0) { + return; + } + + const msgSuffix = msg ? `: ${msg}` : "."; + msg = `Expected actual: "${format(actual)}" to include: "${ + format(expected) + }"${msgSuffix}\nmissing: ${format(missing)}`; + throw new AssertionError(msg); +} diff --git a/assert/assert_array_includes_test.ts b/assert/assert_array_includes_test.ts new file mode 100644 index 000000000000..6d3734464f7c --- /dev/null +++ b/assert/assert_array_includes_test.ts @@ -0,0 +1,34 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertArrayIncludes, AssertionError, assertThrows } from "./mod.ts"; + +Deno.test("ArrayContains", function () { + const fixture = ["deno", "iz", "luv"]; + const fixtureObject = [{ deno: "luv" }, { deno: "Js" }]; + assertArrayIncludes(fixture, ["deno"]); + assertArrayIncludes(fixtureObject, [{ deno: "luv" }]); + assertArrayIncludes( + Uint8Array.from([1, 2, 3, 4]), + Uint8Array.from([1, 2, 3]), + ); + assertThrows( + () => assertArrayIncludes(fixtureObject, [{ deno: "node" }]), + AssertionError, + `Expected actual: "[ + { + deno: "luv", + }, + { + deno: "Js", + }, +]" to include: "[ + { + deno: "node", + }, +]". +missing: [ + { + deno: "node", + }, +]`, + ); +}); diff --git a/assert/assert_equals.ts b/assert/assert_equals.ts new file mode 100644 index 000000000000..53090bd854ea --- /dev/null +++ b/assert/assert_equals.ts @@ -0,0 +1,46 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { equal } from "./equal.ts"; +import { format } from "./_format.ts"; +import { AssertionError } from "./assertion_error.ts"; +import { red } from "../fmt/colors.ts"; +import { buildMessage, diff, diffstr } from "../_util/diff.ts"; +import { CAN_NOT_DISPLAY } from "./_constants.ts"; + +/** + * Make an assertion that `actual` and `expected` are equal, deeply. If not + * deeply equal, then throw. + * + * Type parameter can be specified to ensure values under comparison have the same type. + * + * @example + * ```ts + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; + * + * Deno.test("example", function (): void { + * assertEquals("world", "world"); + * assertEquals({ hello: "world" }, { hello: "world" }); + * }); + * ``` + */ +export function assertEquals(actual: T, expected: T, msg?: string) { + if (equal(actual, expected)) { + return; + } + const msgSuffix = msg ? `: ${msg}` : "."; + let message = `Values are not equal${msgSuffix}`; + + const actualString = format(actual); + const expectedString = format(expected); + try { + const stringDiff = (typeof actual === "string") && + (typeof expected === "string"); + const diffResult = stringDiff + ? diffstr(actual as string, expected as string) + : diff(actualString.split("\n"), expectedString.split("\n")); + const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n"); + message = `${message}\n${diffMsg}`; + } catch { + message = `${message}\n${red(CAN_NOT_DISPLAY)} + \n\n`; + } + throw new AssertionError(message); +} diff --git a/assert/assert_equals_test.ts b/assert/assert_equals_test.ts new file mode 100644 index 000000000000..5c12cf9fa337 --- /dev/null +++ b/assert/assert_equals_test.ts @@ -0,0 +1,212 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertEquals, AssertionError, assertThrows } from "./mod.ts"; +import { bold, gray, green, red, stripColor, yellow } from "../fmt/colors.ts"; + +const createHeader = (): string[] => [ + "", + "", + ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${ + green( + bold("Expected"), + ) + }`, + "", + "", +]; + +const added: (s: string) => string = (s: string): string => + green(bold(stripColor(s))); +const removed: (s: string) => string = (s: string): string => + red(bold(stripColor(s))); + +Deno.test({ + name: "pass case", + fn() { + assertEquals({ a: 10 }, { a: 10 }); + assertEquals(true, true); + assertEquals(10, 10); + assertEquals("abc", "abc"); + assertEquals({ a: 10, b: { c: "1" } }, { a: 10, b: { c: "1" } }); + assertEquals(new Date("invalid"), new Date("invalid")); + }, +}); + +Deno.test({ + name: "failed with number", + fn() { + assertThrows( + () => assertEquals(1, 2), + AssertionError, + [ + "Values are not equal.", + ...createHeader(), + removed(`- ${yellow("1")}`), + added(`+ ${yellow("2")}`), + "", + ].join("\n"), + ); + }, +}); + +Deno.test({ + name: "failed with number vs string", + fn() { + assertThrows( + () => assertEquals(1, "1"), + AssertionError, + [ + "Values are not equal.", + ...createHeader(), + removed(`- ${yellow("1")}`), + added(`+ "1"`), + ].join("\n"), + ); + }, +}); + +Deno.test({ + name: "failed with array", + fn() { + assertThrows( + () => assertEquals([1, "2", 3], ["1", "2", 3]), + AssertionError, + ` + [ +- 1, ++ "1", + "2", + 3, + ]`, + ); + }, +}); + +Deno.test({ + name: "failed with object", + fn() { + assertThrows( + () => assertEquals({ a: 1, b: "2", c: 3 }, { a: 1, b: 2, c: [3] }), + AssertionError, + ` + { + a: 1, ++ b: 2, ++ c: [ ++ 3, ++ ], +- b: "2", +- c: 3, + }`, + ); + }, +}); + +Deno.test({ + name: "failed with date", + fn() { + assertThrows( + () => + assertEquals( + new Date(2019, 0, 3, 4, 20, 1, 10), + new Date(2019, 0, 3, 4, 20, 1, 20), + ), + AssertionError, + [ + "Values are not equal.", + ...createHeader(), + removed(`- ${new Date(2019, 0, 3, 4, 20, 1, 10).toISOString()}`), + added(`+ ${new Date(2019, 0, 3, 4, 20, 1, 20).toISOString()}`), + "", + ].join("\n"), + ); + assertThrows( + () => + assertEquals(new Date("invalid"), new Date(2019, 0, 3, 4, 20, 1, 20)), + AssertionError, + [ + "Values are not equal.", + ...createHeader(), + removed(`- ${new Date("invalid")}`), + added(`+ ${new Date(2019, 0, 3, 4, 20, 1, 20).toISOString()}`), + "", + ].join("\n"), + ); + }, +}); + +Deno.test({ + name: "failed with custom msg", + fn() { + assertThrows( + () => assertEquals(1, 2, "CUSTOM MESSAGE"), + AssertionError, + [ + "Values are not equal: CUSTOM MESSAGE", + ...createHeader(), + removed(`- ${yellow("1")}`), + added(`+ ${yellow("2")}`), + "", + ].join("\n"), + ); + }, +}); + +Deno.test( + "assertEquals compares objects structurally if one object's constructor is undefined and the other is Object", + () => { + const a = Object.create(null); + a.prop = "test"; + const b = { + prop: "test", + }; + + assertEquals(a, b); + assertEquals(b, a); + }, +); + +Deno.test("assertEquals diff for differently ordered objects", () => { + assertThrows( + () => { + assertEquals( + { + aaaaaaaaaaaaaaaaaaaaaaaa: 0, + bbbbbbbbbbbbbbbbbbbbbbbb: 0, + ccccccccccccccccccccccc: 0, + }, + { + ccccccccccccccccccccccc: 1, + aaaaaaaaaaaaaaaaaaaaaaaa: 0, + bbbbbbbbbbbbbbbbbbbbbbbb: 0, + }, + ); + }, + AssertionError, + ` + { + aaaaaaaaaaaaaaaaaaaaaaaa: 0, + bbbbbbbbbbbbbbbbbbbbbbbb: 0, +- ccccccccccccccccccccccc: 0, ++ ccccccccccccccccccccccc: 1, + }`, + ); +}); + +Deno.test("assertEquals same Set with object keys", () => { + const data = [ + { + id: "_1p7ZED73OF98VbT1SzSkjn", + type: { id: "_ETGENUS" }, + name: "Thuja", + friendlyId: "g-thuja", + }, + { + id: "_567qzghxZmeQ9pw3q09bd3", + type: { id: "_ETGENUS" }, + name: "Pinus", + friendlyId: "g-pinus", + }, + ]; + assertEquals(data, data); + assertEquals(new Set(data), new Set(data)); +}); diff --git a/assert/assert_exists.ts b/assert/assert_exists.ts new file mode 100644 index 000000000000..3ce3600be706 --- /dev/null +++ b/assert/assert_exists.ts @@ -0,0 +1,18 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +/** + * Make an assertion that actual is not null or undefined. + * If not then throw. + */ +export function assertExists( + actual: T, + msg?: string, +): asserts actual is NonNullable { + if (actual === undefined || actual === null) { + const msgSuffix = msg ? `: ${msg}` : "."; + msg = + `Expected actual: "${actual}" to not be null or undefined${msgSuffix}`; + throw new AssertionError(msg); + } +} diff --git a/assert/assert_exists_test.ts b/assert/assert_exists_test.ts new file mode 100644 index 000000000000..dd33c278c429 --- /dev/null +++ b/assert/assert_exists_test.ts @@ -0,0 +1,35 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assert, assertEquals, assertExists, AssertionError } from "./mod.ts"; + +Deno.test("AssertExists", function () { + assertExists("Denosaurus"); + assertExists(false); + assertExists(0); + assertExists(""); + assertExists(-0); + assertExists(0); + assertExists(NaN); + + const value = new URLSearchParams({ value: "test" }).get("value"); + assertExists(value); + assertEquals(value.length, 4); + + let didThrow; + try { + assertExists(undefined); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + didThrow = false; + try { + assertExists(null); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); +}); diff --git a/assert/assert_false.ts b/assert/assert_false.ts new file mode 100644 index 000000000000..dc5d4446d1d9 --- /dev/null +++ b/assert/assert_false.ts @@ -0,0 +1,10 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +/** Make an assertion, error will be thrown if `expr` have truthy value. */ +type Falsy = false | 0 | 0n | "" | null | undefined; +export function assertFalse(expr: unknown, msg = ""): asserts expr is Falsy { + if (expr) { + throw new AssertionError(msg); + } +} diff --git a/assert/assert_false_test.ts b/assert/assert_false_test.ts new file mode 100644 index 000000000000..7dea2fada296 --- /dev/null +++ b/assert/assert_false_test.ts @@ -0,0 +1,18 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertFalse, assertThrows } from "./mod.ts"; + +Deno.test("Assert False with falsy values", () => { + assertFalse(false); + assertFalse(0); + assertFalse(""); + assertFalse(null); + assertFalse(undefined); +}); + +Deno.test("Assert False with truthy values", () => { + assertThrows(() => assertFalse(true)); + assertThrows(() => assertFalse(1)); + assertThrows(() => assertFalse("a")); + assertThrows(() => assertFalse({})); + assertThrows(() => assertFalse([])); +}); diff --git a/assert/assert_instance_of.ts b/assert/assert_instance_of.ts new file mode 100644 index 000000000000..66ce29e6e076 --- /dev/null +++ b/assert/assert_instance_of.ts @@ -0,0 +1,47 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +// deno-lint-ignore no-explicit-any +type AnyConstructor = new (...args: any[]) => any; +type GetConstructorType = T extends // deno-lint-ignore no-explicit-any +new (...args: any) => infer C ? C + : never; + +/** + * Make an assertion that `obj` is an instance of `type`. + * If not then throw. + */ +export function assertInstanceOf( + actual: unknown, + expectedType: T, + msg = "", +): asserts actual is GetConstructorType { + if (actual instanceof expectedType) return; + + const msgSuffix = msg ? `: ${msg}` : "."; + const expectedTypeStr = expectedType.name; + + let actualTypeStr = ""; + if (actual === null) { + actualTypeStr = "null"; + } else if (actual === undefined) { + actualTypeStr = "undefined"; + } else if (typeof actual === "object") { + actualTypeStr = actual.constructor?.name ?? "Object"; + } else { + actualTypeStr = typeof actual; + } + + if (expectedTypeStr == actualTypeStr) { + msg = + `Expected object to be an instance of "${expectedTypeStr}"${msgSuffix}`; + } else if (actualTypeStr == "function") { + msg = + `Expected object to be an instance of "${expectedTypeStr}" but was not an instanced object${msgSuffix}`; + } else { + msg = + `Expected object to be an instance of "${expectedTypeStr}" but was "${actualTypeStr}"${msgSuffix}`; + } + + throw new AssertionError(msg); +} diff --git a/assert/assert_instance_of_test.ts b/assert/assert_instance_of_test.ts new file mode 100644 index 000000000000..16db51bedd51 --- /dev/null +++ b/assert/assert_instance_of_test.ts @@ -0,0 +1,116 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertInstanceOf, AssertionError, assertThrows } from "./mod.ts"; + +Deno.test({ + name: "assertInstanceOf", + fn() { + class TestClass1 {} + class TestClass2 {} + class TestClass3 {} + + // Regular types + assertInstanceOf(new Date(), Date); + assertInstanceOf(new Number(), Number); + assertInstanceOf(Promise.resolve(), Promise); + assertInstanceOf(new TestClass1(), TestClass1); + + // Throwing cases + assertThrows( + () => assertInstanceOf(new Date(), RegExp), + AssertionError, + `Expected object to be an instance of "RegExp" but was "Date".`, + ); + assertThrows( + () => assertInstanceOf(5, Date), + AssertionError, + `Expected object to be an instance of "Date" but was "number".`, + ); + assertThrows( + () => assertInstanceOf(new TestClass1(), TestClass2), + AssertionError, + `Expected object to be an instance of "TestClass2" but was "TestClass1".`, + ); + + // Custom message + assertThrows( + () => assertInstanceOf(new Date(), RegExp, "Custom message"), + AssertionError, + "Custom message", + ); + + // Edge cases + assertThrows( + () => assertInstanceOf(5, Number), + AssertionError, + `Expected object to be an instance of "Number" but was "number".`, + ); + + let TestClassWithSameName: new () => unknown; + { + class TestClass3 {} + TestClassWithSameName = TestClass3; + } + assertThrows( + () => assertInstanceOf(new TestClassWithSameName(), TestClass3), + AssertionError, + `Expected object to be an instance of "TestClass3".`, + ); + + assertThrows( + () => assertInstanceOf(TestClass1, TestClass1), + AssertionError, + `Expected object to be an instance of "TestClass1" but was not an instanced object.`, + ); + assertThrows( + () => assertInstanceOf(() => {}, TestClass1), + AssertionError, + `Expected object to be an instance of "TestClass1" but was not an instanced object.`, + ); + assertThrows( + () => assertInstanceOf(null, TestClass1), + AssertionError, + `Expected object to be an instance of "TestClass1" but was "null".`, + ); + assertThrows( + () => assertInstanceOf(undefined, TestClass1), + AssertionError, + `Expected object to be an instance of "TestClass1" but was "undefined".`, + ); + assertThrows( + () => assertInstanceOf({}, TestClass1), + AssertionError, + `Expected object to be an instance of "TestClass1" but was "Object".`, + ); + assertThrows( + () => assertInstanceOf(Object.create(null), TestClass1), + AssertionError, + `Expected object to be an instance of "TestClass1" but was "Object".`, + ); + + // Test TypeScript types functionality, wrapped in a function that never runs + // deno-lint-ignore no-unused-vars + function typeScriptTests() { + class ClassWithProperty { + property = "prop1"; + } + const testInstance = new ClassWithProperty() as unknown; + + // @ts-expect-error: `testInstance` is `unknown` so setting its property before `assertInstanceOf` should give a type error. + testInstance.property = "prop2"; + + assertInstanceOf(testInstance, ClassWithProperty); + + // Now `testInstance` should be of type `ClassWithProperty` + testInstance.property = "prop3"; + + let x = 5 as unknown; + + // @ts-expect-error: `x` is `unknown` so adding to it shouldn't work + x += 5; + assertInstanceOf(x, Number); + + // @ts-expect-error: `x` is now `Number` rather than `number`, so this should still give a type error. + x += 5; + } + }, +}); diff --git a/assert/assert_is_error.ts b/assert/assert_is_error.ts new file mode 100644 index 000000000000..985e482e9fb1 --- /dev/null +++ b/assert/assert_is_error.ts @@ -0,0 +1,39 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; +import { stripColor } from "../fmt/colors.ts"; + +/** + * Make an assertion that `error` is an `Error`. + * If not then an error will be thrown. + * An error class and a string that should be included in the + * error message can also be asserted. + */ +export function assertIsError( + error: unknown, + // deno-lint-ignore no-explicit-any + ErrorClass?: new (...args: any[]) => E, + msgIncludes?: string, + msg?: string, +): asserts error is E { + const msgSuffix = msg ? `: ${msg}` : "."; + if (error instanceof Error === false) { + throw new AssertionError( + `Expected "error" to be an Error object${msgSuffix}}`, + ); + } + if (ErrorClass && !(error instanceof ErrorClass)) { + msg = `Expected error to be instance of "${ErrorClass.name}", but was "${ + typeof error === "object" ? error?.constructor?.name : "[not an object]" + }"${msgSuffix}`; + throw new AssertionError(msg); + } + if ( + msgIncludes && (!(error instanceof Error) || + !stripColor(error.message).includes(stripColor(msgIncludes))) + ) { + msg = `Expected error message to include "${msgIncludes}", but got "${ + error instanceof Error ? error.message : "[not an Error]" + }"${msgSuffix}`; + throw new AssertionError(msg); + } +} diff --git a/assert/assert_is_error_test.ts b/assert/assert_is_error_test.ts new file mode 100644 index 000000000000..2ca4ed9be39a --- /dev/null +++ b/assert/assert_is_error_test.ts @@ -0,0 +1,37 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError, assertIsError, assertThrows } from "./mod.ts"; + +Deno.test("Assert Is Error Non-Error Fail", () => { + assertThrows( + () => assertIsError("Panic!", undefined, "Panic!"), + AssertionError, + `Expected "error" to be an Error object.`, + ); + + assertThrows( + () => assertIsError(null), + AssertionError, + `Expected "error" to be an Error object.`, + ); + + assertThrows( + () => assertIsError(undefined), + AssertionError, + `Expected "error" to be an Error object.`, + ); +}); + +Deno.test("Assert Is Error Parent Error", () => { + assertIsError(new AssertionError("Fail!"), Error, "Fail!"); +}); + +Deno.test("Assert Is Error with custom Error", () => { + class CustomError extends Error {} + class AnotherCustomError extends Error {} + assertIsError(new CustomError("failed"), CustomError, "fail"); + assertThrows( + () => assertIsError(new AnotherCustomError("failed"), CustomError, "fail"), + AssertionError, + 'Expected error to be instance of "CustomError", but was "AnotherCustomError".', + ); +}); diff --git a/assert/assert_match.ts b/assert/assert_match.ts new file mode 100644 index 000000000000..253f49b61975 --- /dev/null +++ b/assert/assert_match.ts @@ -0,0 +1,18 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +/** + * Make an assertion that `actual` match RegExp `expected`. If not + * then throw. + */ +export function assertMatch( + actual: string, + expected: RegExp, + msg?: string, +) { + if (!expected.test(actual)) { + const msgSuffix = msg ? `: ${msg}` : "."; + msg = `Expected actual: "${actual}" to match: "${expected}"${msgSuffix}`; + throw new AssertionError(msg); + } +} diff --git a/assert/assert_match_test.ts b/assert/assert_match_test.ts new file mode 100644 index 000000000000..0ddda8d19f44 --- /dev/null +++ b/assert/assert_match_test.ts @@ -0,0 +1,21 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assert, AssertionError, assertMatch } from "./mod.ts"; + +Deno.test("AssertStringMatching", function () { + assertMatch("foobar@deno.com", RegExp(/[a-zA-Z]+@[a-zA-Z]+.com/)); +}); + +Deno.test("AssertStringMatchingThrows", function () { + let didThrow = false; + try { + assertMatch("Denosaurus from Jurassic", RegExp(/Raptor/)); + } catch (e) { + assert(e instanceof AssertionError); + assert( + e.message === + `Expected actual: "Denosaurus from Jurassic" to match: "/Raptor/".`, + ); + didThrow = true; + } + assert(didThrow); +}); diff --git a/assert/assert_not_equals.ts b/assert/assert_not_equals.ts new file mode 100644 index 000000000000..1777f65de9fb --- /dev/null +++ b/assert/assert_not_equals.ts @@ -0,0 +1,38 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { equal } from "./equal.ts"; +import { AssertionError } from "./assertion_error.ts"; + +/** + * Make an assertion that `actual` and `expected` are not equal, deeply. + * If not then throw. + * + * Type parameter can be specified to ensure values under comparison have the same type. + * + * @example + * ```ts + * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_equals.ts"; + * + * assertNotEquals(1, 2) + * ``` + */ +export function assertNotEquals(actual: T, expected: T, msg?: string) { + if (!equal(actual, expected)) { + return; + } + let actualString: string; + let expectedString: string; + try { + actualString = String(actual); + } catch { + actualString = "[Cannot display]"; + } + try { + expectedString = String(expected); + } catch { + expectedString = "[Cannot display]"; + } + const msgSuffix = msg ? `: ${msg}` : "."; + throw new AssertionError( + `Expected actual: ${actualString} not to be: ${expectedString}${msgSuffix}`, + ); +} diff --git a/assert/assert_not_equals_test.ts b/assert/assert_not_equals_test.ts new file mode 100644 index 000000000000..0085aee7c293 --- /dev/null +++ b/assert/assert_not_equals_test.ts @@ -0,0 +1,28 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { + assert, + assertEquals, + AssertionError, + assertNotEquals, +} from "./mod.ts"; + +Deno.test("NotEquals", function () { + const a = { foo: "bar" }; + const b = { bar: "foo" }; + assertNotEquals(a, b); + assertNotEquals("Denosaurus", "Tyrannosaurus"); + assertNotEquals( + new Date(2019, 0, 3, 4, 20, 1, 10), + new Date(2019, 0, 3, 4, 20, 1, 20), + ); + assertNotEquals(new Date("invalid"), new Date(2019, 0, 3, 4, 20, 1, 20)); + let didThrow; + try { + assertNotEquals("Raptor", "Raptor"); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); +}); diff --git a/assert/assert_not_instance_of.ts b/assert/assert_not_instance_of.ts new file mode 100644 index 000000000000..14571132cf30 --- /dev/null +++ b/assert/assert_not_instance_of.ts @@ -0,0 +1,18 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertFalse } from "./assert_false.ts"; + +/** + * Make an assertion that `obj` is not an instance of `type`. + * If so, then throw. + */ +export function assertNotInstanceOf( + actual: A, + // deno-lint-ignore no-explicit-any + unexpectedType: new (...args: any[]) => T, + msg?: string, +): asserts actual is Exclude { + const msgSuffix = msg ? `: ${msg}` : "."; + msg = + `Expected object to not be an instance of "${typeof unexpectedType}"${msgSuffix}`; + assertFalse(actual instanceof unexpectedType, msg); +} diff --git a/assert/assert_not_instance_of_test.ts b/assert/assert_not_instance_of_test.ts new file mode 100644 index 000000000000..e24eb05b3320 --- /dev/null +++ b/assert/assert_not_instance_of_test.ts @@ -0,0 +1,11 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertNotInstanceOf } from "./mod.ts"; + +Deno.test({ + name: "assertNotInstanceOf", + fn() { + assertNotInstanceOf("not a number", Number); + assertNotInstanceOf(42, String); + assertNotInstanceOf(new URL("http://example.com"), Boolean); + }, +}); diff --git a/assert/assert_not_match.ts b/assert/assert_not_match.ts new file mode 100644 index 000000000000..42cc6bfd1620 --- /dev/null +++ b/assert/assert_not_match.ts @@ -0,0 +1,19 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +/** + * Make an assertion that `actual` not match RegExp `expected`. If match + * then throw. + */ +export function assertNotMatch( + actual: string, + expected: RegExp, + msg?: string, +) { + if (expected.test(actual)) { + const msgSuffix = msg ? `: ${msg}` : "."; + msg = + `Expected actual: "${actual}" to not match: "${expected}"${msgSuffix}`; + throw new AssertionError(msg); + } +} diff --git a/assert/assert_not_match_test.ts b/assert/assert_not_match_test.ts new file mode 100644 index 000000000000..e0584d84f22d --- /dev/null +++ b/assert/assert_not_match_test.ts @@ -0,0 +1,21 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assert, AssertionError, assertNotMatch } from "./mod.ts"; + +Deno.test("AssertStringNotMatching", function () { + assertNotMatch("foobar.deno.com", RegExp(/[a-zA-Z]+@[a-zA-Z]+.com/)); +}); + +Deno.test("AssertStringNotMatchingThrows", function () { + let didThrow = false; + try { + assertNotMatch("Denosaurus from Jurassic", RegExp(/from/)); + } catch (e) { + assert(e instanceof AssertionError); + assert( + e.message === + `Expected actual: "Denosaurus from Jurassic" to not match: "/from/".`, + ); + didThrow = true; + } + assert(didThrow); +}); diff --git a/assert/assert_not_strict_equals.ts b/assert/assert_not_strict_equals.ts new file mode 100644 index 000000000000..8676d6a005d4 --- /dev/null +++ b/assert/assert_not_strict_equals.ts @@ -0,0 +1,30 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; +import { format } from "./_format.ts"; + +/** + * Make an assertion that `actual` and `expected` are not strictly equal. + * If the values are strictly equal then throw. + * + * ```ts + * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_not_strict_equals.ts"; + * + * assertNotStrictEquals(1, 1) + * ``` + */ +export function assertNotStrictEquals( + actual: T, + expected: T, + msg?: string, +) { + if (!Object.is(actual, expected)) { + return; + } + + const msgSuffix = msg ? `: ${msg}` : "."; + throw new AssertionError( + `Expected "actual" to be strictly unequal to: ${ + format(actual) + }${msgSuffix}\n`, + ); +} diff --git a/assert/assert_not_strict_equals_test.ts b/assert/assert_not_strict_equals_test.ts new file mode 100644 index 000000000000..49fc24d23ecc --- /dev/null +++ b/assert/assert_not_strict_equals_test.ts @@ -0,0 +1,29 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError, assertNotStrictEquals, assertThrows } from "./mod.ts"; + +Deno.test({ + name: "strictly unequal pass case", + fn() { + assertNotStrictEquals(true, false); + assertNotStrictEquals(10, 11); + assertNotStrictEquals("abc", "xyz"); + assertNotStrictEquals(1, "1"); + assertNotStrictEquals(-0, +0); + + const xs = [1, false, "foo"]; + const ys = [1, true, "bar"]; + assertNotStrictEquals(xs, ys); + + const x = { a: 1 }; + const y = { a: 2 }; + assertNotStrictEquals(x, y); + }, +}); + +Deno.test({ + name: "strictly unequal fail case", + fn() { + assertThrows(() => assertNotStrictEquals(1, 1), AssertionError); + assertThrows(() => assertNotStrictEquals(NaN, NaN), AssertionError); + }, +}); diff --git a/assert/assert_object_match.ts b/assert/assert_object_match.ts new file mode 100644 index 000000000000..8acb1242d72b --- /dev/null +++ b/assert/assert_object_match.ts @@ -0,0 +1,92 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertEquals } from "./assert_equals.ts"; + +/** + * Make an assertion that `actual` object is a subset of `expected` object, deeply. + * If not, then throw. + */ +export function assertObjectMatch( + // deno-lint-ignore no-explicit-any + actual: Record, + expected: Record, + msg?: string, +) { + type loose = Record; + + function filter(a: loose, b: loose) { + const seen = new WeakMap(); + return fn(a, b); + + function fn(a: loose, b: loose): loose { + // Prevent infinite loop with circular references with same filter + if ((seen.has(a)) && (seen.get(a) === b)) { + return a; + } + try { + seen.set(a, b); + } catch (err) { + if (err instanceof TypeError) { + throw new TypeError( + `Cannot assertObjectMatch ${ + a === null ? null : `type ${typeof a}` + }`, + ); + } else throw err; + } + // Filter keys and symbols which are present in both actual and expected + const filtered = {} as loose; + const entries = [ + ...Object.getOwnPropertyNames(a), + ...Object.getOwnPropertySymbols(a), + ] + .filter((key) => key in b) + .map((key) => [key, a[key as string]]) as Array<[string, unknown]>; + for (const [key, value] of entries) { + // On array references, build a filtered array and filter nested objects inside + if (Array.isArray(value)) { + const subset = (b as loose)[key]; + if (Array.isArray(subset)) { + filtered[key] = fn({ ...value }, { ...subset }); + continue; + } + } // On regexp references, keep value as it to avoid loosing pattern and flags + else if (value instanceof RegExp) { + filtered[key] = value; + continue; + } // On nested objects references, build a filtered object recursively + else if (typeof value === "object" && value !== null) { + const subset = (b as loose)[key]; + if ((typeof subset === "object") && (subset)) { + // When both operands are maps, build a filtered map with common keys and filter nested objects inside + if ((value instanceof Map) && (subset instanceof Map)) { + filtered[key] = new Map( + [...value].filter(([k]) => subset.has(k)).map(( + [k, v], + ) => [k, typeof v === "object" ? fn(v, subset.get(k)) : v]), + ); + continue; + } + // When both operands are set, build a filtered set with common values + if ((value instanceof Set) && (subset instanceof Set)) { + filtered[key] = new Set([...value].filter((v) => subset.has(v))); + continue; + } + filtered[key] = fn(value as loose, subset as loose); + continue; + } + } + filtered[key] = value; + } + return filtered; + } + } + return assertEquals( + // get the intersection of "actual" and "expected" + // side effect: all the instances' constructor field is "Object" now. + filter(actual, expected), + // set (nested) instances' constructor field to be "Object" without changing expected value. + // see https://github.com/denoland/deno_std/pull/1419 + filter(expected, expected), + msg, + ); +} diff --git a/assert/assert_object_match_test.ts b/assert/assert_object_match_test.ts new file mode 100644 index 000000000000..78421edfc6f4 --- /dev/null +++ b/assert/assert_object_match_test.ts @@ -0,0 +1,339 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { + assert, + assertEquals, + AssertionError, + assertObjectMatch, + assertThrows, +} from "./mod.ts"; + +Deno.test("AssertObjectMatching", function () { + const sym = Symbol("foo"); + const a = { foo: true, bar: false }; + const b = { ...a, baz: a }; + const c = { ...b, qux: b }; + const d = { corge: c, grault: c }; + const e = { foo: true } as { [key: string]: unknown }; + e.bar = e; + const f = { [sym]: true, bar: false }; + interface r { + foo: boolean; + bar: boolean; + } + const g: r = { foo: true, bar: false }; + const h = { foo: [1, 2, 3], bar: true }; + const i = { foo: [a, e], bar: true }; + const j = { foo: [[1, 2, 3]], bar: true }; + const k = { foo: [[1, [2, [3]]]], bar: true }; + const l = { foo: [[1, [2, [a, e, j, k]]]], bar: true }; + const m = { foo: /abc+/i, bar: [/abc/g, /abc/m] }; + const n = { + foo: new Set(["foo", "bar"]), + bar: new Map([ + ["foo", 1], + ["bar", 2], + ]), + baz: new Map([ + ["a", a], + ["b", b], + ]), + }; + + // Simple subset + assertObjectMatch(a, { + foo: true, + }); + // Subset with another subset + assertObjectMatch(b, { + foo: true, + baz: { bar: false }, + }); + // Subset with multiple subsets + assertObjectMatch(c, { + foo: true, + baz: { bar: false }, + qux: { + baz: { foo: true }, + }, + }); + // Subset with same object reference as subset + assertObjectMatch(d, { + corge: { + foo: true, + qux: { bar: false }, + }, + grault: { + bar: false, + qux: { foo: true }, + }, + }); + // Subset with circular reference + assertObjectMatch(e, { + foo: true, + bar: { + bar: { + bar: { + foo: true, + }, + }, + }, + }); + // Subset with interface + assertObjectMatch(g, { bar: false }); + // Subset with same symbol + assertObjectMatch(f, { + [sym]: true, + }); + // Subset with array inside + assertObjectMatch(h, { foo: [] }); + assertObjectMatch(h, { foo: [1, 2] }); + assertObjectMatch(h, { foo: [1, 2, 3] }); + assertObjectMatch(i, { foo: [{ bar: false }] }); + assertObjectMatch(i, { + foo: [{ bar: false }, { bar: { bar: { bar: { foo: true } } } }], + }); + // Subset with nested array inside + assertObjectMatch(j, { foo: [[1, 2, 3]] }); + assertObjectMatch(k, { foo: [[1, [2, [3]]]] }); + assertObjectMatch(l, { foo: [[1, [2, [a, e, j, k]]]] }); + // Regexp + assertObjectMatch(m, { foo: /abc+/i }); + assertObjectMatch(m, { bar: [/abc/g, /abc/m] }); + //Built-in data structures + assertObjectMatch(n, { foo: new Set(["foo"]) }); + assertObjectMatch(n, { bar: new Map([["bar", 2]]) }); + assertObjectMatch(n, { baz: new Map([["b", b]]) }); + assertObjectMatch(n, { baz: new Map([["b", { foo: true }]]) }); + + // Missing key + { + let didThrow; + try { + assertObjectMatch( + { + foo: true, + }, + { + foo: true, + bar: false, + }, + ); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + } + // Simple subset + { + let didThrow; + try { + assertObjectMatch(a, { + foo: false, + }); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + } + // Subset with another subset + { + let didThrow; + try { + assertObjectMatch(b, { + foo: true, + baz: { bar: true }, + }); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + } + // Subset with multiple subsets + { + let didThrow; + try { + assertObjectMatch(c, { + foo: true, + baz: { bar: false }, + qux: { + baz: { foo: false }, + }, + }); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + } + // Subset with same object reference as subset + { + let didThrow; + try { + assertObjectMatch(d, { + corge: { + foo: true, + qux: { bar: true }, + }, + grault: { + bar: false, + qux: { foo: false }, + }, + }); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + } + // Subset with circular reference + { + let didThrow; + try { + assertObjectMatch(e, { + foo: true, + bar: { + bar: { + bar: { + foo: false, + }, + }, + }, + }); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + } + // Subset with symbol key but with string key subset + { + let didThrow; + try { + assertObjectMatch(f, { + foo: true, + }); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + } + // Subset with array inside but doesn't match key subset + { + let didThrow; + try { + assertObjectMatch(i, { + foo: [1, 2, 3, 4], + }); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + } + { + let didThrow; + try { + assertObjectMatch(i, { + foo: [{ bar: true }, { foo: false }], + }); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); + } + // actual/expected value as instance of class + { + class A { + a: number; + constructor(a: number) { + this.a = a; + } + } + assertObjectMatch({ test: new A(1) }, { test: { a: 1 } }); + assertObjectMatch({ test: { a: 1 } }, { test: { a: 1 } }); + assertObjectMatch({ test: { a: 1 } }, { test: new A(1) }); + assertObjectMatch({ test: new A(1) }, { test: new A(1) }); + } + { + // actual/expected contains same instance of Map/TypedArray/etc + const body = new Uint8Array([0, 1, 2]); + assertObjectMatch({ body, foo: "foo" }, { body }); + } + { + // match subsets of arrays + assertObjectMatch( + { positions: [[1, 2, 3, 4]] }, + { + positions: [[1, 2, 3]], + }, + ); + } + //Regexp + assertThrows(() => assertObjectMatch(m, { foo: /abc+/ }), AssertionError); + assertThrows(() => assertObjectMatch(m, { foo: /abc*/i }), AssertionError); + assertThrows( + () => assertObjectMatch(m, { bar: [/abc/m, /abc/g] }), + AssertionError, + ); + //Built-in data structures + assertThrows( + () => assertObjectMatch(n, { foo: new Set(["baz"]) }), + AssertionError, + ); + assertThrows( + () => assertObjectMatch(n, { bar: new Map([["bar", 3]]) }), + AssertionError, + ); + assertThrows( + () => assertObjectMatch(n, { baz: new Map([["a", { baz: true }]]) }), + AssertionError, + ); + // null in the first argument throws an assertion error, rather than a TypeError: Invalid value used as weak map key + assertThrows( + () => assertObjectMatch({ foo: null }, { foo: { bar: 42 } }), + AssertionError, + ); + assertObjectMatch({ foo: null, bar: null }, { foo: null }); + assertObjectMatch({ foo: undefined, bar: null }, { foo: undefined }); + assertThrows( + () => assertObjectMatch({ foo: undefined, bar: null }, { foo: null }), + AssertionError, + ); + // Non mapable primative types should throw a readable type error + assertThrows( + // @ts-expect-error Argument of type 'null' is not assignable to parameter of type 'Record' + () => assertObjectMatch(null, { foo: 42 }), + TypeError, + "assertObjectMatch", + ); + // @ts-expect-error Argument of type 'null' is not assignable to parameter of type 'Record' + assertThrows(() => assertObjectMatch(null, { foo: 42 }), TypeError, "null"); // since typeof null is "object", want to make sure user knows the bad value is "null" + assertThrows( + // @ts-expect-error Argument of type 'undefined' is not assignable to parameter of type 'Record' + () => assertObjectMatch(undefined, { foo: 42 }), + TypeError, + "assertObjectMatch", + ); + // @ts-expect-error Argument of type 'number' is not assignable to parameter of type 'Record' + assertThrows(() => assertObjectMatch(21, 42), TypeError, "assertObjectMatch"); + assertThrows( + // @ts-expect-error Argument of type 'string' is not assignable to parameter of type 'Record' + () => assertObjectMatch("string", "string"), + TypeError, + "assertObjectMatch", + ); +}); diff --git a/assert/assert_rejects.ts b/assert/assert_rejects.ts new file mode 100644 index 000000000000..d55d834ac934 --- /dev/null +++ b/assert/assert_rejects.ts @@ -0,0 +1,144 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; +import { assertIsError } from "./assert_is_error.ts"; + +/** + * Executes a function which returns a promise, expecting it to reject. + * + * @example + * ```ts + * import { assertRejects } from "https://deno.land/std@$STD_VERSION/assert/assert_rejects.ts"; + * + * Deno.test("doesThrow", async function () { + * await assertRejects( + * async () => { + * throw new TypeError("hello world!"); + * }, + * ); + * await assertRejects( + * async () => { + * return Promise.reject(new Error()); + * }, + * ); + * }); + * + * // This test will not pass. + * Deno.test("fails", async function () { + * await assertRejects( + * async () => { + * console.log("Hello world"); + * }, + * ); + * }); + * ``` + */ +export function assertRejects( + fn: () => PromiseLike, + msg?: string, +): Promise; +/** + * Executes a function which returns a promise, expecting it to reject. + * If it does not, then it throws. An error class and a string that should be + * included in the error message can also be asserted. + * + * @example + * ```ts + * import { assertRejects } from "https://deno.land/std@$STD_VERSION/assert/assert_rejects.ts"; + * + * Deno.test("doesThrow", async function () { + * await assertRejects(async () => { + * throw new TypeError("hello world!"); + * }, TypeError); + * await assertRejects( + * async () => { + * throw new TypeError("hello world!"); + * }, + * TypeError, + * "hello", + * ); + * }); + * + * // This test will not pass. + * Deno.test("fails", async function () { + * await assertRejects( + * async () => { + * console.log("Hello world"); + * }, + * ); + * }); + * ``` + */ +export function assertRejects( + fn: () => PromiseLike, + // deno-lint-ignore no-explicit-any + ErrorClass: new (...args: any[]) => E, + msgIncludes?: string, + msg?: string, +): Promise; +export async function assertRejects( + fn: () => PromiseLike, + errorClassOrMsg?: + // deno-lint-ignore no-explicit-any + | (new (...args: any[]) => E) + | string, + msgIncludesOrMsg?: string, + msg?: string, +): Promise { + // deno-lint-ignore no-explicit-any + let ErrorClass: (new (...args: any[]) => E) | undefined = undefined; + let msgIncludes: string | undefined = undefined; + let err; + + if (typeof errorClassOrMsg !== "string") { + if ( + errorClassOrMsg === undefined || + errorClassOrMsg.prototype instanceof Error || + errorClassOrMsg.prototype === Error.prototype + ) { + // deno-lint-ignore no-explicit-any + ErrorClass = errorClassOrMsg as new (...args: any[]) => E; + msgIncludes = msgIncludesOrMsg; + } + } else { + msg = errorClassOrMsg; + } + let doesThrow = false; + let isPromiseReturned = false; + const msgSuffix = msg ? `: ${msg}` : "."; + try { + const possiblePromise = fn(); + if ( + possiblePromise && + typeof possiblePromise === "object" && + typeof possiblePromise.then === "function" + ) { + isPromiseReturned = true; + await possiblePromise; + } + } catch (error) { + if (!isPromiseReturned) { + throw new AssertionError( + `Function throws when expected to reject${msgSuffix}`, + ); + } + if (ErrorClass) { + if (error instanceof Error === false) { + throw new AssertionError(`A non-Error object was rejected${msgSuffix}`); + } + assertIsError( + error, + ErrorClass, + msgIncludes, + msg, + ); + } + err = error; + doesThrow = true; + } + if (!doesThrow) { + throw new AssertionError( + `Expected function to reject${msgSuffix}`, + ); + } + return err; +} diff --git a/assert/assert_rejects_test.ts b/assert/assert_rejects_test.ts new file mode 100644 index 000000000000..1deb1fb6b45c --- /dev/null +++ b/assert/assert_rejects_test.ts @@ -0,0 +1,109 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assert, assertEquals, AssertionError, assertRejects } from "./mod.ts"; + +Deno.test("assertRejects with return type", async () => { + await assertRejects(() => { + return Promise.reject(new Error()); + }); +}); + +Deno.test("assertRejects with synchronous function that throws", async () => { + await assertRejects(() => + assertRejects(() => { + throw new Error(); + }) + ); + await assertRejects( + () => + assertRejects(() => { + throw { wrong: "true" }; + }), + AssertionError, + "Function throws when expected to reject.", + ); +}); + +Deno.test("assertRejects with PromiseLike", async () => { + await assertRejects( + () => ({ + then() { + throw new Error("some error"); + }, + }), + Error, + "some error", + ); +}); + +Deno.test("assertRejects with non-error value rejected and error class", async () => { + await assertRejects( + () => { + return assertRejects( + () => { + return Promise.reject("Panic!"); + }, + Error, + "Panic!", + ); + }, + AssertionError, + "A non-Error object was rejected.", + ); +}); + +Deno.test("assertRejects with non-error value rejected", async () => { + await assertRejects(() => { + return Promise.reject(null); + }); + await assertRejects(() => { + return Promise.reject(undefined); + }); +}); + +Deno.test("assertRejects with error class", async () => { + await assertRejects( + () => { + return Promise.reject(new Error("foo")); + }, + Error, + "foo", + ); +}); + +Deno.test("assertRejects resolves with caught error", async () => { + const error = await assertRejects( + () => { + return Promise.reject(new Error("foo")); + }, + ); + assert(error instanceof Error); + assertEquals(error.message, "foo"); +}); + +Deno.test("Assert Throws Async Parent Error", async () => { + await assertRejects( + () => { + return Promise.reject(new AssertionError("Fail!")); + }, + Error, + "Fail!", + ); +}); + +Deno.test( + "Assert Throws Async promise rejected with custom Error", + async () => { + class CustomError extends Error {} + class AnotherCustomError extends Error {} + await assertRejects( + () => + assertRejects( + () => Promise.reject(new AnotherCustomError("failed")), + CustomError, + "fail", + ), + AssertionError, + 'Expected error to be instance of "CustomError", but was "AnotherCustomError".', + ); + }, +); diff --git a/assert/assert_strict_equals.ts b/assert/assert_strict_equals.ts new file mode 100644 index 000000000000..e982b82d377f --- /dev/null +++ b/assert/assert_strict_equals.ts @@ -0,0 +1,69 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { format } from "./_format.ts"; +import { AssertionError } from "./assertion_error.ts"; +import { buildMessage, diff, diffstr } from "../_util/diff.ts"; +import { CAN_NOT_DISPLAY } from "./_constants.ts"; +import { red } from "../fmt/colors.ts"; + +/** + * Make an assertion that `actual` and `expected` are strictly equal. If + * not then throw. + * + * @example + * ```ts + * import { assertStrictEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_strict_equals.ts"; + * + * Deno.test("isStrictlyEqual", function (): void { + * const a = {}; + * const b = a; + * assertStrictEquals(a, b); + * }); + * + * // This test fails + * Deno.test("isNotStrictlyEqual", function (): void { + * const a = {}; + * const b = {}; + * assertStrictEquals(a, b); + * }); + * ``` + */ +export function assertStrictEquals( + actual: unknown, + expected: T, + msg?: string, +): asserts actual is T { + if (Object.is(actual, expected)) { + return; + } + + const msgSuffix = msg ? `: ${msg}` : "."; + let message: string; + + const actualString = format(actual); + const expectedString = format(expected); + + if (actualString === expectedString) { + const withOffset = actualString + .split("\n") + .map((l) => ` ${l}`) + .join("\n"); + message = + `Values have the same structure but are not reference-equal${msgSuffix}\n\n${ + red(withOffset) + }\n`; + } else { + try { + const stringDiff = (typeof actual === "string") && + (typeof expected === "string"); + const diffResult = stringDiff + ? diffstr(actual as string, expected as string) + : diff(actualString.split("\n"), expectedString.split("\n")); + const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n"); + message = `Values are not strictly equal${msgSuffix}\n${diffMsg}`; + } catch { + message = `\n${red(CAN_NOT_DISPLAY)} + \n\n`; + } + } + + throw new AssertionError(message); +} diff --git a/assert/assert_strict_equals_test.ts b/assert/assert_strict_equals_test.ts new file mode 100644 index 000000000000..f99aee00a0e9 --- /dev/null +++ b/assert/assert_strict_equals_test.ts @@ -0,0 +1,93 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError, assertStrictEquals, assertThrows } from "./mod.ts"; + +Deno.test({ + name: "strict types test", + fn() { + const x = { number: 2 }; + + const y = x as Record; + const z = x as unknown; + + // y.number; + // ~~~~~~ + // Property 'number' does not exist on type 'Record'.deno-ts(2339) + + assertStrictEquals(y, x); + y.number; // ok + + // z.number; + // ~ + // Object is of type 'unknown'.deno-ts(2571) + + assertStrictEquals(z, x); + z.number; // ok + }, +}); + +Deno.test({ + name: "strict pass case", + fn() { + assertStrictEquals(true, true); + assertStrictEquals(10, 10); + assertStrictEquals("abc", "abc"); + assertStrictEquals(NaN, NaN); + + const xs = [1, false, "foo"]; + const ys = xs; + assertStrictEquals(xs, ys); + + const x = { a: 1 }; + const y = x; + assertStrictEquals(x, y); + }, +}); + +Deno.test({ + name: "strict failed with structure diff", + fn() { + assertThrows( + () => assertStrictEquals({ a: 1, b: 2 }, { a: 1, c: [3] }), + AssertionError, + ` + { + a: 1, ++ c: [ ++ 3, ++ ], +- b: 2, + }`, + ); + }, +}); + +Deno.test({ + name: "strict failed with reference diff", + fn() { + assertThrows( + () => assertStrictEquals({ a: 1, b: 2 }, { a: 1, b: 2 }), + AssertionError, + `Values have the same structure but are not reference-equal. + + { + a: 1, + b: 2, + }`, + ); + }, +}); + +Deno.test({ + name: "strict failed with custom msg", + fn() { + assertThrows( + () => assertStrictEquals({ a: 1 }, { a: 1 }, "CUSTOM MESSAGE"), + AssertionError, + `Values have the same structure but are not reference-equal: CUSTOM MESSAGE + + { + a: 1, + }`, + ); + }, +}); diff --git a/assert/assert_string_includes.ts b/assert/assert_string_includes.ts new file mode 100644 index 000000000000..ec4c912a259d --- /dev/null +++ b/assert/assert_string_includes.ts @@ -0,0 +1,18 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +/** + * Make an assertion that actual includes expected. If not + * then throw. + */ +export function assertStringIncludes( + actual: string, + expected: string, + msg?: string, +) { + if (!actual.includes(expected)) { + const msgSuffix = msg ? `: ${msg}` : "."; + msg = `Expected actual: "${actual}" to contain: "${expected}"${msgSuffix}`; + throw new AssertionError(msg); + } +} diff --git a/assert/assert_string_includes_test.ts b/assert/assert_string_includes_test.ts new file mode 100644 index 000000000000..552cfb4c9ea5 --- /dev/null +++ b/assert/assert_string_includes_test.ts @@ -0,0 +1,37 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { + assert, + assertEquals, + AssertionError, + assertStringIncludes, +} from "./mod.ts"; + +Deno.test("AssertStringIncludes", function () { + assertStringIncludes("Denosaurus", "saur"); + assertStringIncludes("Denosaurus", "Deno"); + assertStringIncludes("Denosaurus", "rus"); + let didThrow; + try { + assertStringIncludes("Denosaurus", "Raptor"); + didThrow = false; + } catch (e) { + assert(e instanceof AssertionError); + didThrow = true; + } + assertEquals(didThrow, true); +}); + +Deno.test("AssertStringContainsThrow", function () { + let didThrow = false; + try { + assertStringIncludes("Denosaurus from Jurassic", "Raptor"); + } catch (e) { + assert(e instanceof AssertionError); + assert( + e.message === + `Expected actual: "Denosaurus from Jurassic" to contain: "Raptor".`, + ); + didThrow = true; + } + assert(didThrow); +}); diff --git a/assert/assert_throws.ts b/assert/assert_throws.ts new file mode 100644 index 000000000000..c47aba9c00e8 --- /dev/null +++ b/assert/assert_throws.ts @@ -0,0 +1,121 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertIsError } from "./assert_is_error.ts"; +import { AssertionError } from "./assertion_error.ts"; + +/** + * Executes a function, expecting it to throw. If it does not, then it + * throws. + * + * @example + * ```ts + * import { assertThrows } from "https://deno.land/std@$STD_VERSION/assert/assert_throws.ts"; + * + * Deno.test("doesThrow", function (): void { + * assertThrows((): void => { + * throw new TypeError("hello world!"); + * }); + * }); + * + * // This test will not pass. + * Deno.test("fails", function (): void { + * assertThrows((): void => { + * console.log("Hello world"); + * }); + * }); + * ``` + */ +export function assertThrows( + fn: () => unknown, + msg?: string, +): unknown; +/** + * Executes a function, expecting it to throw. If it does not, then it + * throws. An error class and a string that should be included in the + * error message can also be asserted. + * + * @example + * ```ts + * import { assertThrows } from "https://deno.land/std@$STD_VERSION/assert/assert_throws.ts"; + * + * Deno.test("doesThrow", function (): void { + * assertThrows((): void => { + * throw new TypeError("hello world!"); + * }, TypeError); + * assertThrows( + * (): void => { + * throw new TypeError("hello world!"); + * }, + * TypeError, + * "hello", + * ); + * }); + * + * // This test will not pass. + * Deno.test("fails", function (): void { + * assertThrows((): void => { + * console.log("Hello world"); + * }); + * }); + * ``` + */ +export function assertThrows( + fn: () => unknown, + // deno-lint-ignore no-explicit-any + ErrorClass: new (...args: any[]) => E, + msgIncludes?: string, + msg?: string, +): E; +export function assertThrows( + fn: () => unknown, + errorClassOrMsg?: + // deno-lint-ignore no-explicit-any + | (new (...args: any[]) => E) + | string, + msgIncludesOrMsg?: string, + msg?: string, +): E | Error | unknown { + // deno-lint-ignore no-explicit-any + let ErrorClass: (new (...args: any[]) => E) | undefined = undefined; + let msgIncludes: string | undefined = undefined; + let err; + + if (typeof errorClassOrMsg !== "string") { + if ( + errorClassOrMsg === undefined || + errorClassOrMsg.prototype instanceof Error || + errorClassOrMsg.prototype === Error.prototype + ) { + // deno-lint-ignore no-explicit-any + ErrorClass = errorClassOrMsg as new (...args: any[]) => E; + msgIncludes = msgIncludesOrMsg; + } else { + msg = msgIncludesOrMsg; + } + } else { + msg = errorClassOrMsg; + } + let doesThrow = false; + const msgSuffix = msg ? `: ${msg}` : "."; + try { + fn(); + } catch (error) { + if (ErrorClass) { + if (error instanceof Error === false) { + throw new AssertionError(`A non-Error object was thrown${msgSuffix}`); + } + assertIsError( + error, + ErrorClass, + msgIncludes, + msg, + ); + } + err = error; + doesThrow = true; + } + if (!doesThrow) { + msg = `Expected function to throw${msgSuffix}`; + throw new AssertionError(msg); + } + return err; +} diff --git a/assert/assert_throws_test.ts b/assert/assert_throws_test.ts new file mode 100644 index 000000000000..a420c4b2d25c --- /dev/null +++ b/assert/assert_throws_test.ts @@ -0,0 +1,129 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { + assert, + assertEquals, + AssertionError, + assertThrows, + fail, +} from "./mod.ts"; + +Deno.test("assertThrows with wrong error class", () => { + assertThrows( + () => { + //This next assertThrows will throw an AssertionError due to the wrong + //expected error class + assertThrows( + () => { + fail("foo"); + }, + TypeError, + "Failed assertion: foo", + ); + }, + AssertionError, + `Expected error to be instance of "TypeError", but was "AssertionError"`, + ); +}); + +Deno.test("assertThrows with return type", () => { + assertThrows(() => { + throw new Error(); + }); +}); + +Deno.test("assertThrows with non-error value thrown and error class", () => { + assertThrows( + () => { + assertThrows( + () => { + throw "Panic!"; + }, + Error, + "Panic!", + ); + }, + AssertionError, + "A non-Error object was thrown.", + ); +}); + +Deno.test("assertThrows with non-error value thrown", () => { + assertThrows( + () => { + throw "Panic!"; + }, + ); + assertThrows( + () => { + throw null; + }, + ); + assertThrows( + () => { + throw undefined; + }, + ); +}); + +Deno.test("assertThrows with error class", () => { + assertThrows( + () => { + throw new Error("foo"); + }, + Error, + "foo", + ); +}); + +Deno.test("assertThrows with thrown error returns caught error", () => { + const error = assertThrows( + () => { + throw new Error("foo"); + }, + ); + assert(error instanceof Error); + assertEquals(error.message, "foo"); +}); + +Deno.test("assertThrows with thrown non-error returns caught error", () => { + const stringError = assertThrows( + () => { + throw "Panic!"; + }, + ); + assert(typeof stringError === "string"); + assertEquals(stringError, "Panic!"); + + const numberError = assertThrows( + () => { + throw 1; + }, + ); + assert(typeof numberError === "number"); + assertEquals(numberError, 1); + + const nullError = assertThrows( + () => { + throw null; + }, + ); + assert(nullError === null); + + const undefinedError = assertThrows( + () => { + throw undefined; + }, + ); + assert(typeof undefinedError === "undefined"); + assertEquals(undefinedError, undefined); +}); + +Deno.test("Assert Throws Parent Error", () => { + assertThrows( + () => { + throw new AssertionError("Fail!"); + }, + Error, + "Fail!", + ); +}); diff --git a/assert/assertion_error.ts b/assert/assertion_error.ts new file mode 100644 index 000000000000..feecc9e87a66 --- /dev/null +++ b/assert/assertion_error.ts @@ -0,0 +1,7 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +export class AssertionError extends Error { + override name = "AssertionError"; + constructor(message: string) { + super(message); + } +} diff --git a/assert/equal.ts b/assert/equal.ts new file mode 100644 index 000000000000..288471de523e --- /dev/null +++ b/assert/equal.ts @@ -0,0 +1,111 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +function isKeyedCollection(x: unknown): x is Set { + return [Symbol.iterator, "size"].every((k) => k in (x as Set)); +} + +function constructorsEqual(a: object, b: object) { + return a.constructor === b.constructor || + a.constructor === Object && !b.constructor || + !a.constructor && b.constructor === Object; +} + +/** + * 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 { + // Have to render RegExp & Date for string comparison + // unless it's mistreated as object + if ( + a && + b && + ((a instanceof RegExp && b instanceof RegExp) || + (a instanceof URL && b instanceof URL)) + ) { + return String(a) === String(b); + } + if (a instanceof Date && b instanceof Date) { + const aTime = a.getTime(); + const bTime = b.getTime(); + // Check for NaN equality manually since NaN is not + // equal to itself. + if (Number.isNaN(aTime) && Number.isNaN(bTime)) { + return true; + } + return aTime === bTime; + } + if (typeof a === "number" && typeof b === "number") { + return Number.isNaN(a) && Number.isNaN(b) || a === b; + } + if (Object.is(a, b)) { + return true; + } + if (a && typeof a === "object" && b && typeof b === "object") { + if (a && b && !constructorsEqual(a, b)) { + return false; + } + if (a instanceof WeakMap || b instanceof WeakMap) { + if (!(a instanceof WeakMap && b instanceof WeakMap)) return false; + throw new TypeError("cannot compare WeakMap instances"); + } + if (a instanceof WeakSet || b instanceof WeakSet) { + if (!(a instanceof WeakSet && b instanceof WeakSet)) return false; + throw new TypeError("cannot compare WeakSet instances"); + } + if (seen.get(a) === b) { + return true; + } + if (Object.keys(a || {}).length !== Object.keys(b || {}).length) { + return false; + } + seen.set(a, b); + if (isKeyedCollection(a) && isKeyedCollection(b)) { + if (a.size !== b.size) { + return false; + } + + let unmatchedEntries = a.size; + + for (const [aKey, aValue] of a.entries()) { + for (const [bKey, bValue] of b.entries()) { + /* Given that Map keys can be references, we need + * to ensure that they are also deeply equal */ + if ( + (aKey === aValue && bKey === bValue && compare(aKey, bKey)) || + (compare(aKey, bKey) && compare(aValue, bValue)) + ) { + unmatchedEntries--; + break; + } + } + } + + return unmatchedEntries === 0; + } + const merged = { ...a, ...b }; + for ( + const key of [ + ...Object.getOwnPropertyNames(merged), + ...Object.getOwnPropertySymbols(merged), + ] + ) { + type Key = keyof typeof merged; + if (!compare(a && a[key as Key], b && b[key as Key])) { + return false; + } + if (((key in a) && (!(key in b))) || ((key in b) && (!(key in a)))) { + return false; + } + } + if (a instanceof WeakRef || b instanceof WeakRef) { + if (!(a instanceof WeakRef && b instanceof WeakRef)) return false; + return compare(a.deref(), b.deref()); + } + return true; + } + return false; + })(c, d); +} diff --git a/assert/equal_test.ts b/assert/equal_test.ts new file mode 100644 index 000000000000..782898c79f1d --- /dev/null +++ b/assert/equal_test.ts @@ -0,0 +1,266 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assert, assertFalse, assertThrows, equal } from "./mod.ts"; + +Deno.test("EqualDifferentZero", () => { + assert(equal(0, -0)); + assert(equal(0, +0)); + assert(equal(+0, -0)); + assert(equal([0], [-0])); + assert(equal(["hello", 12.21, 0], ["hello", 12.21, -0])); + assert(equal(["hello", 12.21, 0], ["hello", 12.21, +0])); + assert(equal(["hello", 12.21, -0], ["hello", 12.21, +0])); + assert(equal({ msg: "hello", case: 0 }, { msg: "hello", case: -0 })); + assert(equal({ msg: "hello", array: [0] }, { msg: "hello", array: [-0] })); +}); + +Deno.test("Equal", function () { + assert(equal("world", "world")); + assert(!equal("hello", "world")); + assertFalse(equal("hello", "world")); + assert(equal(5, 5)); + assert(!equal(5, 6)); + assertFalse(equal(5, 6)); + assert(equal(NaN, NaN)); + assert(equal({ hello: "world" }, { hello: "world" })); + assert(!equal({ world: "hello" }, { hello: "world" })); + assertFalse(equal({ world: "hello" }, { hello: "world" })); + assert( + equal( + { hello: "world", hi: { there: "everyone" } }, + { hello: "world", hi: { there: "everyone" } }, + ), + ); + assert( + !equal( + { hello: "world", hi: { there: "everyone" } }, + { hello: "world", hi: { there: "everyone else" } }, + ), + ); + assertFalse( + equal( + { hello: "world", hi: { there: "everyone" } }, + { hello: "world", hi: { there: "everyone else" } }, + ), + ); + assert(equal({ [Symbol.for("foo")]: "bar" }, { [Symbol.for("foo")]: "bar" })); + assert(!equal({ [Symbol("foo")]: "bar" }, { [Symbol("foo")]: "bar" })); + assertFalse(equal({ [Symbol("foo")]: "bar" }, { [Symbol("foo")]: "bar" })); + + assert(equal(/deno/, /deno/)); + assert(!equal(/deno/, /node/)); + assertFalse(equal(/deno/, /node/)); + assert(equal(new Date(2019, 0, 3), new Date(2019, 0, 3))); + assert(!equal(new Date(2019, 0, 3), new Date(2019, 1, 3))); + assertFalse(equal(new Date(2019, 0, 3), new Date(2019, 1, 3))); + assert( + !equal( + new Date(2019, 0, 3, 4, 20, 1, 10), + new Date(2019, 0, 3, 4, 20, 1, 20), + ), + ); + assertFalse( + equal( + new Date(2019, 0, 3, 4, 20, 1, 10), + new Date(2019, 0, 3, 4, 20, 1, 20), + ), + ); + assert(equal(new Date("Invalid"), new Date("Invalid"))); + assert(!equal(new Date("Invalid"), new Date(2019, 0, 3))); + assertFalse(equal(new Date("Invalid"), new Date(2019, 0, 3))); + assert(!equal(new Date("Invalid"), new Date(2019, 0, 3, 4, 20, 1, 10))); + assertFalse(equal(new Date("Invalid"), new Date(2019, 0, 3, 4, 20, 1, 10))); + assert(equal(new Set([1]), new Set([1]))); + assert(!equal(new Set([1]), new Set([2]))); + assertFalse(equal(new Set([1]), new Set([2]))); + assert(equal(new Set([1, 2, 3]), new Set([3, 2, 1]))); + assert(equal(new Set([1, new Set([2, 3])]), new Set([new Set([3, 2]), 1]))); + assert(!equal(new Set([1, 2]), new Set([3, 2, 1]))); + assertFalse(equal(new Set([1, 2]), new Set([3, 2, 1]))); + assert(!equal(new Set([1, 2, 3]), new Set([4, 5, 6]))); + assertFalse(equal(new Set([1, 2, 3]), new Set([4, 5, 6]))); + assert(equal(new Set("denosaurus"), new Set("denosaurussss"))); + assert(equal(new Map(), new Map())); + assert( + equal( + new Map([ + ["foo", "bar"], + ["baz", "baz"], + ]), + new Map([ + ["foo", "bar"], + ["baz", "baz"], + ]), + ), + ); + assert( + equal( + new Map([["foo", new Map([["bar", "baz"]])]]), + new Map([["foo", new Map([["bar", "baz"]])]]), + ), + ); + assert( + equal( + new Map([["foo", { bar: "baz" }]]), + new Map([["foo", { bar: "baz" }]]), + ), + ); + assert( + equal( + new Map([ + ["foo", "bar"], + ["baz", "qux"], + ]), + new Map([ + ["baz", "qux"], + ["foo", "bar"], + ]), + ), + ); + assert(equal(new Map([["foo", ["bar"]]]), new Map([["foo", ["bar"]]]))); + assert(!equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]]))); + assertFalse(equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]]))); + assertFalse(equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]]))); + assert( + !equal( + new Map([["foo", "bar"]]), + new Map([ + ["foo", "bar"], + ["bar", "baz"], + ]), + ), + ); + assertFalse( + equal( + new Map([["foo", "bar"]]), + new Map([ + ["foo", "bar"], + ["bar", "baz"], + ]), + ), + ); + assert( + !equal( + new Map([["foo", new Map([["bar", "baz"]])]]), + new Map([["foo", new Map([["bar", "qux"]])]]), + ), + ); + assert(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, true]]))); + assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, false]]))); + assertFalse(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, false]]))); + assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 2 }, true]]))); + assertFalse(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 2 }, true]]))); + assert(equal([1, 2, 3], [1, 2, 3])); + assert(equal([1, [2, 3]], [1, [2, 3]])); + assert(!equal([1, 2, 3, 4], [1, 2, 3])); + assertFalse(equal([1, 2, 3, 4], [1, 2, 3])); + assert(!equal([1, 2, 3, 4], [1, 2, 3])); + assertFalse(equal([1, 2, 3, 4], [1, 2, 3])); + assert(!equal([1, 2, 3, 4], [1, 4, 2, 3])); + assertFalse(equal([1, 2, 3, 4], [1, 4, 2, 3])); + assert(equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([1, 2, 3, 4]))); + assert(!equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([2, 1, 4, 3]))); + assertFalse( + equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([2, 1, 4, 3])), + ); + assert( + equal(new URL("https://example.test"), new URL("https://example.test")), + ); + assert( + !equal( + new URL("https://example.test"), + new URL("https://example.test/with-path"), + ), + ); + assertFalse( + equal( + new URL("https://example.test"), + new URL("https://example.test/with-path"), + ), + ); + assert( + !equal({ a: undefined, b: undefined }, { a: undefined, c: undefined }), + ); + assertFalse( + equal({ a: undefined, b: undefined }, { a: undefined, c: undefined }), + ); + assertFalse(equal({ a: undefined, b: undefined }, { a: undefined })); + assertThrows(() => equal(new WeakMap(), new WeakMap())); + assertThrows(() => equal(new WeakSet(), new WeakSet())); + assert(!equal(new WeakMap(), new WeakSet())); + assertFalse(equal(new WeakMap(), new WeakSet())); + assert( + equal(new WeakRef({ hello: "world" }), new WeakRef({ hello: "world" })), + ); + assert( + !equal(new WeakRef({ world: "hello" }), new WeakRef({ hello: "world" })), + ); + assertFalse( + equal(new WeakRef({ world: "hello" }), new WeakRef({ hello: "world" })), + ); + assert(!equal({ hello: "world" }, new WeakRef({ hello: "world" }))); + assertFalse(equal({ hello: "world" }, new WeakRef({ hello: "world" }))); + assert( + !equal( + new WeakRef({ hello: "world" }), + new (class extends WeakRef {})({ hello: "world" }), + ), + ); + assertFalse( + equal( + new WeakRef({ hello: "world" }), + new (class extends WeakRef {})({ hello: "world" }), + ), + ); + assert( + !equal( + new WeakRef({ hello: "world" }), + new (class extends WeakRef { + foo = "bar"; + })({ hello: "world" }), + ), + ); + assertFalse( + equal( + new WeakRef({ hello: "world" }), + new (class extends WeakRef { + foo = "bar"; + })({ hello: "world" }), + ), + ); + + assert( + !equal( + new (class A { + #hello = "world"; + })(), + new (class B { + #hello = "world"; + })(), + ), + ); + + assertFalse( + equal( + new (class A { + #hello = "world"; + })(), + new (class B { + #hello = "world"; + })(), + ), + ); +}); + +Deno.test("EqualCircular", () => { + const objA: { prop?: unknown } = {}; + objA.prop = objA; + const objB: { prop?: unknown } = {}; + objB.prop = objB; + assert(equal(objA, objB)); + + const mapA = new Map(); + mapA.set("prop", mapA); + const mapB = new Map(); + mapB.set("prop", mapB); + assert(equal(mapA, mapB)); +}); diff --git a/assert/fail.ts b/assert/fail.ts new file mode 100644 index 000000000000..6eef3fe61c0d --- /dev/null +++ b/assert/fail.ts @@ -0,0 +1,10 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assert } from "./assert.ts"; + +/** + * Forcefully throws a failed assertion + */ +export function fail(msg?: string): never { + const msgSuffix = msg ? `: ${msg}` : "."; + assert(false, `Failed assertion${msgSuffix}`); +} diff --git a/assert/fail_test.ts b/assert/fail_test.ts new file mode 100644 index 000000000000..0610b7607c00 --- /dev/null +++ b/assert/fail_test.ts @@ -0,0 +1,13 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError, assertThrows, fail } from "./mod.ts"; + +Deno.test("AssertFail", function () { + assertThrows(fail, AssertionError, "Failed assertion."); + assertThrows( + () => { + fail("foo"); + }, + AssertionError, + "Failed assertion: foo", + ); +}); diff --git a/assert/mod.ts b/assert/mod.ts new file mode 100644 index 000000000000..bdcb8e40f195 --- /dev/null +++ b/assert/mod.ts @@ -0,0 +1,35 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +/** A library of assertion functions. + * If the assertion is false an `AssertionError` will be thrown which will + * result in pretty-printed diff of failing assertion. + * + * This module is browser compatible, but do not rely on good formatting of + * values for AssertionError messages in browsers. + * + * @module + */ + +export * from "./assert_almost_equals.ts"; +export * from "./assert_array_includes.ts"; +export * from "./assert_equals.ts"; +export * from "./assert_exists.ts"; +export * from "./assert_false.ts"; +export * from "./assert_instance_of.ts"; +export * from "./assert_is_error.ts"; +export * from "./assert_match.ts"; +export * from "./assert_not_equals.ts"; +export * from "./assert_not_instance_of.ts"; +export * from "./assert_not_match.ts"; +export * from "./assert_not_strict_equals.ts"; +export * from "./assert_object_match.ts"; +export * from "./assert_rejects.ts"; +export * from "./assert_strict_equals.ts"; +export * from "./assert_string_includes.ts"; +export * from "./assert_throws.ts"; +export * from "./assert.ts"; +export * from "./assertion_error.ts"; +export * from "./equal.ts"; +export * from "./fail.ts"; +export * from "./unimplemented.ts"; +export * from "./unreachable.ts"; diff --git a/assert/shared_test.ts b/assert/shared_test.ts new file mode 100644 index 000000000000..d8860a8ab059 --- /dev/null +++ b/assert/shared_test.ts @@ -0,0 +1,20 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { + assertArrayIncludes, + assertEquals, + assertNotEquals, + assertNotStrictEquals, + assertStrictEquals, +} from "./mod.ts"; + +Deno.test({ + name: "assert* functions with specified type parameter", + fn() { + assertEquals("hello", "hello"); + assertNotEquals(1, 2); + assertArrayIncludes([true, false], [true]); + const value = { x: 1 }; + assertStrictEquals(value, value); + assertNotStrictEquals(value, { x: 1 }); + }, +}); diff --git a/assert/unimplemented.ts b/assert/unimplemented.ts new file mode 100644 index 000000000000..6c62e4f97e69 --- /dev/null +++ b/assert/unimplemented.ts @@ -0,0 +1,8 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +/** Use this to stub out methods that will throw when invoked. */ +export function unimplemented(msg?: string): never { + const msgSuffix = msg ? `: ${msg}` : "."; + throw new AssertionError(`Unimplemented${msgSuffix}`); +} diff --git a/assert/unimplemented_test.ts b/assert/unimplemented_test.ts new file mode 100644 index 000000000000..a2a7ebf389b6 --- /dev/null +++ b/assert/unimplemented_test.ts @@ -0,0 +1,14 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assert, AssertionError, unimplemented } from "./mod.ts"; + +Deno.test("AssertsUnimplemented", function () { + let didThrow = false; + try { + unimplemented(); + } catch (e) { + assert(e instanceof AssertionError); + assert(e.message === "Unimplemented."); + didThrow = true; + } + assert(didThrow); +}); diff --git a/assert/unreachable.ts b/assert/unreachable.ts new file mode 100644 index 000000000000..d9f36ef8f769 --- /dev/null +++ b/assert/unreachable.ts @@ -0,0 +1,7 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { AssertionError } from "./assertion_error.ts"; + +/** Use this to assert unreachable code. */ +export function unreachable(): never { + throw new AssertionError("unreachable"); +} diff --git a/assert/unreachable_test.ts b/assert/unreachable_test.ts new file mode 100644 index 000000000000..60a40898211d --- /dev/null +++ b/assert/unreachable_test.ts @@ -0,0 +1,14 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assert, AssertionError, unreachable } from "./mod.ts"; + +Deno.test("AssertsUnreachable", function () { + let didThrow = false; + try { + unreachable(); + } catch (e) { + assert(e instanceof AssertionError); + assert(e.message === "unreachable"); + didThrow = true; + } + assert(didThrow); +}); diff --git a/async/abortable_test.ts b/async/abortable_test.ts index 87d039839fac..f7420f34ec7e 100644 --- a/async/abortable_test.ts +++ b/async/abortable_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { deferred } from "./deferred.ts"; import { abortable } from "./abortable.ts"; diff --git a/async/deadline_test.ts b/async/deadline_test.ts index 3c9e267cc6cf..4a7e33b69d1a 100644 --- a/async/deadline_test.ts +++ b/async/deadline_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { delay } from "./delay.ts"; import { deadline, DeadlineError } from "./deadline.ts"; diff --git a/async/debounce_test.ts b/async/debounce_test.ts index 0be5b8326202..79cb6f936bbc 100644 --- a/async/debounce_test.ts +++ b/async/debounce_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertStrictEquals } from "../testing/asserts.ts"; +import { assertEquals, assertStrictEquals } from "../assert/mod.ts"; import { debounce, DebouncedFunction } from "./debounce.ts"; import { delay } from "./delay.ts"; diff --git a/async/deferred_test.ts b/async/deferred_test.ts index 0a6d56617cc5..4a3980cc70f9 100644 --- a/async/deferred_test.ts +++ b/async/deferred_test.ts @@ -1,9 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { - assertEquals, - assertRejects, - assertThrows, -} from "../testing/asserts.ts"; +import { assertEquals, assertRejects, assertThrows } from "../assert/mod.ts"; import { deferred } from "./deferred.ts"; Deno.test("[async] deferred: resolve", async function () { diff --git a/async/delay_test.ts b/async/delay_test.ts index de1bb6f00589..6bb138a5b43d 100644 --- a/async/delay_test.ts +++ b/async/delay_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { delay } from "./delay.ts"; -import { assert, assertRejects } from "../testing/asserts.ts"; +import { assert, assertRejects } from "../assert/mod.ts"; Deno.test("[async] delay", async function () { const start = new Date(); diff --git a/async/mux_async_iterator_test.ts b/async/mux_async_iterator_test.ts index 9ce7ab2521d3..ecf179e52ca6 100644 --- a/async/mux_async_iterator_test.ts +++ b/async/mux_async_iterator_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { MuxAsyncIterator } from "./mux_async_iterator.ts"; async function* gen123(): AsyncIterableIterator { diff --git a/async/pool_test.ts b/async/pool_test.ts index 6de9b24bd29f..908adaa13b45 100644 --- a/async/pool_test.ts +++ b/async/pool_test.ts @@ -6,7 +6,7 @@ import { assertEquals, assertRejects, assertStringIncludes, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; Deno.test("[async] pooledMap", async function () { const start = new Date(); diff --git a/async/retry.ts b/async/retry.ts index 70d56ec257a7..d7c581a75924 100644 --- a/async/retry.ts +++ b/async/retry.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; export class RetryError extends Error { constructor(cause: unknown, attempts: number) { diff --git a/async/retry_test.ts b/async/retry_test.ts index 5c090e8d81bb..a68cf41d2ac5 100644 --- a/async/retry_test.ts +++ b/async/retry_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { _exponentialBackoffWithJitter, retry, RetryError } from "./retry.ts"; -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { FakeTime } from "../testing/time.ts"; function generateErroringFunction(errorsBeforeSucceeds: number) { diff --git a/async/tee_test.ts b/async/tee_test.ts index 039238de5027..0e4492c2e584 100644 --- a/async/tee_test.ts +++ b/async/tee_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { tee } from "./tee.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; /** An example async generator */ const gen = async function* iter() { diff --git a/bytes/bytes_list_test.ts b/bytes/bytes_list_test.ts index ddba27dd4b7f..cf9dd7593abc 100644 --- a/bytes/bytes_list_test.ts +++ b/bytes/bytes_list_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { BytesList } from "./bytes_list.ts"; import * as bytes from "./mod.ts"; function setup() { diff --git a/bytes/concat_test.ts b/bytes/concat_test.ts index 8ee98dc0424b..b7e9b97bba2e 100644 --- a/bytes/concat_test.ts +++ b/bytes/concat_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { concat } from "./concat.ts"; Deno.test("[bytes] concat", () => { diff --git a/bytes/copy_test.ts b/bytes/copy_test.ts index 7a704e847770..d3c9852b6aaf 100644 --- a/bytes/copy_test.ts +++ b/bytes/copy_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { copy } from "./copy.ts"; Deno.test("[bytes] copy", function () { diff --git a/bytes/ends_with_test.ts b/bytes/ends_with_test.ts index cbbd63d1e471..a341b25b91a1 100644 --- a/bytes/ends_with_test.ts +++ b/bytes/ends_with_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { endsWith } from "./ends_with.ts"; Deno.test("[bytes] endsWith", () => { diff --git a/bytes/equals_test.ts b/bytes/equals_test.ts index 8998f08c404d..2319cc04050a 100644 --- a/bytes/equals_test.ts +++ b/bytes/equals_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { equals } from "./equals.ts"; -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; Deno.test("[bytes] equals", () => { const v = equals(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3])); diff --git a/bytes/includes_needle_test.ts b/bytes/includes_needle_test.ts index 675917fc6ab1..348647aeaeb5 100644 --- a/bytes/includes_needle_test.ts +++ b/bytes/includes_needle_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { includesNeedle } from "./includes_needle.ts"; -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; Deno.test("[bytes] includesNeedle", () => { const encoder = new TextEncoder(); diff --git a/bytes/index_of_needle_test.ts b/bytes/index_of_needle_test.ts index a74082987d34..7a4eb379d5f5 100644 --- a/bytes/index_of_needle_test.ts +++ b/bytes/index_of_needle_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { indexOfNeedle } from "./index_of_needle.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test("[bytes] indexOfNeedle1", () => { const i = indexOfNeedle( diff --git a/bytes/last_index_of_needle_test.ts b/bytes/last_index_of_needle_test.ts index 43cba4d3ce7e..3440432121bf 100644 --- a/bytes/last_index_of_needle_test.ts +++ b/bytes/last_index_of_needle_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { lastIndexOfNeedle } from "./last_index_of_needle.ts"; Deno.test("[bytes] lastIndexOfNeedle1", () => { diff --git a/bytes/repeat_test.ts b/bytes/repeat_test.ts index 0a961ad50188..25b28b0a533c 100644 --- a/bytes/repeat_test.ts +++ b/bytes/repeat_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { repeat } from "./repeat.ts"; Deno.test("[bytes] repeat", () => { diff --git a/bytes/starts_with_test.ts b/bytes/starts_with_test.ts index 3e7d0d3fa5bb..54c1089d59e4 100644 --- a/bytes/starts_with_test.ts +++ b/bytes/starts_with_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { startsWith } from "./starts_with.ts"; Deno.test("[bytes] startsWith", () => { diff --git a/collections/_comparators_test.ts b/collections/_comparators_test.ts index f1cff4885732..05671eb2abf8 100644 --- a/collections/_comparators_test.ts +++ b/collections/_comparators_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { ascend, descend } from "./_comparators.ts"; Deno.test("[collections/comparators] ascend", () => { diff --git a/collections/aggregate_groups.ts b/collections/aggregate_groups.ts index 7ac8df6d2ce5..42cbfba5e13d 100644 --- a/collections/aggregate_groups.ts +++ b/collections/aggregate_groups.ts @@ -10,7 +10,7 @@ import { mapEntries } from "./map_entries.ts"; * @example * ```ts * import { aggregateGroups } from "https://deno.land/std@$STD_VERSION/collections/aggregate_groups.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const foodProperties = { * "Curry": ["spicy", "vegan"], diff --git a/collections/aggregate_groups_test.ts b/collections/aggregate_groups_test.ts index a9d79fb90816..b67a79076a10 100644 --- a/collections/aggregate_groups_test.ts +++ b/collections/aggregate_groups_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { aggregateGroups } from "./aggregate_groups.ts"; function aggregateGroupsTest( diff --git a/collections/associate_by.ts b/collections/associate_by.ts index 6b361fb8edd9..f4ac5fec4dd4 100644 --- a/collections/associate_by.ts +++ b/collections/associate_by.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { associateBy } from "https://deno.land/std@$STD_VERSION/collections/associate_by.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const users = [ * { id: "a2e", userName: "Anna" }, diff --git a/collections/associate_by_test.ts b/collections/associate_by_test.ts index db9a872fdea0..8212f6189824 100644 --- a/collections/associate_by_test.ts +++ b/collections/associate_by_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { associateBy } from "./associate_by.ts"; function associateByTest( diff --git a/collections/associate_with.ts b/collections/associate_with.ts index 83582fcb81cb..391b3af5e73f 100644 --- a/collections/associate_with.ts +++ b/collections/associate_with.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { associateWith } from "https://deno.land/std@$STD_VERSION/collections/associate_with.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const names = ["Kim", "Lara", "Jonathan"]; * const namesToLength = associateWith(names, (it) => it.length); diff --git a/collections/associate_with_test.ts b/collections/associate_with_test.ts index bf76bf234f86..ec5b87e42831 100644 --- a/collections/associate_with_test.ts +++ b/collections/associate_with_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { associateWith } from "./associate_with.ts"; function associateWithTest( diff --git a/collections/binary_heap.ts b/collections/binary_heap.ts index b6167cc20b4d..b3b34ea091cc 100644 --- a/collections/binary_heap.ts +++ b/collections/binary_heap.ts @@ -35,7 +35,7 @@ function getParentIndex(index: number) { * BinaryHeap, * descend, * } from "https://deno.land/std@$STD_VERSION/collections/binary_heap.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const maxHeap = new BinaryHeap(); * maxHeap.push(4, 1, 3, 5, 2); diff --git a/collections/binary_heap_test.ts b/collections/binary_heap_test.ts index e4a6b6e531fc..8e3588894f27 100644 --- a/collections/binary_heap_test.ts +++ b/collections/binary_heap_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; -import { assert } from "../_util/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; +import { assert } from "../assert/assert.ts"; import { ascend, BinaryHeap, descend } from "./binary_heap.ts"; import { Container, MyMath } from "./_test_utils.ts"; diff --git a/collections/binary_search_node_test.ts b/collections/binary_search_node_test.ts index 82c907e53d46..22c4bb0c4829 100644 --- a/collections/binary_search_node_test.ts +++ b/collections/binary_search_node_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertStrictEquals } from "../testing/asserts.ts"; +import { assertEquals, assertStrictEquals } from "../assert/mod.ts"; import { BinarySearchNode } from "./binary_search_node.ts"; let parent: BinarySearchNode; diff --git a/collections/binary_search_tree.ts b/collections/binary_search_tree.ts index 9285bd8eb684..5bd6de86ba09 100644 --- a/collections/binary_search_tree.ts +++ b/collections/binary_search_tree.ts @@ -29,7 +29,7 @@ export * from "./_comparators.ts"; * BinarySearchTree, * descend, * } from "https://deno.land/std@$STD_VERSION/collections/binary_search_tree.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const values = [3, 10, 13, 4, 6, 7, 1, 14]; * const tree = new BinarySearchTree(); diff --git a/collections/binary_search_tree_test.ts b/collections/binary_search_tree_test.ts index fd6db91d861e..190b2657ff46 100644 --- a/collections/binary_search_tree_test.ts +++ b/collections/binary_search_tree_test.ts @@ -4,7 +4,7 @@ import { assertEquals, assertStrictEquals, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import { ascend, BinarySearchTree, descend } from "./binary_search_tree.ts"; class MyMath { diff --git a/collections/chunk.ts b/collections/chunk.ts index 740c9cf40fa7..8efb1c97c017 100644 --- a/collections/chunk.ts +++ b/collections/chunk.ts @@ -7,7 +7,7 @@ * @example * ```ts * import { chunk } from "https://deno.land/std@$STD_VERSION/collections/chunk.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const words = [ * "lorem", diff --git a/collections/chunk_test.ts b/collections/chunk_test.ts index 81ceceb160e5..09fb8a72e54e 100644 --- a/collections/chunk_test.ts +++ b/collections/chunk_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { chunk } from "./chunk.ts"; function chunkTest( diff --git a/collections/deep_merge.ts b/collections/deep_merge.ts index c44493909adb..a022865cffa7 100644 --- a/collections/deep_merge.ts +++ b/collections/deep_merge.ts @@ -16,7 +16,7 @@ const { hasOwn } = Object; * @example * ```ts * import { deepMerge } from "https://deno.land/std@$STD_VERSION/collections/deep_merge.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const a = { foo: true }; * const b = { foo: { bar: true } }; @@ -69,7 +69,7 @@ function deepMergeInternal< >( record: Readonly, other: Readonly, - seen: Set>, + seen: Set>, options?: Readonly, ) { // Extract options @@ -119,15 +119,15 @@ function deepMergeInternal< } function mergeObjects( - left: Readonly>, - right: Readonly>, - seen: Set>, + left: Readonly>>, + right: Readonly>>, + seen: Set>, options: Readonly = { arrays: "merge", sets: "merge", maps: "merge", }, -): Readonly> { +): Readonly | Iterable>> { // Recursively merge mergeable objects if (isMergeable(left) && isMergeable(right)) { return deepMergeInternal(left, right, seen, options); @@ -177,22 +177,24 @@ function mergeObjects( * are not considered mergeable (it means that reference will be copied) */ function isMergeable( - value: NonNullable, + value: NonNullable, ): value is Record { return Object.getPrototypeOf(value) === Object.prototype; } function isIterable( - value: NonNullable, + value: NonNullable, ): value is Iterable { return typeof (value as Iterable)[Symbol.iterator] === "function"; } -function isNonNullObject(value: unknown): value is NonNullable { +function isNonNullObject( + value: unknown, +): value is NonNullable> { return value !== null && typeof value === "object"; } -function getKeys(record: T): Array { +function getKeys>(record: T): Array { const ret = Object.getOwnPropertySymbols(record) as Array; filterInPlace( ret, diff --git a/collections/deep_merge_test.ts b/collections/deep_merge_test.ts index 02395eb5e19a..72c9c983a53f 100644 --- a/collections/deep_merge_test.ts +++ b/collections/deep_merge_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertStrictEquals } from "../testing/asserts.ts"; +import { assertEquals, assertStrictEquals } from "../assert/mod.ts"; import { deepMerge } from "./deep_merge.ts"; Deno.test("deepMerge: simple merge", () => { diff --git a/collections/distinct.ts b/collections/distinct.ts index c344efca1e30..afa7c73f1fc5 100644 --- a/collections/distinct.ts +++ b/collections/distinct.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { distinct } from "https://deno.land/std@$STD_VERSION/collections/distinct.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const numbers = [3, 2, 5, 2, 5]; * const distinctNumbers = distinct(numbers); diff --git a/collections/distinct_by.ts b/collections/distinct_by.ts index a3c0de8ca286..f2fea74e8efe 100644 --- a/collections/distinct_by.ts +++ b/collections/distinct_by.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { distinctBy } from "https://deno.land/std@$STD_VERSION/collections/distinct_by.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const names = ["Anna", "Kim", "Arnold", "Kate"]; * const exampleNamesByFirstLetter = distinctBy(names, (it) => it.charAt(0)); diff --git a/collections/distinct_by_test.ts b/collections/distinct_by_test.ts index 0862efaabafb..cb9ec5de4937 100644 --- a/collections/distinct_by_test.ts +++ b/collections/distinct_by_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { distinctBy } from "./distinct_by.ts"; function distinctByTest( diff --git a/collections/distinct_test.ts b/collections/distinct_test.ts index b509ad1e3295..7c457b40d330 100644 --- a/collections/distinct_test.ts +++ b/collections/distinct_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { distinct } from "./distinct.ts"; function distinctTest( diff --git a/collections/drop_last_while.ts b/collections/drop_last_while.ts index 81eb6d5aaf33..5e7a2d3b6c0f 100644 --- a/collections/drop_last_while.ts +++ b/collections/drop_last_while.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { dropLastWhile } from "https://deno.land/std@$STD_VERSION/collections/drop_last_while.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const numbers = [22, 30, 44]; * diff --git a/collections/drop_last_while_test.ts b/collections/drop_last_while_test.ts index 3dd47cae780d..f46e11044cdf 100644 --- a/collections/drop_last_while_test.ts +++ b/collections/drop_last_while_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { dropLastWhile } from "./drop_last_while.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test("[collections/dropLastWhile] Num array", () => { const values = [20, 33, 44]; diff --git a/collections/drop_while.ts b/collections/drop_while.ts index 59ed34d41dc5..7753b78e9dce 100644 --- a/collections/drop_while.ts +++ b/collections/drop_while.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { dropWhile } from "https://deno.land/std@$STD_VERSION/collections/drop_while.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const numbers = [3, 2, 5, 2, 5]; * const dropWhileNumbers = dropWhile(numbers, (i) => i !== 2); diff --git a/collections/drop_while_test.ts b/collections/drop_while_test.ts index 417371921975..243c89f9b984 100644 --- a/collections/drop_while_test.ts +++ b/collections/drop_while_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { dropWhile } from "./drop_while.ts"; Deno.test("[collections/dropWhile] Array", () => { diff --git a/collections/filter_entries.ts b/collections/filter_entries.ts index 5c77829b6a8b..e39603acc708 100644 --- a/collections/filter_entries.ts +++ b/collections/filter_entries.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { filterEntries } from "https://deno.land/std@$STD_VERSION/collections/filter_entries.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const menu = { * "Salad": 11, diff --git a/collections/filter_entries_test.ts b/collections/filter_entries_test.ts index 094b0e60d135..9ee4bc017706 100644 --- a/collections/filter_entries_test.ts +++ b/collections/filter_entries_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { filterEntries } from "./filter_entries.ts"; function filterEntriesTest( diff --git a/collections/filter_keys.ts b/collections/filter_keys.ts index 581a85de1864..7322fbf00744 100644 --- a/collections/filter_keys.ts +++ b/collections/filter_keys.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { filterKeys } from "https://deno.land/std@$STD_VERSION/collections/filter_keys.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const menu = { * "Salad": 11, diff --git a/collections/filter_keys_test.ts b/collections/filter_keys_test.ts index 948072f859b8..9b4ee7c434d7 100644 --- a/collections/filter_keys_test.ts +++ b/collections/filter_keys_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { filterKeys } from "./filter_keys.ts"; function filterKeysTest( diff --git a/collections/filter_values.ts b/collections/filter_values.ts index d6d225490131..677de1fc0a23 100644 --- a/collections/filter_values.ts +++ b/collections/filter_values.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { filterValues } from "https://deno.land/std@$STD_VERSION/collections/filter_values.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const people = { * "Arnold": 37, diff --git a/collections/filter_values_test.ts b/collections/filter_values_test.ts index ee9548275ea9..2168bdc7abc5 100644 --- a/collections/filter_values_test.ts +++ b/collections/filter_values_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { filterValues } from "./filter_values.ts"; function filterValuesTest( diff --git a/collections/find_single.ts b/collections/find_single.ts index 1f8f1e9df9e3..f4e574ce6ed6 100644 --- a/collections/find_single.ts +++ b/collections/find_single.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { findSingle } from "https://deno.land/std@$STD_VERSION/collections/find_single.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const bookings = [ * { month: "January", active: false }, diff --git a/collections/find_single_test.ts b/collections/find_single_test.ts index ea5c85dd4e14..ed3a1faaa47f 100644 --- a/collections/find_single_test.ts +++ b/collections/find_single_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { findSingle } from "./find_single.ts"; function findSingleTest( diff --git a/collections/first_not_nullish_of.ts b/collections/first_not_nullish_of.ts index 08c221b3ff7f..0dc31fd38faa 100644 --- a/collections/first_not_nullish_of.ts +++ b/collections/first_not_nullish_of.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { firstNotNullishOf } from "https://deno.land/std@$STD_VERSION/collections/first_not_nullish_of.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const tables = [ * { number: 11, order: null }, diff --git a/collections/first_not_nullish_of_test.ts b/collections/first_not_nullish_of_test.ts index 1c4d7817d6df..0efa23efe5cc 100644 --- a/collections/first_not_nullish_of_test.ts +++ b/collections/first_not_nullish_of_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { firstNotNullishOf } from "./first_not_nullish_of.ts"; function firstNotNullishOfTest( diff --git a/collections/group_by.ts b/collections/group_by.ts index 03b35691a7c2..31a61d60a6b4 100644 --- a/collections/group_by.ts +++ b/collections/group_by.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { groupBy } from "https://deno.land/std@$STD_VERSION/collections/group_by.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const people = [ * { name: "Anna" }, diff --git a/collections/group_by_test.ts b/collections/group_by_test.ts index fd37e92d000b..7720c488319a 100644 --- a/collections/group_by_test.ts +++ b/collections/group_by_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { groupBy } from "./group_by.ts"; function groupByTest( diff --git a/collections/includes_value.ts b/collections/includes_value.ts index d5a62e810ba2..c9d3e8bd32d2 100644 --- a/collections/includes_value.ts +++ b/collections/includes_value.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { includesValue } from "https://deno.land/std@$STD_VERSION/collections/includes_value.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const input = { * first: 33, diff --git a/collections/includes_value_test.ts b/collections/includes_value_test.ts index 8e545fa21711..c27a38df70c5 100644 --- a/collections/includes_value_test.ts +++ b/collections/includes_value_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { includesValue } from "./includes_value.ts"; -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; Deno.test("[collections/includesValue] Example", () => { const input = { diff --git a/collections/intersect.ts b/collections/intersect.ts index 7269bb9fe5bb..5923a5e7e133 100644 --- a/collections/intersect.ts +++ b/collections/intersect.ts @@ -10,7 +10,7 @@ import { filterInPlace } from "./_utils.ts"; * @example * ```ts * import { intersect } from "https://deno.land/std@$STD_VERSION/collections/intersect.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const lisaInterests = ["Cooking", "Music", "Hiking"]; * const kimInterests = ["Music", "Tennis", "Cooking"]; diff --git a/collections/intersect_test.ts b/collections/intersect_test.ts index 4bd8736bc5b2..1ee9624dc894 100644 --- a/collections/intersect_test.ts +++ b/collections/intersect_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { intersect } from "./intersect.ts"; function intersectTest( diff --git a/collections/join_to_string.ts b/collections/join_to_string.ts index 3a4be92d52f1..3fce4cacbdf1 100644 --- a/collections/join_to_string.ts +++ b/collections/join_to_string.ts @@ -23,7 +23,7 @@ export type JoinToStringOptions = { * @example * ```ts * import { joinToString } from "https://deno.land/std@$STD_VERSION/collections/join_to_string.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const users = [ * { name: "Kim" }, diff --git a/collections/join_to_string_test.ts b/collections/join_to_string_test.ts index c8d1f2879fe2..c8549623566e 100644 --- a/collections/join_to_string_test.ts +++ b/collections/join_to_string_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { joinToString } from "./join_to_string.ts"; Deno.test({ diff --git a/collections/map_entries.ts b/collections/map_entries.ts index 68a7022374dc..aefd57497945 100644 --- a/collections/map_entries.ts +++ b/collections/map_entries.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { mapEntries } from "https://deno.land/std@$STD_VERSION/collections/map_entries.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const usersById = { * "a2e": { name: "Kim", age: 22 }, diff --git a/collections/map_entries_test.ts b/collections/map_entries_test.ts index ccf5a928ea51..18a0e20e42b8 100644 --- a/collections/map_entries_test.ts +++ b/collections/map_entries_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { mapEntries } from "./map_entries.ts"; function mapEntriesTest( diff --git a/collections/map_keys.ts b/collections/map_keys.ts index 1b25cf23e454..291c84d22c41 100644 --- a/collections/map_keys.ts +++ b/collections/map_keys.ts @@ -11,7 +11,7 @@ * @example * ```ts * import { mapKeys } from "https://deno.land/std@$STD_VERSION/collections/map_keys.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const counts = { a: 5, b: 3, c: 8 }; * diff --git a/collections/map_keys_test.ts b/collections/map_keys_test.ts index c063c052f461..8fcdffa48314 100644 --- a/collections/map_keys_test.ts +++ b/collections/map_keys_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { mapKeys } from "./map_keys.ts"; function mapKeysTest( diff --git a/collections/map_not_nullish.ts b/collections/map_not_nullish.ts index 9410259600e6..421d15b49819 100644 --- a/collections/map_not_nullish.ts +++ b/collections/map_not_nullish.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { mapNotNullish } from "https://deno.land/std@$STD_VERSION/collections/map_not_nullish.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const people = [ * { middleName: null }, diff --git a/collections/map_not_nullish_test.ts b/collections/map_not_nullish_test.ts index e6b0584346a8..2db299cdf1d3 100644 --- a/collections/map_not_nullish_test.ts +++ b/collections/map_not_nullish_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { mapNotNullish } from "./map_not_nullish.ts"; function mapNotNullishTest( diff --git a/collections/map_values.ts b/collections/map_values.ts index de2c08466cab..a97c28ab7695 100644 --- a/collections/map_values.ts +++ b/collections/map_values.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { mapValues } from "https://deno.land/std@$STD_VERSION/collections/map_values.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const usersById = { * "a5ec": { name: "Mischa" }, diff --git a/collections/map_values_test.ts b/collections/map_values_test.ts index 7310c8daa015..2db813258f60 100644 --- a/collections/map_values_test.ts +++ b/collections/map_values_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { mapValues } from "./map_values.ts"; function mapValuesTest( diff --git a/collections/max_by.ts b/collections/max_by.ts index c2125b6be7f7..972f7a1d1b48 100644 --- a/collections/max_by.ts +++ b/collections/max_by.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { maxBy } from "https://deno.land/std@$STD_VERSION/collections/max_by.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const people = [ * { name: "Anna", age: 34 }, diff --git a/collections/max_by_test.ts b/collections/max_by_test.ts index a56fdc1baffc..4b3ef6daa4f1 100644 --- a/collections/max_by_test.ts +++ b/collections/max_by_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { maxBy } from "./max_by.ts"; Deno.test("[collections/maxBy] of array of input", () => { diff --git a/collections/max_of.ts b/collections/max_of.ts index c37872a51f64..6004d6403e2c 100644 --- a/collections/max_of.ts +++ b/collections/max_of.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { maxOf } from "https://deno.land/std@$STD_VERSION/collections/max_of.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const inventory = [ * { name: "mustard", count: 2 }, diff --git a/collections/max_of_test.ts b/collections/max_of_test.ts index 4d90fffaf5ba..8334e846bc0d 100644 --- a/collections/max_of_test.ts +++ b/collections/max_of_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { maxOf } from "./max_of.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test("[collections/maxOf] Regular max", () => { const array = [5, 18, 35, 120]; diff --git a/collections/max_with.ts b/collections/max_with.ts index f572c7d5a5b0..6fc0c5e5bbed 100644 --- a/collections/max_with.ts +++ b/collections/max_with.ts @@ -12,7 +12,7 @@ * @example * ```ts * import { maxWith } from "https://deno.land/std@$STD_VERSION/collections/max_with.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const people = ["Kim", "Anna", "John", "Arthur"]; * const largestName = maxWith(people, (a, b) => a.length - b.length); diff --git a/collections/max_with_test.ts b/collections/max_with_test.ts index f8116c5393c8..05380ed23b10 100644 --- a/collections/max_with_test.ts +++ b/collections/max_with_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { maxWith } from "./max_with.ts"; function maxWithTest( diff --git a/collections/min_by.ts b/collections/min_by.ts index 4bd42c2047c4..3bc69e5fc599 100644 --- a/collections/min_by.ts +++ b/collections/min_by.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { minBy } from "https://deno.land/std@$STD_VERSION/collections/min_by.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const people = [ * { name: "Anna", age: 34 }, diff --git a/collections/min_by_test.ts b/collections/min_by_test.ts index 69e8a415ac32..57ed17f8c9e3 100644 --- a/collections/min_by_test.ts +++ b/collections/min_by_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { minBy } from "./min_by.ts"; Deno.test("[collections/minBy] of array of input", () => { diff --git a/collections/min_of.ts b/collections/min_of.ts index ec7037e685f2..64ae52d10d05 100644 --- a/collections/min_of.ts +++ b/collections/min_of.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { minOf } from "https://deno.land/std@$STD_VERSION/collections/min_of.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const inventory = [ * { name: "mustard", count: 2 }, diff --git a/collections/min_of_test.ts b/collections/min_of_test.ts index 395bcd60ab42..1799e78bc76d 100644 --- a/collections/min_of_test.ts +++ b/collections/min_of_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { minOf } from "./min_of.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test("[collections/minOf] Regular min", () => { const array = [5, 18, 35, 120]; diff --git a/collections/min_with.ts b/collections/min_with.ts index 5b4d61d024d1..5020f3439084 100644 --- a/collections/min_with.ts +++ b/collections/min_with.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { minWith } from "https://deno.land/std@$STD_VERSION/collections/min_with.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const people = ["Kim", "Anna", "John"]; * const smallestName = minWith(people, (a, b) => a.length - b.length); diff --git a/collections/min_with_test.ts b/collections/min_with_test.ts index 8be0488acd80..cba24b92dbd2 100644 --- a/collections/min_with_test.ts +++ b/collections/min_with_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { minWith } from "./min_with.ts"; function minWithTest( diff --git a/collections/partition.ts b/collections/partition.ts index 3e24a8299588..93ece2ec6a40 100644 --- a/collections/partition.ts +++ b/collections/partition.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { partition } from "https://deno.land/std@$STD_VERSION/collections/partition.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const numbers = [5, 6, 7, 8, 9]; * const [even, odd] = partition(numbers, (it) => it % 2 == 0); diff --git a/collections/partition_entries.ts b/collections/partition_entries.ts index d2f2bb2559b9..9b7353a5f89e 100644 --- a/collections/partition_entries.ts +++ b/collections/partition_entries.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { partitionEntries } from "https://deno.land/std@$STD_VERSION/collections/partition_entries.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const menu = { * "Salad": 11, diff --git a/collections/partition_entries_test.ts b/collections/partition_entries_test.ts index 11a7ee53051f..eb23f789dfc8 100644 --- a/collections/partition_entries_test.ts +++ b/collections/partition_entries_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { partitionEntries } from "./partition_entries.ts"; function partitionEntriesTest( diff --git a/collections/partition_test.ts b/collections/partition_test.ts index 8e70f958f62f..100238301682 100644 --- a/collections/partition_test.ts +++ b/collections/partition_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { partition } from "./partition.ts"; function partitionTest( diff --git a/collections/permutations.ts b/collections/permutations.ts index c66b98cdb0a1..a75a71778a5f 100644 --- a/collections/permutations.ts +++ b/collections/permutations.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { permutations } from "https://deno.land/std@$STD_VERSION/collections/permutations.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const numbers = [ 1, 2 ]; * const windows = permutations(numbers); diff --git a/collections/permutations_test.ts b/collections/permutations_test.ts index cf614eb67d92..33bfb893d871 100644 --- a/collections/permutations_test.ts +++ b/collections/permutations_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { permutations } from "./permutations.ts"; function permutationsTest( diff --git a/collections/red_black_node_test.ts b/collections/red_black_node_test.ts index bc8997aadd6f..82ff2cc467b6 100644 --- a/collections/red_black_node_test.ts +++ b/collections/red_black_node_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertStrictEquals } from "../testing/asserts.ts"; +import { assertStrictEquals } from "../assert/mod.ts"; import { RedBlackNode } from "./red_black_node.ts"; Deno.test("[collections/RedBlackNode] constructor and from", () => { diff --git a/collections/red_black_tree.ts b/collections/red_black_tree.ts index 8fe937b9451d..cf9205924993 100644 --- a/collections/red_black_tree.ts +++ b/collections/red_black_tree.ts @@ -30,7 +30,7 @@ export * from "./_comparators.ts"; * descend, * RedBlackTree, * } from "https://deno.land/std@$STD_VERSION/collections/red_black_tree.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const values = [3, 10, 13, 4, 6, 7, 1, 14]; * const tree = new RedBlackTree(); diff --git a/collections/red_black_tree_test.ts b/collections/red_black_tree_test.ts index fc3d032d63a3..b938515b5b30 100644 --- a/collections/red_black_tree_test.ts +++ b/collections/red_black_tree_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertStrictEquals } from "../testing/asserts.ts"; +import { assertEquals, assertStrictEquals } from "../assert/mod.ts"; import { ascend, descend, RedBlackTree } from "./red_black_tree.ts"; import { Container, MyMath } from "./_test_utils.ts"; diff --git a/collections/reduce_groups.ts b/collections/reduce_groups.ts index f3383fcf2709..e7d245bef49b 100644 --- a/collections/reduce_groups.ts +++ b/collections/reduce_groups.ts @@ -10,7 +10,7 @@ import { mapValues } from "./map_values.ts"; * @example * ```ts * import { reduceGroups } from "https://deno.land/std@$STD_VERSION/collections/reduce_groups.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const votes = { * "Woody": [2, 3, 1, 4], diff --git a/collections/reduce_groups_test.ts b/collections/reduce_groups_test.ts index d7d5a940abbb..c7b666fd0766 100644 --- a/collections/reduce_groups_test.ts +++ b/collections/reduce_groups_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { reduceGroups } from "./reduce_groups.ts"; function reduceGroupsTest( diff --git a/collections/running_reduce.ts b/collections/running_reduce.ts index 85f124fb8310..50c43fb68fee 100644 --- a/collections/running_reduce.ts +++ b/collections/running_reduce.ts @@ -9,7 +9,7 @@ * @example * ```ts * import { runningReduce } from "https://deno.land/std@$STD_VERSION/collections/running_reduce.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const numbers = [1, 2, 3, 4, 5]; * const sumSteps = runningReduce(numbers, (sum, current) => sum + current, 0); diff --git a/collections/running_reduce_test.ts b/collections/running_reduce_test.ts index d607e32721ad..3a09a4599a38 100644 --- a/collections/running_reduce_test.ts +++ b/collections/running_reduce_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { runningReduce } from "./running_reduce.ts"; Deno.test({ diff --git a/collections/sample.ts b/collections/sample.ts index ea6971302083..8dc459726fe6 100644 --- a/collections/sample.ts +++ b/collections/sample.ts @@ -9,7 +9,7 @@ import { randomInteger } from "./_utils.ts"; * @example * ```ts * import { sample } from "https://deno.land/std@$STD_VERSION/collections/sample.ts"; - * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assert } from "https://deno.land/std@$STD_VERSION/assert/assert.ts"; * * const numbers = [1, 2, 3, 4]; * const random = sample(numbers); diff --git a/collections/sample_test.ts b/collections/sample_test.ts index dc2ace0be839..c5e1e064c23e 100644 --- a/collections/sample_test.ts +++ b/collections/sample_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { sample } from "./sample.ts"; Deno.test({ diff --git a/collections/sliding_windows.ts b/collections/sliding_windows.ts index 961c6db585dd..1bfb3390a271 100644 --- a/collections/sliding_windows.ts +++ b/collections/sliding_windows.ts @@ -14,7 +14,7 @@ * @example * ```ts * import { slidingWindows } from "https://deno.land/std@$STD_VERSION/collections/sliding_windows.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * const numbers = [1, 2, 3, 4, 5]; * * const windows = slidingWindows(numbers, 3); diff --git a/collections/sliding_windows_test.ts b/collections/sliding_windows_test.ts index 949ff1cfc471..613bdd3c773a 100644 --- a/collections/sliding_windows_test.ts +++ b/collections/sliding_windows_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { slidingWindows } from "./sliding_windows.ts"; function slidingWindowsTest( diff --git a/collections/sort_by.ts b/collections/sort_by.ts index d815afe222a7..d38846da1d86 100644 --- a/collections/sort_by.ts +++ b/collections/sort_by.ts @@ -17,7 +17,7 @@ export type SortByOptions = { * @example * ```ts * import { sortBy } from "https://deno.land/std@$STD_VERSION/collections/sort_by.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const people = [ * { name: "Anna", age: 34 }, diff --git a/collections/sort_by_test.ts b/collections/sort_by_test.ts index ee4071d09b03..1adac52f689f 100644 --- a/collections/sort_by_test.ts +++ b/collections/sort_by_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { sortBy } from "./sort_by.ts"; Deno.test({ diff --git a/collections/sum_of.ts b/collections/sum_of.ts index 4e5ecda55b97..d719cc5e3a68 100644 --- a/collections/sum_of.ts +++ b/collections/sum_of.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { sumOf } from "https://deno.land/std@$STD_VERSION/collections/sum_of.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const people = [ * { name: "Anna", age: 34 }, diff --git a/collections/sum_of_test.ts b/collections/sum_of_test.ts index bff6d6e00cb4..aea33c3ab106 100644 --- a/collections/sum_of_test.ts +++ b/collections/sum_of_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { sumOf } from "./sum_of.ts"; Deno.test("[collections/sumOf] On object properties", () => { diff --git a/collections/take_last_while.ts b/collections/take_last_while.ts index 9b70e4b2536f..2a27be5bafa8 100644 --- a/collections/take_last_while.ts +++ b/collections/take_last_while.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { takeLastWhile } from "https://deno.land/std@$STD_VERSION/collections/take_last_while.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const arr = [1, 2, 3, 4, 5, 6]; * diff --git a/collections/take_last_while_test.ts b/collections/take_last_while_test.ts index 504f6a17d88c..7745daad4acb 100644 --- a/collections/take_last_while_test.ts +++ b/collections/take_last_while_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { takeLastWhile } from "./take_last_while.ts"; Deno.test("[collections/takeLastWhile] Num array", () => { diff --git a/collections/take_while.ts b/collections/take_while.ts index 99de9bc4762c..a3a6944ed6bd 100644 --- a/collections/take_while.ts +++ b/collections/take_while.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { takeWhile } from "https://deno.land/std@$STD_VERSION/collections/take_while.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const arr = [1, 2, 3, 4, 5, 6]; * diff --git a/collections/take_while_test.ts b/collections/take_while_test.ts index 153701bca306..2c896c83b682 100644 --- a/collections/take_while_test.ts +++ b/collections/take_while_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { takeWhile } from "./take_while.ts"; Deno.test("[collections/takeWhile] Num array", () => { diff --git a/collections/union.ts b/collections/union.ts index 5183055f48e7..e33f4561bbc7 100644 --- a/collections/union.ts +++ b/collections/union.ts @@ -7,7 +7,7 @@ * @example * ```ts * import { union } from "https://deno.land/std@$STD_VERSION/collections/union.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const soupIngredients = ["Pepper", "Carrots", "Leek"]; * const saladIngredients = ["Carrots", "Radicchio", "Pepper"]; diff --git a/collections/union_test.ts b/collections/union_test.ts index 3dd9eff2e0aa..2d5da45145f4 100644 --- a/collections/union_test.ts +++ b/collections/union_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { union } from "./union.ts"; function unionTest( diff --git a/collections/unzip.ts b/collections/unzip.ts index 341bc4c92232..f21b3c8ca8b0 100644 --- a/collections/unzip.ts +++ b/collections/unzip.ts @@ -8,7 +8,7 @@ * * ```ts * import { unzip } from "https://deno.land/std@$STD_VERSION/collections/unzip.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const parents = [ * ["Maria", "Jeff"], diff --git a/collections/unzip_test.ts b/collections/unzip_test.ts index dceae6a6c9db..ea09746bb409 100644 --- a/collections/unzip_test.ts +++ b/collections/unzip_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { unzip } from "./unzip.ts"; function unzipTest( diff --git a/collections/without_all.ts b/collections/without_all.ts index 105dacbb2474..51683712f26c 100644 --- a/collections/without_all.ts +++ b/collections/without_all.ts @@ -7,7 +7,7 @@ * @example * ```ts * import { withoutAll } from "https://deno.land/std@$STD_VERSION/collections/without_all.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const withoutList = withoutAll([2, 1, 2, 3], [1, 2]); * diff --git a/collections/without_all_test.ts b/collections/without_all_test.ts index 4330ece5cd02..649ab27451ef 100644 --- a/collections/without_all_test.ts +++ b/collections/without_all_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { withoutAll } from "./without_all.ts"; function withoutAllTest( diff --git a/collections/zip.ts b/collections/zip.ts index 348380324147..6d7d4bcdb9bc 100644 --- a/collections/zip.ts +++ b/collections/zip.ts @@ -8,7 +8,7 @@ * @example * ```ts * import { zip } from "https://deno.land/std@$STD_VERSION/collections/zip.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * const numbers = [1, 2, 3, 4]; * const letters = ["a", "b", "c", "d"]; diff --git a/collections/zip_test.ts b/collections/zip_test.ts index 8d5c8fea9e3a..1ada9f92989b 100644 --- a/collections/zip_test.ts +++ b/collections/zip_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { zip } from "./zip.ts"; function zip1Test( diff --git a/console/_rle.ts b/console/_rle.ts index 415ba2ea3917..e66bd4c370a1 100644 --- a/console/_rle.ts +++ b/console/_rle.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; export function runLengthEncode(arr: number[]) { const data: number[] = []; diff --git a/console/_tools/generate_data.ts b/console/_tools/generate_data.ts index 473982bce844..83c227903956 100755 --- a/console/_tools/generate_data.ts +++ b/console/_tools/generate_data.ts @@ -2,7 +2,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Ported from unicode_width rust crate, Copyright (c) 2015 The Rust Project Developers. MIT license. -import { assert } from "../../_util/asserts.ts"; +import { assert } from "../../assert/assert.ts"; import { runLengthEncode } from "../_rle.ts"; // change this line and re-run the script to update for new Unicode versions diff --git a/console/unicode_width.ts b/console/unicode_width.ts index 4a78b0c74ff9..9221b4645ab1 100644 --- a/console/unicode_width.ts +++ b/console/unicode_width.ts @@ -46,7 +46,7 @@ function charWidth(ch: string) { * @example * ```ts * import { unicodeWidth } from "https://deno.land/std@$STD_VERSION/console/unicode_width.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * import { stripColor } from "https://deno.land/std@$STD_VERSION/fmt/colors.ts"; * * assertEquals(unicodeWidth("hello world"), 11); diff --git a/console/unicode_width_test.ts b/console/unicode_width_test.ts index 72c99f74be84..7b3b2da16558 100644 --- a/console/unicode_width_test.ts +++ b/console/unicode_width_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { unicodeWidth } from "./unicode_width.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test("unicodeWidth", async (t) => { await t.step("ASCII", () => { diff --git a/crypto/_benches/bench.ts b/crypto/_benches/bench.ts index ded292535e52..d1cd83f86d32 100644 --- a/crypto/_benches/bench.ts +++ b/crypto/_benches/bench.ts @@ -1,6 +1,6 @@ #!/usr/bin/env -S deno run // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../../testing/asserts.ts"; +import { assert, assertEquals } from "../../assert/mod.ts"; import { crypto as stdCrypto } from "../mod.ts"; diff --git a/crypto/_fnv/util_test.ts b/crypto/_fnv/util_test.ts index 52117138ffec..36981f8c2196 100644 --- a/crypto/_fnv/util_test.ts +++ b/crypto/_fnv/util_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../../testing/asserts.ts"; +import { assertEquals } from "../../assert/mod.ts"; import { mul32, mul64 } from "./util.ts"; Deno.test("[hash/fnv/util] mul32", () => { diff --git a/crypto/_wasm/test.ts b/crypto/_wasm/test.ts index 638923d82c0d..be0110e946db 100644 --- a/crypto/_wasm/test.ts +++ b/crypto/_wasm/test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../../testing/asserts.ts"; +import { assertEquals } from "../../assert/mod.ts"; import { instantiateWasm } from "./mod.ts"; const webCrypto = globalThis.crypto; diff --git a/crypto/crypto.ts b/crypto/crypto.ts index 114e064bbee5..5182ba1b20c6 100644 --- a/crypto/crypto.ts +++ b/crypto/crypto.ts @@ -86,7 +86,7 @@ * * ```ts * import { crypto } from "https://deno.land/std@$STD_VERSION/crypto/mod.ts"; - * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assert } from "https://deno.land/std@$STD_VERSION/assert/assert.ts"; * * const a = await crypto.subtle.digest( * "SHA-384", @@ -110,7 +110,7 @@ * * ```ts * import { timingSafeEqual } from "https://deno.land/std@$STD_VERSION/crypto/timing_safe_equal.ts"; - * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assert } from "https://deno.land/std@$STD_VERSION/assert/assert.ts"; * * const a = await crypto.subtle.digest( * "SHA-384", diff --git a/crypto/crypto_test.ts b/crypto/crypto_test.ts index 1e7c7b4447ca..05b763971da1 100644 --- a/crypto/crypto_test.ts +++ b/crypto/crypto_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { crypto as stdCrypto } from "./mod.ts"; import { repeat } from "../bytes/repeat.ts"; import { dirname, fromFileUrl } from "../path/mod.ts"; diff --git a/crypto/keystack_test.ts b/crypto/keystack_test.ts index bf4267751b76..dafd29640b79 100644 --- a/crypto/keystack_test.ts +++ b/crypto/keystack_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { KeyStack } from "./keystack.ts"; diff --git a/crypto/timing_safe_equal.ts b/crypto/timing_safe_equal.ts index 8933a209c689..e8b4c8e82665 100644 --- a/crypto/timing_safe_equal.ts +++ b/crypto/timing_safe_equal.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; /** Compare to array buffers or data views in a way that timing based attacks * cannot gain information about the platform. */ diff --git a/crypto/timing_safe_equal_test.ts b/crypto/timing_safe_equal_test.ts index ed54cefcb2ca..4a4ca7f548b7 100644 --- a/crypto/timing_safe_equal_test.ts +++ b/crypto/timing_safe_equal_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { timingSafeEqual } from "./timing_safe_equal.ts"; Deno.test({ diff --git a/crypto/to_hash_string_test.ts b/crypto/to_hash_string_test.ts index 59824dbb28e6..6ce5a41bb6a6 100644 --- a/crypto/to_hash_string_test.ts +++ b/crypto/to_hash_string_test.ts @@ -2,7 +2,7 @@ import { crypto, type DigestAlgorithm } from "./mod.ts"; import { toHashString } from "./to_hash_string.ts"; import { repeat } from "../bytes/repeat.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; const encoder = new TextEncoder(); diff --git a/csv/_io.ts b/csv/_io.ts index 5011b2a2ba68..294c3ed02eae 100644 --- a/csv/_io.ts +++ b/csv/_io.ts @@ -3,7 +3,7 @@ // Copyright 2011 The Go Authors. All rights reserved. BSD license. // https://github.com/golang/go/blob/master/LICENSE // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; export interface ReadOptions { /** Character which separates values. diff --git a/csv/csv_parse_stream_test.ts b/csv/csv_parse_stream_test.ts index b66a681153b7..e2c513c89efb 100644 --- a/csv/csv_parse_stream_test.ts +++ b/csv/csv_parse_stream_test.ts @@ -9,7 +9,7 @@ import { assertEquals, assertRejects, assertStringIncludes, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import type { AssertTrue, IsExact } from "../testing/types.ts"; import { fromFileUrl, join } from "../path/mod.ts"; import { StringReader } from "../io/string_reader.ts"; diff --git a/csv/csv_stringify_stream_test.ts b/csv/csv_stringify_stream_test.ts index a5e18a43b227..db7660604c4b 100644 --- a/csv/csv_stringify_stream_test.ts +++ b/csv/csv_stringify_stream_test.ts @@ -2,7 +2,7 @@ import { CsvStringifyStream } from "./csv_stringify_stream.ts"; import { StringifyError } from "./stringify.ts"; import { readableStreamFromIterable } from "../streams/readable_stream_from_iterable.ts"; -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; Deno.test({ name: "[csv/csv_stringify_stream] CsvStringifyStream", diff --git a/csv/parse.ts b/csv/parse.ts index 54bcf24f20b0..43320eacfff5 100644 --- a/csv/parse.ts +++ b/csv/parse.ts @@ -11,7 +11,7 @@ import { type ParseResult, type ReadOptions, } from "./_io.ts"; -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; export { ERR_BARE_QUOTE, diff --git a/csv/parse_test.ts b/csv/parse_test.ts index 8e70fb427569..1eeab4f0c2aa 100644 --- a/csv/parse_test.ts +++ b/csv/parse_test.ts @@ -4,7 +4,7 @@ // https://github.com/golang/go/blob/master/LICENSE // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assert, assertEquals, assertThrows } from "../assert/mod.ts"; import { parse, ParseError, ParseOptions } from "./parse.ts"; import type { AssertTrue, IsExact } from "../testing/types.ts"; diff --git a/csv/stringify_test.ts b/csv/stringify_test.ts index ccb5f45db2e9..63146456a94c 100644 --- a/csv/stringify_test.ts +++ b/csv/stringify_test.ts @@ -9,7 +9,7 @@ import { assertEquals, assertStringIncludes, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import { stringify, StringifyError } from "./stringify.ts"; const CRLF = "\r\n"; diff --git a/datetime/constants_test.ts b/datetime/constants_test.ts index 909d41c966b6..d4d1cfd04d78 100644 --- a/datetime/constants_test.ts +++ b/datetime/constants_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { DAY, HOUR, MINUTE, SECOND, WEEK } from "./constants.ts"; Deno.test({ diff --git a/datetime/day_of_year_test.ts b/datetime/day_of_year_test.ts index 25568c85a167..7c0ac57c5a62 100644 --- a/datetime/day_of_year_test.ts +++ b/datetime/day_of_year_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { dayOfYear, dayOfYearUtc } from "./day_of_year.ts"; Deno.test({ diff --git a/datetime/difference_test.ts b/datetime/difference_test.ts index c929d091a1c3..0be9f13f6aed 100644 --- a/datetime/difference_test.ts +++ b/datetime/difference_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { difference } from "./difference.ts"; Deno.test({ diff --git a/datetime/format_test.ts b/datetime/format_test.ts index 6f09771c8dcd..f6f5ca57f3ae 100644 --- a/datetime/format_test.ts +++ b/datetime/format_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { format } from "./format.ts"; Deno.test({ diff --git a/datetime/is_leap_test.ts b/datetime/is_leap_test.ts index 0e90f1226ff6..3aaf9c7786ac 100644 --- a/datetime/is_leap_test.ts +++ b/datetime/is_leap_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { isLeap, isUtcLeap } from "./is_leap.ts"; Deno.test({ diff --git a/datetime/parse_test.ts b/datetime/parse_test.ts index 98f73a5d10fa..d45155242880 100644 --- a/datetime/parse_test.ts +++ b/datetime/parse_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { FakeTime } from "../testing/time.ts"; import { parse } from "./parse.ts"; diff --git a/datetime/to_imf_test.ts b/datetime/to_imf_test.ts index 07e181f1b3b5..84d0e7a208c8 100644 --- a/datetime/to_imf_test.ts +++ b/datetime/to_imf_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { toIMF } from "./to_imf.ts"; Deno.test({ diff --git a/datetime/week_of_year_test.ts b/datetime/week_of_year_test.ts index 1b1f13f91a26..82c18c187d45 100644 --- a/datetime/week_of_year_test.ts +++ b/datetime/week_of_year_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { weekOfYear } from "./week_of_year.ts"; Deno.test({ diff --git a/deno.json b/deno.json index b8728c69dcc5..98adcd459ab6 100644 --- a/deno.json +++ b/deno.json @@ -13,8 +13,7 @@ "fmt:licence-headers": "deno run --allow-read --allow-write ./_tools/check_licence.ts", "lint:deprecations": "deno run --allow-read --allow-net ./_tools/check_deprecation.ts", "lint:doc-imports": "deno run --allow-env --allow-read ./_tools/check_doc_imports.ts", - "lint:check-assertions": "deno run --allow-read --allow-net ./_tools/check_assertions.ts", - "lint": "deno lint && deno task fmt:licence-headers --check && deno task lint:deprecations && deno task lint:doc-imports && deno task lint:check-assertions", + "lint": "deno lint && deno task fmt:licence-headers --check && deno task lint:deprecations && deno task lint:doc-imports", "typos": "typos -c ./.github/workflows/typos.toml", "build:crypto": "deno task --cwd crypto/_wasm wasmbuild", "wasmbuild": "deno run --unstable -A https://deno.land/x/wasmbuild@0.10.3/main.ts --js-ext mjs --sync" diff --git a/dotenv/load_test.ts b/dotenv/load_test.ts index f84e58e53e95..4844094a5244 100644 --- a/dotenv/load_test.ts +++ b/dotenv/load_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "../path/mod.ts"; const moduleDir = path.dirname(path.fromFileUrl(import.meta.url)); diff --git a/dotenv/mod_test.ts b/dotenv/mod_test.ts index 8e567747b05c..73b1299a2f55 100644 --- a/dotenv/mod_test.ts +++ b/dotenv/mod_test.ts @@ -6,7 +6,7 @@ import { assertStrictEquals, assertStringIncludes, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import { load, type LoadOptions, diff --git a/encoding/ascii85_test.ts b/encoding/ascii85_test.ts index 3af1b24a6c37..75afd0924d42 100644 --- a/encoding/ascii85_test.ts +++ b/encoding/ascii85_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { Ascii85Standard, decode, encode } from "./ascii85.ts"; type TestCases = Partial<{ [index in Ascii85Standard]: string[][] }>; const utf8encoder = new TextEncoder(); diff --git a/encoding/base32_test.ts b/encoding/base32_test.ts index ecaf0dfd56b4..5e91b35fcc52 100644 --- a/encoding/base32_test.ts +++ b/encoding/base32_test.ts @@ -1,7 +1,7 @@ // 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 "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { decode, encode } from "./base32.ts"; // Lifted from https://stackoverflow.com/questions/38987784 diff --git a/encoding/base58_test.ts b/encoding/base58_test.ts index fa3e4e5c9fc4..1c3d356d6534 100644 --- a/encoding/base58_test.ts +++ b/encoding/base58_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { decode, encode } from "./base58.ts"; const testSetString = [ diff --git a/encoding/base64_test.ts b/encoding/base64_test.ts index afbd2d656927..2a574e77cdb7 100644 --- a/encoding/base64_test.ts +++ b/encoding/base64_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { decode, encode } from "./base64.ts"; const testsetString = [ diff --git a/encoding/base64url_test.ts b/encoding/base64url_test.ts index 807a82e8830f..6467ddb3b700 100644 --- a/encoding/base64url_test.ts +++ b/encoding/base64url_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { decode, encode } from "./base64url.ts"; const testsetString = [ diff --git a/encoding/binary_test.ts b/encoding/binary_test.ts index 3dbdc3f497f3..eb113a1b96c4 100644 --- a/encoding/binary_test.ts +++ b/encoding/binary_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { getNBytes, putVarbig, diff --git a/encoding/hex_test.ts b/encoding/hex_test.ts index 72290771fac5..cdd1065d5b32 100644 --- a/encoding/hex_test.ts +++ b/encoding/hex_test.ts @@ -4,7 +4,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { decode, encode } from "./hex.ts"; diff --git a/encoding/varint_test.ts b/encoding/varint_test.ts index f1bb25f7b03d..b34f486e37f3 100644 --- a/encoding/varint_test.ts +++ b/encoding/varint_test.ts @@ -2,7 +2,7 @@ // Copyright 2020 Keith Cirkel. All rights reserved. MIT license. // This implementation is a port of https://deno.land/x/varint@v2.0.0 by @keithamus -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { decode, decode32, diff --git a/examples/cat_test.ts b/examples/cat_test.ts index 88f4297af064..27482e99154a 100644 --- a/examples/cat_test.ts +++ b/examples/cat_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertStrictEquals } from "../testing/asserts.ts"; +import { assertStrictEquals } from "../assert/mod.ts"; import { dirname, fromFileUrl } from "../path/mod.ts"; const moduleDir = dirname(fromFileUrl(import.meta.url)); diff --git a/examples/catj_test.ts b/examples/catj_test.ts index 4ee823d21d5c..6b3a9c218321 100644 --- a/examples/catj_test.ts +++ b/examples/catj_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertStrictEquals } from "../testing/asserts.ts"; +import { assertStrictEquals } from "../assert/mod.ts"; import { dirname, fromFileUrl } from "../path/mod.ts"; const moduleDir = dirname(fromFileUrl(import.meta.url)); diff --git a/examples/chat/server_test.ts b/examples/chat/server_test.ts index f9f6c864a0ce..4f33002c13b2 100644 --- a/examples/chat/server_test.ts +++ b/examples/chat/server_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../../testing/asserts.ts"; +import { assert, assertEquals } from "../../assert/mod.ts"; import { dirname, fromFileUrl, resolve } from "../../path/mod.ts"; const moduleDir = resolve(dirname(fromFileUrl(import.meta.url))); diff --git a/examples/colors_test.ts b/examples/colors_test.ts index 16a2cc8cb3c2..83a2f4912c14 100644 --- a/examples/colors_test.ts +++ b/examples/colors_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertStrictEquals } from "../testing/asserts.ts"; +import { assertStrictEquals } from "../assert/mod.ts"; import { dirname, fromFileUrl } from "../path/mod.ts"; const moduleDir = dirname(fromFileUrl(import.meta.url)); diff --git a/examples/curl_test.ts b/examples/curl_test.ts index 0d1edfd76918..16a40631b306 100644 --- a/examples/curl_test.ts +++ b/examples/curl_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { serve } from "../http/server.ts"; -import { assertStrictEquals } from "../testing/asserts.ts"; +import { assertStrictEquals } from "../assert/mod.ts"; import { dirname, fromFileUrl } from "../path/mod.ts"; const moduleDir = dirname(fromFileUrl(import.meta.url)); diff --git a/examples/echo_server_test.ts b/examples/echo_server_test.ts index e03531fbf769..c40b6a656ba1 100644 --- a/examples/echo_server_test.ts +++ b/examples/echo_server_test.ts @@ -3,7 +3,7 @@ import { assertEquals, assertNotEquals, assertStrictEquals, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import { BufReader, ReadLineResult } from "../io/buf_reader.ts"; import { dirname, fromFileUrl } from "../path/mod.ts"; import { TextLineStream } from "../streams/text_line_stream.ts"; diff --git a/examples/test.ts b/examples/test.ts index 4b270b2e0f49..37d2d4777306 100644 --- a/examples/test.ts +++ b/examples/test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { dirname, fromFileUrl, relative, resolve } from "../path/mod.ts"; const moduleDir = dirname(fromFileUrl(import.meta.url)); diff --git a/examples/welcome_test.ts b/examples/welcome_test.ts index 5c27eb6f3d85..14f40728c8ec 100644 --- a/examples/welcome_test.ts +++ b/examples/welcome_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertStrictEquals } from "../testing/asserts.ts"; +import { assertStrictEquals } from "../assert/mod.ts"; import { dirname, fromFileUrl } from "../path/mod.ts"; const moduleDir = dirname(fromFileUrl(import.meta.url)); diff --git a/examples/xeval_test.ts b/examples/xeval_test.ts index 8953d0b66849..292012e3a66a 100644 --- a/examples/xeval_test.ts +++ b/examples/xeval_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { xeval } from "./xeval.ts"; -import { assertEquals, assertStringIncludes } from "../testing/asserts.ts"; +import { assertEquals, assertStringIncludes } from "../assert/mod.ts"; import { dirname, fromFileUrl } from "../path/mod.ts"; const moduleDir = dirname(fromFileUrl(import.meta.url)); diff --git a/flags/mod.ts b/flags/mod.ts index e76e2064fe40..dce276aa7777 100644 --- a/flags/mod.ts +++ b/flags/mod.ts @@ -33,7 +33,7 @@ * * @module */ -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; /** Combines recursively all intersection types and returns a new single type. */ type Id = TRecord extends Record diff --git a/flags/test.ts b/flags/test.ts index 7e01876bb590..f8de71fdbd48 100644 --- a/flags/test.ts +++ b/flags/test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { Args, parse, ParseOptions } from "./mod.ts"; import { assertType, IsExact } from "../testing/types.ts"; diff --git a/fmt/bytes_test.ts b/fmt/bytes_test.ts index 49bb5f6327b3..7c3880c52977 100644 --- a/fmt/bytes_test.ts +++ b/fmt/bytes_test.ts @@ -3,7 +3,7 @@ // Copyright 2021 Yoshiya Hinosawa. All rights reserved. MIT license. import { format } from "./bytes.ts"; -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; const parts = new Intl.NumberFormat().formatToParts(1000.1); const decimal = parts.find(({ type }) => type === "decimal")!.value; diff --git a/fmt/colors_test.ts b/fmt/colors_test.ts index 48bc73f4b28c..a949b76bb82e 100644 --- a/fmt/colors_test.ts +++ b/fmt/colors_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as c from "./colors.ts"; import "../examples/colors.ts"; diff --git a/fmt/duration_test.ts b/fmt/duration_test.ts index b32b155d4f49..9e0b872ce526 100644 --- a/fmt/duration_test.ts +++ b/fmt/duration_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertExists } from "../testing/asserts.ts"; +import { assertEquals, assertExists } from "../assert/mod.ts"; import { format } from "./duration.ts"; Deno.test({ diff --git a/fmt/printf_test.ts b/fmt/printf_test.ts index c9b1e9334c03..1efa55a2fa49 100644 --- a/fmt/printf_test.ts +++ b/fmt/printf_test.ts @@ -6,7 +6,7 @@ // BSD: Copyright (c) 2009 The Go Authors. All rights reserved. import { sprintf } from "./printf.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; const S = sprintf; diff --git a/front_matter/_test_utils.ts b/front_matter/_test_utils.ts index ee3639ad5ba0..76e370ff0887 100644 --- a/front_matter/_test_utils.ts +++ b/front_matter/_test_utils.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assert, assertEquals, assertThrows } from "../assert/mod.ts"; import { dirname, fromFileUrl, join, resolve } from "../path/mod.ts"; import { Format } from "./mod.ts"; diff --git a/front_matter/mod.ts b/front_matter/mod.ts index 9a4ab94ca2d2..77d28b1b584c 100644 --- a/front_matter/mod.ts +++ b/front_matter/mod.ts @@ -253,7 +253,7 @@ function _extract( * * ```ts * import { createExtractor, Format, Parser } from "https://deno.land/std@$STD_VERSION/front_matter/mod.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * import { parse as parseYAML } from "https://deno.land/std@$STD_VERSION/yaml/parse.ts"; * import { parse as parseTOML } from "https://deno.land/std@$STD_VERSION/toml/parse.ts"; * const extractYAML = createExtractor({ [Format.YAML]: parseYAML as Parser }); @@ -315,7 +315,7 @@ export function createExtractor( * * ```ts * import { test, Format } from "https://deno.land/std@$STD_VERSION/front_matter/mod.ts"; - * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assert } from "https://deno.land/std@$STD_VERSION/assert/assert.ts"; * * assert(test("---\ntitle: Three dashes marks the spot\n---\n")); * assert(test("---toml\ntitle = 'Three dashes followed by format marks the spot'\n---\n")); @@ -351,7 +351,7 @@ export function test(str: string, formats?: Format[]): boolean { * * ```ts * import { recognize, Format } from "https://deno.land/std@$STD_VERSION/front_matter/mod.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * assertEquals(recognize("---\ntitle: Three dashes marks the spot\n---\n"), Format.YAML); * assertEquals(recognize("---toml\ntitle = 'Three dashes followed by format marks the spot'\n---\n"), Format.TOML); diff --git a/front_matter/mod_test.ts b/front_matter/mod_test.ts index 361484c36f01..f2a012d9fb71 100644 --- a/front_matter/mod_test.ts +++ b/front_matter/mod_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertThrows } from "../testing/asserts.ts"; +import { assert, assertThrows } from "../assert/mod.ts"; import { createExtractor, Format, Parser, test } from "./mod.ts"; import { parse as parseYAML } from "../yaml/parse.ts"; import { parse as parseTOML } from "../toml/parse.ts"; diff --git a/fs/_util_test.ts b/fs/_util_test.ts index 5276c82e97ad..39e8cafd68f3 100644 --- a/fs/_util_test.ts +++ b/fs/_util_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright the Browserify authors. MIT License. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { getFileInfoType, isSamePath, isSubdir, PathType } from "./_util.ts"; import { ensureFileSync } from "./ensure_file.ts"; diff --git a/fs/copy.ts b/fs/copy.ts index 3d7851a6b747..e66457089539 100644 --- a/fs/copy.ts +++ b/fs/copy.ts @@ -4,7 +4,7 @@ import * as path from "../path/mod.ts"; import { ensureDir, ensureDirSync } from "./ensure_dir.ts"; import { getFileInfoType, isSubdir, toPathString } from "./_util.ts"; -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import { isWindows } from "../_util/os.ts"; export interface CopyOptions { diff --git a/fs/copy_test.ts b/fs/copy_test.ts index bd98b0351a6d..64625460624c 100644 --- a/fs/copy_test.ts +++ b/fs/copy_test.ts @@ -4,7 +4,7 @@ import { assertEquals, assertRejects, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { copy, copySync } from "./copy.ts"; import { existsSync } from "./exists.ts"; diff --git a/fs/empty_dir_test.ts b/fs/empty_dir_test.ts index 70a088c97ba7..e189df3ba4a2 100644 --- a/fs/empty_dir_test.ts +++ b/fs/empty_dir_test.ts @@ -4,7 +4,7 @@ import { assertRejects, assertStringIncludes, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { emptyDir, emptyDirSync } from "./empty_dir.ts"; diff --git a/fs/ensure_dir_test.ts b/fs/ensure_dir_test.ts index d1075d3add48..5750da10fa2a 100644 --- a/fs/ensure_dir_test.ts +++ b/fs/ensure_dir_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertRejects, assertThrows } from "../testing/asserts.ts"; +import { assertRejects, assertThrows } from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { ensureDir, ensureDirSync } from "./ensure_dir.ts"; import { ensureFile, ensureFileSync } from "./ensure_file.ts"; diff --git a/fs/ensure_file_test.ts b/fs/ensure_file_test.ts index bd492ffd8452..0a06daa97548 100644 --- a/fs/ensure_file_test.ts +++ b/fs/ensure_file_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertRejects, assertThrows } from "../testing/asserts.ts"; +import { assertRejects, assertThrows } from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { ensureFile, ensureFileSync } from "./ensure_file.ts"; diff --git a/fs/ensure_link_test.ts b/fs/ensure_link_test.ts index 9deefbca17aa..2d0cbf270132 100644 --- a/fs/ensure_link_test.ts +++ b/fs/ensure_link_test.ts @@ -1,10 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // TODO(axetroy): Add test for Windows once symlink is implemented for Windows. -import { - assertEquals, - assertRejects, - assertThrows, -} from "../testing/asserts.ts"; +import { assertEquals, assertRejects, assertThrows } from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { ensureLink, ensureLinkSync } from "./ensure_link.ts"; diff --git a/fs/ensure_symlink_test.ts b/fs/ensure_symlink_test.ts index 3e59220b481b..f7b86a4b0689 100644 --- a/fs/ensure_symlink_test.ts +++ b/fs/ensure_symlink_test.ts @@ -1,10 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // TODO(axetroy): Add test for Windows once symlink is implemented for Windows. -import { - assertEquals, - assertRejects, - assertThrows, -} from "../testing/asserts.ts"; +import { assertEquals, assertRejects, assertThrows } from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { ensureSymlink, ensureSymlinkSync } from "./ensure_symlink.ts"; diff --git a/fs/eol_test.ts b/fs/eol_test.ts index df31f92397a0..9807b038bef9 100644 --- a/fs/eol_test.ts +++ b/fs/eol_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { detect, EOL, format } from "./eol.ts"; const CRLFinput = "deno\r\nis not\r\nnode"; diff --git a/fs/exists_test.ts b/fs/exists_test.ts index b009cbe60d01..4a822a1cfb08 100644 --- a/fs/exists_test.ts +++ b/fs/exists_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertStringIncludes } from "../testing/asserts.ts"; +import { assertEquals, assertStringIncludes } from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { exists, existsSync } from "./exists.ts"; diff --git a/fs/expand_glob.ts b/fs/expand_glob.ts index c2510dbb0b63..25146d29699f 100644 --- a/fs/expand_glob.ts +++ b/fs/expand_glob.ts @@ -9,7 +9,7 @@ import { SEP_PATTERN, } from "../path/mod.ts"; import { walk, walkSync } from "./walk.ts"; -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import { isWindows } from "../_util/os.ts"; import { createWalkEntry, diff --git a/fs/expand_glob_test.ts b/fs/expand_glob_test.ts index 36ad80dce683..61d1993fd6e8 100644 --- a/fs/expand_glob_test.ts +++ b/fs/expand_glob_test.ts @@ -1,9 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { - assert, - assertEquals, - assertStringIncludes, -} from "../testing/asserts.ts"; +import { assert, assertEquals, assertStringIncludes } from "../assert/mod.ts"; import { fromFileUrl, join, diff --git a/fs/move_test.ts b/fs/move_test.ts index 7e514a1d9f92..095342bd4112 100644 --- a/fs/move_test.ts +++ b/fs/move_test.ts @@ -4,7 +4,7 @@ import { assertEquals, assertRejects, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import * as path from "../path/mod.ts"; import { move, moveSync, SubdirectoryMoveError } from "./move.ts"; import { ensureFile, ensureFileSync } from "./ensure_file.ts"; diff --git a/fs/walk.ts b/fs/walk.ts index fc7c746e0061..05323f63b69c 100644 --- a/fs/walk.ts +++ b/fs/walk.ts @@ -2,7 +2,7 @@ // Documentation and interface for walk were adapted from Go // https://golang.org/pkg/path/filepath/#Walk // Copyright 2009 The Go Authors. All rights reserved. BSD license. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import { join, normalize } from "../path/mod.ts"; import { createWalkEntry, @@ -70,7 +70,7 @@ export type { WalkEntry }; * @example * ```ts * import { walk } from "https://deno.land/std@$STD_VERSION/fs/walk.ts"; - * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assert } from "https://deno.land/std@$STD_VERSION/assert/assert.ts"; * * for await (const entry of walk(".")) { * console.log(entry.path); diff --git a/fs/walk_test.ts b/fs/walk_test.ts index e3afc2fa92e7..ad20462755d2 100644 --- a/fs/walk_test.ts +++ b/fs/walk_test.ts @@ -6,7 +6,7 @@ import { assertEquals, assertRejects, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; export function testWalk( setup: (arg0: string) => any | Promise, diff --git a/html/entities.ts b/html/entities.ts index adba24260ecf..e954c9fe449e 100644 --- a/html/entities.ts +++ b/html/entities.ts @@ -27,7 +27,7 @@ const rawRe = new RegExp(`[${[...rawToEntity.keys()].join("")}]`, "g"); * @example * ```ts * import { escape } from "https://deno.land/std@$STD_VERSION/html/entities.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * assertEquals(escape("<>'&AA"), "<>'&AA"); * @@ -59,7 +59,7 @@ const entityListRegexCache = new WeakMap(); * @example * ```ts * import { unescape } from "https://deno.land/std@$STD_VERSION/html/entities.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * // default options (only handles &<>'" and numeric entities) * assertEquals(unescape("<>'&AA"), "<>'&AA"); diff --git a/html/entities_test.ts b/html/entities_test.ts index 1fdd20cb78fe..4da3344ee1bf 100644 --- a/html/entities_test.ts +++ b/html/entities_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { escape, unescape } from "./entities.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import entityList from "./named_entity_list.json" assert { type: "json" }; Deno.test("escape", async (t) => { diff --git a/http/cookie.ts b/http/cookie.ts index 037a294cf3d0..bae4d060e707 100644 --- a/http/cookie.ts +++ b/http/cookie.ts @@ -3,7 +3,7 @@ // https://github.com/golang/go/blob/master/src/net/http/cookie.go // This module is browser compatible. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import { toIMF } from "../datetime/to_imf.ts"; export interface Cookie { diff --git a/http/cookie_map_test.ts b/http/cookie_map_test.ts index 336be08e392f..cbc7ca07126a 100644 --- a/http/cookie_map_test.ts +++ b/http/cookie_map_test.ts @@ -5,7 +5,7 @@ import { assertEquals, assertRejects, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import { KeyStack } from "../crypto/keystack.ts"; import { diff --git a/http/cookie_test.ts b/http/cookie_test.ts index 06007e70c267..2f4801c7d29a 100644 --- a/http/cookie_test.ts +++ b/http/cookie_test.ts @@ -5,7 +5,7 @@ import { getSetCookies, setCookie, } from "./cookie.ts"; -import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assert, assertEquals, assertThrows } from "../assert/mod.ts"; Deno.test({ name: "Cookie parser", diff --git a/http/etag.ts b/http/etag.ts index 27b04415bbeb..d44bf02b7837 100644 --- a/http/etag.ts +++ b/http/etag.ts @@ -83,7 +83,7 @@ async function calcFileInfo( * * ```ts * import { calculate } from "https://deno.land/std@$STD_VERSION/http/etag.ts"; - * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts" + * import { assert } from "https://deno.land/std@$STD_VERSION/assert/assert.ts" * * const body = "hello deno!"; * @@ -119,7 +119,7 @@ export async function calculate( * ifMatch, * } from "https://deno.land/std@$STD_VERSION/http/etag.ts"; * import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts"; - * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts" + * import { assert } from "https://deno.land/std@$STD_VERSION/assert/assert.ts" * * const body = "hello deno!"; * @@ -163,7 +163,7 @@ export function ifMatch( * ifNoneMatch, * } from "https://deno.land/std@$STD_VERSION/http/etag.ts"; * import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts"; - * import { assert } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts" + * import { assert } from "https://deno.land/std@$STD_VERSION/assert/assert.ts" * * const body = "hello deno!"; * diff --git a/http/etag_test.ts b/http/etag_test.ts index 9a09912a84c6..615ae0b7529f 100644 --- a/http/etag_test.ts +++ b/http/etag_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { calculate, ifMatch, ifNoneMatch } from "./etag.ts"; diff --git a/http/file_server_test.ts b/http/file_server_test.ts index 1be87a3b4ac6..06e9abd9d96e 100644 --- a/http/file_server_test.ts +++ b/http/file_server_test.ts @@ -1,9 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { - assert, - assertEquals, - assertStringIncludes, -} from "../testing/asserts.ts"; +import { assert, assertEquals, assertStringIncludes } from "../assert/mod.ts"; import { stub } from "../testing/mock.ts"; import { iterateReader } from "../streams/iterate_reader.ts"; import { writeAll } from "../streams/write_all.ts"; @@ -1364,7 +1360,7 @@ Deno.test( const code = ` import { serveFile } from "${import.meta.resolve("./file_server.ts")}"; import { fromFileUrl } from "${import.meta.resolve("../path/mod.ts")}"; - import { assertEquals } from "${import.meta.resolve("../testing/asserts.ts")}"; + import { assertEquals } from "${import.meta.resolve("../assert/assert_equals.ts")}"; const testdataPath = "${toFileUrl(join(testdataDir, "test file.txt"))}"; const fileInfo = await Deno.stat(new URL(testdataPath)); fileInfo.mtime = null; diff --git a/http/http_errors_test.ts b/http/http_errors_test.ts index 5d4a84e61015..2e328f2746ea 100644 --- a/http/http_errors_test.ts +++ b/http/http_errors_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertInstanceOf } from "../testing/asserts.ts"; +import { assert, assertEquals, assertInstanceOf } from "../assert/mod.ts"; import { type ErrorStatus, Status, STATUS_TEXT } from "./http_status.ts"; diff --git a/http/http_status_test.ts b/http/http_status_test.ts index c23fee05287d..fa605378b9b3 100644 --- a/http/http_status_test.ts +++ b/http/http_status_test.ts @@ -10,7 +10,7 @@ import { Status, STATUS_TEXT, } from "./http_status.ts"; -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; Deno.test({ name: "http/http_status - Status", diff --git a/http/method_test.ts b/http/method_test.ts index 2d23c6f36234..9386564f6513 100644 --- a/http/method_test.ts +++ b/http/method_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { HTTP_METHODS, isHttpMethod } from "./method.ts"; diff --git a/http/negotiation_test.ts b/http/negotiation_test.ts index 6aecadeb0daf..de9a6848b314 100644 --- a/http/negotiation_test.ts +++ b/http/negotiation_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { accepts, acceptsEncodings, acceptsLanguages } from "./negotiation.ts"; Deno.test({ diff --git a/http/server_sent_event.ts b/http/server_sent_event.ts index df2d3bed587a..e7f9381d42db 100644 --- a/http/server_sent_event.ts +++ b/http/server_sent_event.ts @@ -44,7 +44,7 @@ * @module */ -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; const encoder = new TextEncoder(); diff --git a/http/server_sent_event_test.ts b/http/server_sent_event_test.ts index 28062a28fb1f..667b61086f90 100644 --- a/http/server_sent_event_test.ts +++ b/http/server_sent_event_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { ServerSentEvent, ServerSentEventStreamTarget, diff --git a/http/server_test.ts b/http/server_test.ts index 03d1798456ac..a6baee4d4da5 100644 --- a/http/server_test.ts +++ b/http/server_test.ts @@ -13,7 +13,7 @@ import { assertStrictEquals, assertThrows, unreachable, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; const moduleDir = dirname(fromFileUrl(import.meta.url)); const testdataDir = resolve(moduleDir, "testdata"); diff --git a/http/user_agent.ts b/http/user_agent.ts index e5688993edb1..9967d5a7317f 100644 --- a/http/user_agent.ts +++ b/http/user_agent.ts @@ -11,7 +11,7 @@ * @module */ -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; const ARCHITECTURE = "architecture"; const MODEL = "model"; diff --git a/http/user_agent_test.ts b/http/user_agent_test.ts index 35ce0354d3ef..96c8249b90b1 100644 --- a/http/user_agent_test.ts +++ b/http/user_agent_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/assert_equals.ts"; import { UserAgent } from "./user_agent.ts"; Deno.test({ diff --git a/io/buf_reader.ts b/io/buf_reader.ts index 91f3e4035f9c..38d600befd4b 100644 --- a/io/buf_reader.ts +++ b/io/buf_reader.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import { copy } from "../bytes/copy.ts"; import type { Reader } from "../types.d.ts"; diff --git a/io/buf_reader_test.ts b/io/buf_reader_test.ts index f93626820e06..94ba68c29bbb 100644 --- a/io/buf_reader_test.ts +++ b/io/buf_reader_test.ts @@ -2,12 +2,7 @@ // This code has been ported almost directly from Go's src/bytes/buffer_test.go // Copyright 2009 The Go Authors. All rights reserved. BSD license. // https://github.com/golang/go/blob/master/LICENSE -import { - assert, - assertEquals, - assertRejects, - fail, -} from "../testing/asserts.ts"; +import { assert, assertEquals, assertRejects, fail } from "../assert/mod.ts"; import { BufferFullError, BufReader, PartialReadError } from "./buf_reader.ts"; import { StringReader } from "./string_reader.ts"; import { bufsizes, MIN_READ_BUFFER_SIZE } from "./_test_common.ts"; diff --git a/io/buf_writer_test.ts b/io/buf_writer_test.ts index 53ebbd0e2ff4..328b57625964 100644 --- a/io/buf_writer_test.ts +++ b/io/buf_writer_test.ts @@ -2,7 +2,7 @@ // This code has been ported almost directly from Go's src/bytes/buffer_test.go // Copyright 2009 The Go Authors. All rights reserved. BSD license. // https://github.com/golang/go/blob/master/LICENSE -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { BufWriter, BufWriterSync } from "./buf_writer.ts"; import { Buffer } from "./buffer.ts"; import { StringWriter } from "./string_writer.ts"; diff --git a/io/buffer.ts b/io/buffer.ts index e24ed1e79cf4..e817a61fe3f9 100644 --- a/io/buffer.ts +++ b/io/buffer.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import { copy } from "../bytes/copy.ts"; import type { Reader, ReaderSync } from "../types.d.ts"; diff --git a/io/buffer_test.ts b/io/buffer_test.ts index eabf094ad722..d0728e6991cf 100644 --- a/io/buffer_test.ts +++ b/io/buffer_test.ts @@ -8,7 +8,7 @@ import { assertEquals, assertRejects, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import { Buffer } from "./buffer.ts"; import { writeAllSync } from "../streams/write_all.ts"; diff --git a/io/copy_n.ts b/io/copy_n.ts index 127b336cbe42..34c0bf38da7d 100644 --- a/io/copy_n.ts +++ b/io/copy_n.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import type { Reader, Writer } from "../types.d.ts"; const DEFAULT_BUFFER_SIZE = 32 * 1024; diff --git a/io/copy_n_test.ts b/io/copy_n_test.ts index 2ed83181cea9..0e56e57fb66f 100644 --- a/io/copy_n_test.ts +++ b/io/copy_n_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { copyN } from "./copy_n.ts"; import { Buffer } from "./buffer.ts"; import { StringReader } from "./string_reader.ts"; diff --git a/io/limited_reader_test.ts b/io/limited_reader_test.ts index 1a250d8f31c7..d6d220515591 100644 --- a/io/limited_reader_test.ts +++ b/io/limited_reader_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { LimitedReader } from "./limited_reader.ts"; import { StringWriter } from "./string_writer.ts"; import { copy } from "../streams/copy.ts"; diff --git a/io/multi_reader_test.ts b/io/multi_reader_test.ts index bac2f79d5912..909ffbba7315 100644 --- a/io/multi_reader_test.ts +++ b/io/multi_reader_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { MultiReader } from "./multi_reader.ts"; import { StringWriter } from "./string_writer.ts"; import { copyN } from "./copy_n.ts"; diff --git a/io/read_int_test.ts b/io/read_int_test.ts index a0202c8ffb58..5e69cd950a62 100644 --- a/io/read_int_test.ts +++ b/io/read_int_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { readInt } from "./read_int.ts"; import { BufReader } from "./buf_reader.ts"; import { BinaryReader } from "./_test_common.ts"; diff --git a/io/read_lines_test.ts b/io/read_lines_test.ts index ee702d42515d..9b43322601d6 100644 --- a/io/read_lines_test.ts +++ b/io/read_lines_test.ts @@ -2,7 +2,7 @@ // This code has been ported almost directly from Go's src/bytes/buffer_test.go // Copyright 2009 The Go Authors. All rights reserved. BSD license. // https://github.com/golang/go/blob/master/LICENSE -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { Buffer } from "./buffer.ts"; import { readLines } from "./read_lines.ts"; import { readStringDelim } from "./read_string_delim.ts"; diff --git a/io/read_long_test.ts b/io/read_long_test.ts index 394e584c4b3d..2db613b7aa60 100644 --- a/io/read_long_test.ts +++ b/io/read_long_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { readLong } from "./read_long.ts"; import { BufReader } from "./buf_reader.ts"; import { BinaryReader } from "./_test_common.ts"; diff --git a/io/read_range.ts b/io/read_range.ts index 41a45d92fc31..204a17712444 100644 --- a/io/read_range.ts +++ b/io/read_range.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { copy as copyBytes } from "../bytes/copy.ts"; -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import type { Reader, ReaderSync } from "../types.d.ts"; const DEFAULT_BUFFER_SIZE = 32 * 1024; @@ -20,7 +20,7 @@ export interface ByteRange { * range. * * ```ts - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * import { readRange } from "https://deno.land/std@$STD_VERSION/io/read_range.ts"; * * // Read the first 10 bytes of a file @@ -58,7 +58,7 @@ export async function readRange( * within that range. * * ```ts - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * import { readRangeSync } from "https://deno.land/std@$STD_VERSION/io/read_range.ts"; * * // Read the first 10 bytes of a file diff --git a/io/read_range_test.ts b/io/read_range_test.ts index 4d9e20f5ff28..41b382fe2330 100644 --- a/io/read_range_test.ts +++ b/io/read_range_test.ts @@ -6,7 +6,7 @@ import { assertEquals, assertRejects, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import { readRange, readRangeSync } from "./read_range.ts"; import type { Closer, Reader, ReaderSync } from "../types.d.ts"; diff --git a/io/read_short_test.ts b/io/read_short_test.ts index 649aff53bba3..ff501072dad1 100644 --- a/io/read_short_test.ts +++ b/io/read_short_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { readShort } from "./read_short.ts"; import { BufReader } from "./buf_reader.ts"; import { BinaryReader } from "./_test_common.ts"; diff --git a/io/read_string_delim_test.ts b/io/read_string_delim_test.ts index 6cc7e7b8527c..d58d9db51978 100644 --- a/io/read_string_delim_test.ts +++ b/io/read_string_delim_test.ts @@ -2,7 +2,7 @@ // This code has been ported almost directly from Go's src/bytes/buffer_test.go // Copyright 2009 The Go Authors. All rights reserved. BSD license. // https://github.com/golang/go/blob/master/LICENSE -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { readStringDelim } from "./read_string_delim.ts"; import { StringReader } from "./string_reader.ts"; diff --git a/io/slice_long_to_bytes_test.ts b/io/slice_long_to_bytes_test.ts index ceb9e9c2579f..d0d2930dd781 100644 --- a/io/slice_long_to_bytes_test.ts +++ b/io/slice_long_to_bytes_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { readLong } from "./read_long.ts"; import { sliceLongToBytes } from "./slice_long_to_bytes.ts"; import { BufReader } from "./buf_reader.ts"; diff --git a/io/string_reader_test.ts b/io/string_reader_test.ts index 8d5c97041d5d..89118cd2282a 100644 --- a/io/string_reader_test.ts +++ b/io/string_reader_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { StringReader } from "./string_reader.ts"; Deno.test("ioStringReader", async function () { diff --git a/io/string_writer_test.ts b/io/string_writer_test.ts index 530c6b9101d9..0c8a748d3990 100644 --- a/io/string_writer_test.ts +++ b/io/string_writer_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { StringWriter } from "./string_writer.ts"; import { StringReader } from "./string_reader.ts"; import { copyN } from "./copy_n.ts"; diff --git a/json/_test_common.ts b/json/_test_common.ts index 0cc0802d4c51..9019a1b2d28a 100644 --- a/json/_test_common.ts +++ b/json/_test_common.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { readableStreamFromIterable } from "../streams/readable_stream_from_iterable.ts"; import type { ConcatenatedJsonParseStream } from "./concatenated_json_parse_stream.ts"; import type { JsonParseStream } from "./json_parse_stream.ts"; diff --git a/json/concatenated_json_parse_stream_test.ts b/json/concatenated_json_parse_stream_test.ts index 83cd3d1c7e29..903933bae758 100644 --- a/json/concatenated_json_parse_stream_test.ts +++ b/json/concatenated_json_parse_stream_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { ConcatenatedJsonParseStream } from "./concatenated_json_parse_stream.ts"; import { assertInvalidParse, assertValidParse } from "./_test_common.ts"; diff --git a/json/json_parse_stream_test.ts b/json/json_parse_stream_test.ts index 19120c6b1941..2835391b52fb 100644 --- a/json/json_parse_stream_test.ts +++ b/json/json_parse_stream_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { TextDelimiterStream } from "../streams/text_delimiter_stream.ts"; import { TextLineStream } from "../streams/text_line_stream.ts"; import { JsonParseStream } from "./json_parse_stream.ts"; diff --git a/json/json_stringify_stream_test.ts b/json/json_stringify_stream_test.ts index f96be385a8f7..7ebe9c0178b0 100644 --- a/json/json_stringify_stream_test.ts +++ b/json/json_stringify_stream_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { readableStreamFromIterable } from "../streams/readable_stream_from_iterable.ts"; import { JsonStringifyStream, diff --git a/jsonc/parse.ts b/jsonc/parse.ts index b4e63b548881..ef33a238fe6e 100644 --- a/jsonc/parse.ts +++ b/jsonc/parse.ts @@ -10,7 +10,7 @@ * @module */ -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import type { JsonValue } from "../json/common.ts"; export type { JsonValue } from "../json/common.ts"; diff --git a/jsonc/parse_test.ts b/jsonc/parse_test.ts index 31cd4618230b..f270f1333507 100644 --- a/jsonc/parse_test.ts +++ b/jsonc/parse_test.ts @@ -6,7 +6,7 @@ import { assertEquals, assertStrictEquals, assertThrows, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; // The test code for the jsonc module can also be found in the testcode directory. diff --git a/jsonc/testdata/JSONTestSuite/test.ts b/jsonc/testdata/JSONTestSuite/test.ts index 229179ffe282..41b86c65d7d3 100644 --- a/jsonc/testdata/JSONTestSuite/test.ts +++ b/jsonc/testdata/JSONTestSuite/test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import * as JSONC from "../../parse.ts"; -import { assertEquals } from "../../../testing/asserts.ts"; +import { assertEquals } from "../../../assert/mod.ts"; import { walk } from "../../../fs/mod.ts"; import { fromFileUrl } from "../../../path/mod.ts"; diff --git a/jsonc/testdata/node-jsonc-parser/test.ts b/jsonc/testdata/node-jsonc-parser/test.ts index bf5e3283b652..218ecc8954b4 100644 --- a/jsonc/testdata/node-jsonc-parser/test.ts +++ b/jsonc/testdata/node-jsonc-parser/test.ts @@ -7,7 +7,7 @@ *--------------------------------------------------------------------------------------------*/ import * as JSONC from "../../parse.ts"; -import { assertEquals, assertThrows } from "../../../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../../../assert/mod.ts"; function assertValidParse( text: string, expected: unknown, diff --git a/log/handlers_test.ts b/log/handlers_test.ts index 4a6b2b36cb85..2572fd42ada2 100644 --- a/log/handlers_test.ts +++ b/log/handlers_test.ts @@ -4,7 +4,7 @@ import { assertEquals, assertNotEquals, assertRejects, -} from "../testing/asserts.ts"; +} from "../assert/mod.ts"; import { getLevelByName, getLevelName, diff --git a/log/logger_test.ts b/log/logger_test.ts index 86b2889d8e71..ebe28bfa77ed 100644 --- a/log/logger_test.ts +++ b/log/logger_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertMatch } from "../testing/asserts.ts"; +import { assert, assertEquals, assertMatch } from "../assert/mod.ts"; import { Logger, LogRecord } from "./logger.ts"; import { LevelName, LogLevels } from "./levels.ts"; import { BaseHandler } from "./handlers.ts"; diff --git a/log/mod.ts b/log/mod.ts index 6cf9da6c9b81..1be9700cdc9c 100644 --- a/log/mod.ts +++ b/log/mod.ts @@ -259,7 +259,7 @@ import { RotatingFileHandler, WriterHandler, } from "./handlers.ts"; -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import type { LevelName } from "./levels.ts"; export { LogLevels } from "./levels.ts"; diff --git a/log/mod_test.ts b/log/mod_test.ts index 18d66257deb2..06ecc90862e6 100644 --- a/log/mod_test.ts +++ b/log/mod_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { critical, debug, diff --git a/log/test.ts b/log/test.ts index db4bca8d432f..93d9064f66cd 100644 --- a/log/test.ts +++ b/log/test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import * as log from "./mod.ts"; import { getLevelByName, diff --git a/media_types/_util_test.ts b/media_types/_util_test.ts index fb53fb42d8d3..dd9776f4f4f1 100644 --- a/media_types/_util_test.ts +++ b/media_types/_util_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { consumeMediaParam, consumeToken, consumeValue } from "./_util.ts"; Deno.test({ diff --git a/media_types/content_type_test.ts b/media_types/content_type_test.ts index 0c64e6d96bc6..bbdd5ed36e06 100644 --- a/media_types/content_type_test.ts +++ b/media_types/content_type_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { contentType } from "./content_type.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test({ name: "media_types - contentType()", diff --git a/media_types/extension_test.ts b/media_types/extension_test.ts index 334f14c309f7..31f2a4921e03 100644 --- a/media_types/extension_test.ts +++ b/media_types/extension_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { extension } from "./mod.ts"; Deno.test({ diff --git a/media_types/extensions_by_type_test.ts b/media_types/extensions_by_type_test.ts index 69e779893747..6a260bbbd2f3 100644 --- a/media_types/extensions_by_type_test.ts +++ b/media_types/extensions_by_type_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { extensionsByType } from "./mod.ts"; Deno.test({ diff --git a/media_types/format_media_type_test.ts b/media_types/format_media_type_test.ts index 9c33d4b1718c..bfa91d8b612f 100644 --- a/media_types/format_media_type_test.ts +++ b/media_types/format_media_type_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { formatMediaType } from "./mod.ts"; Deno.test({ diff --git a/media_types/get_charset_test.ts b/media_types/get_charset_test.ts index a0f2506f37c0..8fe0eff94896 100644 --- a/media_types/get_charset_test.ts +++ b/media_types/get_charset_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { getCharset } from "./mod.ts"; Deno.test({ diff --git a/media_types/parse_media_type.ts b/media_types/parse_media_type.ts index 89d4e14dd418..d1a74ba4788b 100644 --- a/media_types/parse_media_type.ts +++ b/media_types/parse_media_type.ts @@ -20,7 +20,7 @@ import { consumeMediaParam, decode2331Encoding } from "./_util.ts"; * @example * ```ts * import { parseMediaType } from "https://deno.land/std@$STD_VERSION/media_types/parse_media_type.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * * assertEquals( * parseMediaType("application/JSON"), diff --git a/media_types/parse_media_type_test.ts b/media_types/parse_media_type_test.ts index 8563a48df2e5..bc0b9dea4ac1 100644 --- a/media_types/parse_media_type_test.ts +++ b/media_types/parse_media_type_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parseMediaType } from "./mod.ts"; Deno.test({ diff --git a/media_types/type_by_extension_test.ts b/media_types/type_by_extension_test.ts index 59e6f26c1716..1adfdb687b83 100644 --- a/media_types/type_by_extension_test.ts +++ b/media_types/type_by_extension_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { typeByExtension } from "./mod.ts"; Deno.test({ diff --git a/path/basename_test.ts b/path/basename_test.ts index 60360ceafdc2..3a793a20a8c5 100644 --- a/path/basename_test.ts +++ b/path/basename_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "./mod.ts"; // Test suite from "GNU core utilities" diff --git a/path/common_test.ts b/path/common_test.ts index 004f07820d6c..00e8521a0001 100644 --- a/path/common_test.ts +++ b/path/common_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { common } from "./mod.ts"; Deno.test({ diff --git a/path/dirname_test.ts b/path/dirname_test.ts index 0f9e6674703b..9aed1de071cd 100644 --- a/path/dirname_test.ts +++ b/path/dirname_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "./mod.ts"; // Test suite from "GNU core utilities" diff --git a/path/extname_test.ts b/path/extname_test.ts index c9b207fd1a24..f14fc9f06f28 100644 --- a/path/extname_test.ts +++ b/path/extname_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "./mod.ts"; const slashRE = /\//g; diff --git a/path/from_file_url_test.ts b/path/from_file_url_test.ts index 7b91ad36cb93..94fe473879fd 100644 --- a/path/from_file_url_test.ts +++ b/path/from_file_url_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { posix, win32 } from "./mod.ts"; -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; Deno.test("[path] fromFileUrl", function () { assertEquals(posix.fromFileUrl(new URL("file:///home/foo")), "/home/foo"); diff --git a/path/glob_test.ts b/path/glob_test.ts index 2738781081f3..0e8600b7fb69 100644 --- a/path/glob_test.ts +++ b/path/glob_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { globToRegExp, GlobToRegExpOptions, diff --git a/path/isabsolute_test.ts b/path/isabsolute_test.ts index 363ddcae440d..440c72b162f7 100644 --- a/path/isabsolute_test.ts +++ b/path/isabsolute_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "./mod.ts"; Deno.test("isAbsolute", function () { diff --git a/path/join_test.ts b/path/join_test.ts index 61af483f28d4..1f82b1a094c8 100644 --- a/path/join_test.ts +++ b/path/join_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "./mod.ts"; const backslashRE = /\\/g; diff --git a/path/parse_format_test.ts b/path/parse_format_test.ts index 625c4f831433..89a5862084fa 100644 --- a/path/parse_format_test.ts +++ b/path/parse_format_test.ts @@ -3,7 +3,7 @@ // Ported from https://github.com/browserify/path-browserify/ import type { FormatInputPathObject, ParsedPath } from "./mod.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { posix, win32 } from "./mod.ts"; type FormatTestCase = [FormatInputPathObject, string]; diff --git a/path/relative_test.ts b/path/relative_test.ts index 29291571f3d9..87f4ac294acd 100644 --- a/path/relative_test.ts +++ b/path/relative_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "./mod.ts"; const relativeTests = { diff --git a/path/resolve_test.ts b/path/resolve_test.ts index 8f538bbeb008..1dff0fbbfd4c 100644 --- a/path/resolve_test.ts +++ b/path/resolve_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "./mod.ts"; const windowsTests = diff --git a/path/to_file_url_test.ts b/path/to_file_url_test.ts index 417f0a100c0e..db7c25f6df24 100644 --- a/path/to_file_url_test.ts +++ b/path/to_file_url_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { posix, win32 } from "./mod.ts"; -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; Deno.test("[path] toFileUrl", function () { assertEquals(posix.toFileUrl("/home/foo").href, "file:///home/foo"); diff --git a/path/win32.ts b/path/win32.ts index de4bd58954e7..8d98ccb43c06 100644 --- a/path/win32.ts +++ b/path/win32.ts @@ -23,7 +23,7 @@ import { stripSuffix, stripTrailingSeparators, } from "./_util.ts"; -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; export const sep = "\\"; export const delimiter = ";"; diff --git a/path/zero_length_strings_test.ts b/path/zero_length_strings_test.ts index 6409aca15f46..2974df74ff74 100644 --- a/path/zero_length_strings_test.ts +++ b/path/zero_length_strings_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import * as path from "./mod.ts"; const pwd = Deno.cwd(); diff --git a/permissions/test.ts b/permissions/test.ts index 18e29177e7a3..39f30571142f 100644 --- a/permissions/test.ts +++ b/permissions/test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { grant, grantOrThrow } from "./mod.ts"; -import { assert, assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assert, assertEquals, assertRejects } from "../assert/mod.ts"; Deno.test({ name: "grant basic", diff --git a/regexp/escape.ts b/regexp/escape.ts index f9bc1ccf7344..6b4ddb0f4c7d 100644 --- a/regexp/escape.ts +++ b/regexp/escape.ts @@ -66,7 +66,7 @@ const RX_REGEXP_ESCAPE = new RegExp( * @example * ```ts * import { escape } from "https://deno.land/std@$STD_VERSION/regexp/mod.ts"; - * import { assertEquals, assertMatch, assertNotMatch } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals, assertMatch, assertNotMatch } from "https://deno.land/std@$STD_VERSION/assert/mod.ts"; * * const re = new RegExp(`^${escape(".")}$`, "u"); * diff --git a/regexp/escape_test.ts b/regexp/escape_test.ts index db370eb38586..d062a2610e27 100644 --- a/regexp/escape_test.ts +++ b/regexp/escape_test.ts @@ -1,11 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { escape } from "./escape.ts"; -import { - assertEquals, - assertMatch, - assertNotMatch, -} from "../testing/asserts.ts"; +import { assertEquals, assertMatch, assertNotMatch } from "../assert/mod.ts"; const ALL_ASCII = "\x00\x01\x02\x03\x04\x05\x06\x07\b\t\n\v\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7F"; diff --git a/semver/cmp_test.ts b/semver/cmp_test.ts index 47fd5123883e..26c139a14a15 100644 --- a/semver/cmp_test.ts +++ b/semver/cmp_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { Operator } from "./types.ts"; import { cmp } from "./cmp.ts"; diff --git a/semver/comparator_intersects_test.ts b/semver/comparator_intersects_test.ts index fdc1ecdb20c1..647dcff1f6bc 100644 --- a/semver/comparator_intersects_test.ts +++ b/semver/comparator_intersects_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parseComparator } from "./parse_comparator.ts"; import { comparatorIntersects } from "./comparator_intersects.ts"; import { rangeIntersects } from "./range_intersects.ts"; diff --git a/semver/comparator_test.ts b/semver/comparator_test.ts index 4bdd37594ccf..00908cdb166c 100644 --- a/semver/comparator_test.ts +++ b/semver/comparator_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parseRange } from "./parse_range.ts"; import { parse } from "./parse.ts"; import { testRange } from "./test_range.ts"; diff --git a/semver/compare_build_test.ts b/semver/compare_build_test.ts index 64e4742d1cd5..281889e39114 100644 --- a/semver/compare_build_test.ts +++ b/semver/compare_build_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { compareBuild } from "./compare_build.ts"; diff --git a/semver/compare_test.ts b/semver/compare_test.ts index c3b11006fff9..a94340601d10 100644 --- a/semver/compare_test.ts +++ b/semver/compare_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { compare } from "./compare.ts"; diff --git a/semver/difference_test.ts b/semver/difference_test.ts index 07151b2c34d5..9f95872ff131 100644 --- a/semver/difference_test.ts +++ b/semver/difference_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { ReleaseType } from "./types.ts"; import { difference } from "./difference.ts"; diff --git a/semver/eq_test.ts b/semver/eq_test.ts index f0468481da8f..0514fbbbf3f4 100644 --- a/semver/eq_test.ts +++ b/semver/eq_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { eq } from "./eq.ts"; diff --git a/semver/format_test.ts b/semver/format_test.ts index 694cabff46e8..575b45050f22 100644 --- a/semver/format_test.ts +++ b/semver/format_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { format } from "./format.ts"; import { parse } from "./parse.ts"; import { INVALID, MAX, MIN } from "./constants.ts"; diff --git a/semver/gt_test.ts b/semver/gt_test.ts index b8a0ff8c44a0..2d34819550ce 100644 --- a/semver/gt_test.ts +++ b/semver/gt_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { gt } from "./gt.ts"; diff --git a/semver/gte_test.ts b/semver/gte_test.ts index 7b30202c4d06..2e322db1a063 100644 --- a/semver/gte_test.ts +++ b/semver/gte_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { gte } from "./gte.ts"; diff --git a/semver/gtr_test.ts b/semver/gtr_test.ts index 917f469c16f5..d54e17e1299d 100644 --- a/semver/gtr_test.ts +++ b/semver/gtr_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { gtr } from "./gtr.ts"; import { parse } from "./parse.ts"; import { parseRange } from "./parse_range.ts"; diff --git a/semver/increment_test.ts b/semver/increment_test.ts index 62a7d12bdfd1..7f2ebb310ddb 100644 --- a/semver/increment_test.ts +++ b/semver/increment_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import type { ReleaseType } from "./types.ts"; import { parse } from "./parse.ts"; import { increment } from "./increment.ts"; diff --git a/semver/is_semver_comparator_test.ts b/semver/is_semver_comparator_test.ts index 8cc4b2d7293f..a9bafe274708 100644 --- a/semver/is_semver_comparator_test.ts +++ b/semver/is_semver_comparator_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { INVALID, MIN } from "./constants.ts"; import { isSemVerComparator } from "./is_semver_comparator.ts"; diff --git a/semver/is_semver_range_test.ts b/semver/is_semver_range_test.ts index 08e423a35a39..e21847752e83 100644 --- a/semver/is_semver_range_test.ts +++ b/semver/is_semver_range_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { ALL } from "./constants.ts"; import { isSemVerRange } from "./is_semver_range.ts"; diff --git a/semver/is_semver_test.ts b/semver/is_semver_test.ts index e09a2cbf710e..c40c1fe1b954 100644 --- a/semver/is_semver_test.ts +++ b/semver/is_semver_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { MAX, MIN } from "./constants.ts"; import { isSemVer } from "./is_semver.ts"; diff --git a/semver/is_valid_operator_test.ts b/semver/is_valid_operator_test.ts index 425c67efcf19..6c3524ba2006 100644 --- a/semver/is_valid_operator_test.ts +++ b/semver/is_valid_operator_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { isValidOperator } from "./_shared.ts"; Deno.test({ diff --git a/semver/lt_test.ts b/semver/lt_test.ts index 34320b1c98aa..c9b05d856b20 100644 --- a/semver/lt_test.ts +++ b/semver/lt_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { lt } from "./lt.ts"; diff --git a/semver/ltr_test.ts b/semver/ltr_test.ts index bdf73548ffa1..460d9b5c00db 100644 --- a/semver/ltr_test.ts +++ b/semver/ltr_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { parseRange } from "./parse_range.ts"; import { ltr } from "./ltr.ts"; diff --git a/semver/max_satisfying_test.ts b/semver/max_satisfying_test.ts index 34c32568b83b..c3c1c3a0de31 100644 --- a/semver/max_satisfying_test.ts +++ b/semver/max_satisfying_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { parseRange } from "./parse_range.ts"; import { maxSatisfying } from "./max_satisfying.ts"; diff --git a/semver/min_satisfying_test.ts b/semver/min_satisfying_test.ts index 08fe872b90c2..d6b16a065222 100644 --- a/semver/min_satisfying_test.ts +++ b/semver/min_satisfying_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { parseRange } from "./parse_range.ts"; import { minSatisfying } from "./min_satisfying.ts"; diff --git a/semver/neq_test.ts b/semver/neq_test.ts index a8438d783d53..d5501295489a 100644 --- a/semver/neq_test.ts +++ b/semver/neq_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { neq } from "./neq.ts"; diff --git a/semver/outside_test.ts b/semver/outside_test.ts index 8a43ade5c9ba..ecd0bb51339d 100644 --- a/semver/outside_test.ts +++ b/semver/outside_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { outside } from "./outside.ts"; import { parse } from "./parse.ts"; import { parseRange } from "./parse_range.ts"; diff --git a/semver/parse_test.ts b/semver/parse_test.ts index 071f3434ba64..2419cfad2c6c 100644 --- a/semver/parse_test.ts +++ b/semver/parse_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { parse } from "./parse.ts"; Deno.test("major", async (t) => { diff --git a/semver/range_intersects_test.ts b/semver/range_intersects_test.ts index 4857f4c97abd..f903ca6ccba8 100644 --- a/semver/range_intersects_test.ts +++ b/semver/range_intersects_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parseRange } from "./parse_range.ts"; import { rangeIntersects } from "./range_intersects.ts"; diff --git a/semver/range_min_test.ts b/semver/range_min_test.ts index f86a84fcb514..510718260b30 100644 --- a/semver/range_min_test.ts +++ b/semver/range_min_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { format } from "./format.ts"; import { eq } from "./eq.ts"; import { parse } from "./parse.ts"; diff --git a/semver/range_test.ts b/semver/range_test.ts index c6957e84e527..b370d9921af8 100644 --- a/semver/range_test.ts +++ b/semver/range_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { rangeFormat } from "./range_format.ts"; import { parse } from "./parse.ts"; import { parseRange } from "./parse_range.ts"; diff --git a/semver/rcompare_test.ts b/semver/rcompare_test.ts index 78d2e9baa6cc..96c614c29fad 100644 --- a/semver/rcompare_test.ts +++ b/semver/rcompare_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { rcompare } from "./rcompare.ts"; diff --git a/semver/rsort_test.ts b/semver/rsort_test.ts index 10c53cc61e11..a4ea29fd08f9 100644 --- a/semver/rsort_test.ts +++ b/semver/rsort_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { rsort } from "./rsort.ts"; import { parse } from "./parse.ts"; diff --git a/semver/sort_test.ts b/semver/sort_test.ts index 8ff94eb7a0ea..8595062c8cab 100644 --- a/semver/sort_test.ts +++ b/semver/sort_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { sort } from "./sort.ts"; import { parse } from "./parse.ts"; diff --git a/semver/test_comparator_test.ts b/semver/test_comparator_test.ts index 591ce3cc40ee..7b025ea4e120 100644 --- a/semver/test_comparator_test.ts +++ b/semver/test_comparator_test.ts @@ -1,6 +1,6 @@ // Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { parse } from "./parse.ts"; import { parseComparator } from "./parse_comparator.ts"; import { testComparator } from "./test_comparator.ts"; diff --git a/signal/test.ts b/signal/test.ts index 5715612a08fb..2161838c5020 100644 --- a/signal/test.ts +++ b/signal/test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assert, assertEquals, assertThrows } from "../assert/mod.ts"; import { delay } from "../async/delay.ts"; import { signal } from "./mod.ts"; import { isWindows } from "../_util/os.ts"; diff --git a/streams/_test_common.ts b/streams/_test_common.ts index 9f95f4654a55..0324a2678e4c 100644 --- a/streams/_test_common.ts +++ b/streams/_test_common.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { readableStreamFromIterable } from "./readable_stream_from_iterable.ts"; // N controls how many iterations of certain checks are performed. diff --git a/streams/buffer.ts b/streams/buffer.ts index 74f4633a9966..b76377c8cbb3 100644 --- a/streams/buffer.ts +++ b/streams/buffer.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import { copy } from "../bytes/copy.ts"; const MAX_SIZE = 2 ** 32 - 2; diff --git a/streams/buffer_test.ts b/streams/buffer_test.ts index d7966e13c2be..b20ee757b124 100644 --- a/streams/buffer_test.ts +++ b/streams/buffer_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { Buffer } from "./buffer.ts"; Deno.test("[streams] Buffer Write & Read", async function () { diff --git a/streams/byte_slice_stream.ts b/streams/byte_slice_stream.ts index 545d870f033d..d94c79c4b81f 100644 --- a/streams/byte_slice_stream.ts +++ b/streams/byte_slice_stream.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // This module is browser compatible. -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; /** * A transform stream that only transforms from the zero-indexed `start` and `end` bytes (both inclusive). diff --git a/streams/byte_slice_stream_test.ts b/streams/byte_slice_stream_test.ts index c5ca50a9ecd7..0494de02f142 100644 --- a/streams/byte_slice_stream_test.ts +++ b/streams/byte_slice_stream_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { ByteSliceStream } from "./byte_slice_stream.ts"; Deno.test("[streams] ByteSliceStream", async function () { diff --git a/streams/early_zip_readable_streams_test.ts b/streams/early_zip_readable_streams_test.ts index da703c1b847f..5f29d7c5c3c7 100644 --- a/streams/early_zip_readable_streams_test.ts +++ b/streams/early_zip_readable_streams_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { earlyZipReadableStreams } from "./early_zip_readable_streams.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test("[streams] earlyZipReadableStreams short first", async () => { const textStream = new ReadableStream({ diff --git a/streams/iterate_reader_test.ts b/streams/iterate_reader_test.ts index c95b9f2a115e..7e38f6563f73 100644 --- a/streams/iterate_reader_test.ts +++ b/streams/iterate_reader_test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { iterateReader, iterateReaderSync } from "./iterate_reader.ts"; diff --git a/streams/limited_bytes_transform_stream_test.ts b/streams/limited_bytes_transform_stream_test.ts index 0e2dd5156c3e..21e12d32c8b1 100644 --- a/streams/limited_bytes_transform_stream_test.ts +++ b/streams/limited_bytes_transform_stream_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { LimitedBytesTransformStream } from "./limited_bytes_transform_stream.ts"; Deno.test("[streams] LimitedBytesTransformStream", async function () { diff --git a/streams/limited_transform_stream_test.ts b/streams/limited_transform_stream_test.ts index 4463e4694134..196f9bee5ec9 100644 --- a/streams/limited_transform_stream_test.ts +++ b/streams/limited_transform_stream_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { LimitedTransformStream } from "./limited_transform_stream.ts"; Deno.test("[streams] LimitedTransformStream", async function () { diff --git a/streams/merge_readable_streams_test.ts b/streams/merge_readable_streams_test.ts index fd403e63746a..4640d0b41742 100644 --- a/streams/merge_readable_streams_test.ts +++ b/streams/merge_readable_streams_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { mergeReadableStreams } from "./merge_readable_streams.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test("[streams] mergeReadableStreams", async () => { const textStream = new ReadableStream({ diff --git a/streams/read_all_test.ts b/streams/read_all_test.ts index f5683d7f7c6a..8c1f3951d8e1 100644 --- a/streams/read_all_test.ts +++ b/streams/read_all_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { Buffer } from "../io/buffer.ts"; import { readAll, readAllSync } from "./read_all.ts"; import { init } from "./_test_common.ts"; diff --git a/streams/readable_stream_from_iterable_test.ts b/streams/readable_stream_from_iterable_test.ts index f4557351eaac..7144c934cb16 100644 --- a/streams/readable_stream_from_iterable_test.ts +++ b/streams/readable_stream_from_iterable_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { readableStreamFromIterable } from "./readable_stream_from_iterable.ts"; Deno.test("[streams] readableStreamFromIterable() array", async function () { diff --git a/streams/readable_stream_from_reader_test.ts b/streams/readable_stream_from_reader_test.ts index a140e8079f69..8ddfa218cf59 100644 --- a/streams/readable_stream_from_reader_test.ts +++ b/streams/readable_stream_from_reader_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { readableStreamFromReader } from "./readable_stream_from_reader.ts"; import { Buffer } from "../io/buffer.ts"; import { concat } from "../bytes/concat.ts"; diff --git a/streams/reader_from_iterable_test.ts b/streams/reader_from_iterable_test.ts index aeae84e773b4..502354bafecd 100644 --- a/streams/reader_from_iterable_test.ts +++ b/streams/reader_from_iterable_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { readerFromIterable } from "./reader_from_iterable.ts"; Deno.test("[streams] readerFromIterable()", async function () { diff --git a/streams/reader_from_stream_reader_test.ts b/streams/reader_from_stream_reader_test.ts index e9f5e20ea944..325bae795a52 100644 --- a/streams/reader_from_stream_reader_test.ts +++ b/streams/reader_from_stream_reader_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { copy } from "./copy.ts"; import { readerFromStreamReader } from "./reader_from_stream_reader.ts"; import { Buffer } from "../io/buffer.ts"; diff --git a/streams/text_line_stream_test.ts b/streams/text_line_stream_test.ts index bbcaa456fece..ffa7f81cb3f0 100644 --- a/streams/text_line_stream_test.ts +++ b/streams/text_line_stream_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { TextLineStream } from "./text_line_stream.ts"; -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; Deno.test("[streams] TextLineStream", async () => { const textStream = new ReadableStream({ diff --git a/streams/to_transform_stream_test.ts b/streams/to_transform_stream_test.ts index 6cdc5b110a12..790d6fef340b 100644 --- a/streams/to_transform_stream_test.ts +++ b/streams/to_transform_stream_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects } from "../testing/asserts.ts"; +import { assertEquals, assertRejects } from "../assert/mod.ts"; import { toTransformStream } from "./to_transform_stream.ts"; import { readableStreamFromIterable } from "./readable_stream_from_iterable.ts"; diff --git a/streams/writable_stream_from_writer_test.ts b/streams/writable_stream_from_writer_test.ts index 1dbf527f0ec4..9405cc862207 100644 --- a/streams/writable_stream_from_writer_test.ts +++ b/streams/writable_stream_from_writer_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { writableStreamFromWriter } from "./writable_stream_from_writer.ts"; import type { Closer, Writer } from "../types.d.ts"; diff --git a/streams/write_all_test.ts b/streams/write_all_test.ts index bcf67dd80325..90d6258e47a1 100644 --- a/streams/write_all_test.ts +++ b/streams/write_all_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { writeAll, writeAllSync } from "./write_all.ts"; import { Buffer } from "../io/buffer.ts"; import { init } from "./_test_common.ts"; diff --git a/streams/writer_from_stream_writer_test.ts b/streams/writer_from_stream_writer_test.ts index 7a2bb8586f7c..c0241ec68b2d 100644 --- a/streams/writer_from_stream_writer_test.ts +++ b/streams/writer_from_stream_writer_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { writerFromStreamWriter } from "./writer_from_stream_writer.ts"; Deno.test("[streams] writerFromStreamWriter()", async function () { diff --git a/streams/zip_readable_streams_test.ts b/streams/zip_readable_streams_test.ts index 6b28d4225de2..26bee0029c2b 100644 --- a/streams/zip_readable_streams_test.ts +++ b/streams/zip_readable_streams_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { zipReadableStreams } from "./zip_readable_streams.ts"; Deno.test("[streams] zipReadableStreams", async () => { diff --git a/testing/asserts.ts b/testing/asserts.ts index 0e43f80ce6ab..85d495a99c74 100644 --- a/testing/asserts.ts +++ b/testing/asserts.ts @@ -1,6 +1,9 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -/** A library of assertion functions. +/** + * @deprecated (will be removed after 1.0.0) Import from `std/asserts` instead. + * + * A library of assertion functions. * If the assertion is false an `AssertionError` will be thrown which will * result in pretty-printed diff of failing assertion. * @@ -10,917 +13,321 @@ * @module */ -import { red, stripColor } from "../fmt/colors.ts"; -import { buildMessage, diff, diffstr } from "./_diff.ts"; -import { format } from "./_format.ts"; - -const CAN_NOT_DISPLAY = "[Cannot display]"; - -export class AssertionError extends Error { - override name = "AssertionError"; - constructor(message: string) { - super(message); - } -} - -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 { - // Have to render RegExp & Date for string comparison - // unless it's mistreated as object - if ( - a && - b && - ((a instanceof RegExp && b instanceof RegExp) || - (a instanceof URL && b instanceof URL)) - ) { - return String(a) === String(b); - } - if (a instanceof Date && b instanceof Date) { - const aTime = a.getTime(); - const bTime = b.getTime(); - // Check for NaN equality manually since NaN is not - // equal to itself. - if (Number.isNaN(aTime) && Number.isNaN(bTime)) { - return true; - } - return aTime === bTime; - } - if (typeof a === "number" && typeof b === "number") { - return Number.isNaN(a) && Number.isNaN(b) || a === b; - } - if (Object.is(a, b)) { - return true; - } - if (a && typeof a === "object" && b && typeof b === "object") { - if (a && b && !constructorsEqual(a, b)) { - return false; - } - if (a instanceof WeakMap || b instanceof WeakMap) { - if (!(a instanceof WeakMap && b instanceof WeakMap)) return false; - throw new TypeError("cannot compare WeakMap instances"); - } - if (a instanceof WeakSet || b instanceof WeakSet) { - if (!(a instanceof WeakSet && b instanceof WeakSet)) return false; - throw new TypeError("cannot compare WeakSet instances"); - } - if (seen.get(a) === b) { - return true; - } - if (Object.keys(a || {}).length !== Object.keys(b || {}).length) { - return false; - } - seen.set(a, b); - if (isKeyedCollection(a) && isKeyedCollection(b)) { - if (a.size !== b.size) { - return false; - } - - let unmatchedEntries = a.size; - - for (const [aKey, aValue] of a.entries()) { - for (const [bKey, bValue] of b.entries()) { - /* Given that Map keys can be references, we need - * to ensure that they are also deeply equal */ - if ( - (aKey === aValue && bKey === bValue && compare(aKey, bKey)) || - (compare(aKey, bKey) && compare(aValue, bValue)) - ) { - unmatchedEntries--; - break; - } - } - } - - return unmatchedEntries === 0; - } - const merged = { ...a, ...b }; - for ( - const key of [ - ...Object.getOwnPropertyNames(merged), - ...Object.getOwnPropertySymbols(merged), - ] - ) { - type Key = keyof typeof merged; - if (!compare(a && a[key as Key], b && b[key as Key])) { - return false; - } - if (((key in a) && (!(key in b))) || ((key in b) && (!(key in a)))) { - return false; - } - } - if (a instanceof WeakRef || b instanceof WeakRef) { - if (!(a instanceof WeakRef && b instanceof WeakRef)) return false; - return compare(a.deref(), b.deref()); - } - return true; - } - return false; - })(c, d); -} - -function constructorsEqual(a: object, b: object) { - return a.constructor === b.constructor || - a.constructor === Object && !b.constructor || - !a.constructor && b.constructor === Object; -} - -/** Make an assertion, error will be thrown if `expr` does not have truthy value. */ -export function assert(expr: unknown, msg = ""): asserts expr { - if (!expr) { - throw new AssertionError(msg); - } -} - -/** Make an assertion, error will be thrown if `expr` have truthy value. */ -type Falsy = false | 0 | 0n | "" | null | undefined; -export function assertFalse(expr: unknown, msg = ""): asserts expr is Falsy { - if (expr) { - throw new AssertionError(msg); - } -} - -/** - * Make an assertion that `actual` and `expected` are equal, deeply. If not - * deeply equal, then throw. - * - * Type parameter can be specified to ensure values under comparison have the same type. - * - * @example - * ```ts - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("example", function (): void { - * assertEquals("world", "world"); - * assertEquals({ hello: "world" }, { hello: "world" }); - * }); - * ``` - */ -export function assertEquals(actual: T, expected: T, msg?: string) { - if (equal(actual, expected)) { - return; - } - const msgSuffix = msg ? `: ${msg}` : "."; - let message = `Values are not equal${msgSuffix}`; - - const actualString = format(actual); - const expectedString = format(expected); - try { - const stringDiff = (typeof actual === "string") && - (typeof expected === "string"); - const diffResult = stringDiff - ? diffstr(actual as string, expected as string) - : diff(actualString.split("\n"), expectedString.split("\n")); - const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n"); - message = `${message}\n${diffMsg}`; - } catch { - message = `${message}\n${red(CAN_NOT_DISPLAY)} + \n\n`; - } - throw new AssertionError(message); -} - -/** - * Make an assertion that `actual` and `expected` are not equal, deeply. - * If not then throw. - * - * Type parameter can be specified to ensure values under comparison have the same type. - * - * @example - * ```ts - * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * assertNotEquals(1, 2) - * ``` - */ -export function assertNotEquals(actual: T, expected: T, msg?: string) { - if (!equal(actual, expected)) { - return; - } - let actualString: string; - let expectedString: string; - try { - actualString = String(actual); - } catch { - actualString = "[Cannot display]"; - } - try { - expectedString = String(expected); - } catch { - expectedString = "[Cannot display]"; - } - const msgSuffix = msg ? `: ${msg}` : "."; - throw new AssertionError( - `Expected actual: ${actualString} not to be: ${expectedString}${msgSuffix}`, - ); -} - -/** - * Make an assertion that `actual` and `expected` are strictly equal. If - * not then throw. - * - * @example - * ```ts - * import { assertStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("isStrictlyEqual", function (): void { - * const a = {}; - * const b = a; - * assertStrictEquals(a, b); - * }); - * - * // This test fails - * Deno.test("isNotStrictlyEqual", function (): void { - * const a = {}; - * const b = {}; - * assertStrictEquals(a, b); - * }); - * ``` - */ -export function assertStrictEquals( - actual: unknown, - expected: T, - msg?: string, -): asserts actual is T { - if (Object.is(actual, expected)) { - return; - } - - const msgSuffix = msg ? `: ${msg}` : "."; - let message: string; - - const actualString = format(actual); - const expectedString = format(expected); - - if (actualString === expectedString) { - const withOffset = actualString - .split("\n") - .map((l) => ` ${l}`) - .join("\n"); - message = - `Values have the same structure but are not reference-equal${msgSuffix}\n\n${ - red(withOffset) - }\n`; - } else { - try { - const stringDiff = (typeof actual === "string") && - (typeof expected === "string"); - const diffResult = stringDiff - ? diffstr(actual as string, expected as string) - : diff(actualString.split("\n"), expectedString.split("\n")); - const diffMsg = buildMessage(diffResult, { stringDiff }).join("\n"); - message = `Values are not strictly equal${msgSuffix}\n${diffMsg}`; - } catch { - message = `\n${red(CAN_NOT_DISPLAY)} + \n\n`; - } - } - - throw new AssertionError(message); -} - -/** - * Make an assertion that `actual` and `expected` are not strictly equal. - * If the values are strictly equal then throw. - * - * ```ts - * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * assertNotStrictEquals(1, 1) - * ``` - */ -export function assertNotStrictEquals( - actual: T, - expected: T, - msg?: string, -) { - if (!Object.is(actual, expected)) { - return; - } - - const msgSuffix = msg ? `: ${msg}` : "."; - throw new AssertionError( - `Expected "actual" to be strictly unequal to: ${ - format(actual) - }${msgSuffix}\n`, - ); -} - -/** - * Make an assertion that `actual` and `expected` are almost equal numbers through - * a given tolerance. It can be used to take into account IEEE-754 double-precision - * floating-point representation limitations. - * If the values are not almost equal then throw. - * - * @example - * ```ts - * import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * assertAlmostEquals(0.1, 0.2); - * - * // Using a custom tolerance value - * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); - * assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17)); - * ``` - */ -export function assertAlmostEquals( - actual: number, - expected: number, - tolerance = 1e-7, - msg?: string, -) { - if (Object.is(actual, expected)) { - return; - } - const delta = Math.abs(expected - actual); - if (delta <= tolerance) { - return; - } - - const msgSuffix = msg ? `: ${msg}` : "."; - const f = (n: number) => Number.isInteger(n) ? n : n.toExponential(); - throw new AssertionError( - `Expected actual: "${f(actual)}" to be close to "${f(expected)}": \ -delta "${f(delta)}" is greater than "${f(tolerance)}"${msgSuffix}`, - ); -} - -// deno-lint-ignore no-explicit-any -type AnyConstructor = new (...args: any[]) => any; -type GetConstructorType = T extends // deno-lint-ignore no-explicit-any -new (...args: any) => infer C ? C - : never; - -/** - * Make an assertion that `obj` is an instance of `type`. - * If not then throw. - */ -export function assertInstanceOf( - actual: unknown, - expectedType: T, - msg = "", -): asserts actual is GetConstructorType { - if (actual instanceof expectedType) return; - - const msgSuffix = msg ? `: ${msg}` : "."; - const expectedTypeStr = expectedType.name; - - let actualTypeStr = ""; - if (actual === null) { - actualTypeStr = "null"; - } else if (actual === undefined) { - actualTypeStr = "undefined"; - } else if (typeof actual === "object") { - actualTypeStr = actual.constructor?.name ?? "Object"; - } else { - actualTypeStr = typeof actual; - } - - if (expectedTypeStr == actualTypeStr) { - msg = - `Expected object to be an instance of "${expectedTypeStr}"${msgSuffix}`; - } else if (actualTypeStr == "function") { - msg = - `Expected object to be an instance of "${expectedTypeStr}" but was not an instanced object${msgSuffix}`; - } else { - msg = - `Expected object to be an instance of "${expectedTypeStr}" but was "${actualTypeStr}"${msgSuffix}`; - } - - throw new AssertionError(msg); -} - -/** - * Make an assertion that `obj` is not an instance of `type`. - * If so, then throw. - */ -export function assertNotInstanceOf( - actual: A, - // deno-lint-ignore no-explicit-any - unexpectedType: new (...args: any[]) => T, - msg?: string, -): asserts actual is Exclude { - const msgSuffix = msg ? `: ${msg}` : "."; - msg = - `Expected object to not be an instance of "${typeof unexpectedType}"${msgSuffix}`; - assertFalse(actual instanceof unexpectedType, msg); -} - -/** - * Make an assertion that actual is not null or undefined. - * If not then throw. - */ -export function assertExists( - actual: T, - msg?: string, -): asserts actual is NonNullable { - if (actual === undefined || actual === null) { - const msgSuffix = msg ? `: ${msg}` : "."; - msg = - `Expected actual: "${actual}" to not be null or undefined${msgSuffix}`; - throw new AssertionError(msg); - } -} - -/** - * Make an assertion that actual includes expected. If not - * then throw. - */ -export function assertStringIncludes( - actual: string, - expected: string, - msg?: string, -) { - if (!actual.includes(expected)) { - const msgSuffix = msg ? `: ${msg}` : "."; - msg = `Expected actual: "${actual}" to contain: "${expected}"${msgSuffix}`; - throw new AssertionError(msg); - } -} - -/** - * Make an assertion that `actual` includes the `expected` values. - * If not then an error will be thrown. - * - * Type parameter can be specified to ensure values under comparison have the same type. - * - * @example - * ```ts - * import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * assertArrayIncludes([1, 2], [2]) - * ``` - */ -export function assertArrayIncludes( - actual: ArrayLike, - expected: ArrayLike, - msg?: string, -) { - const missing: unknown[] = []; - for (let i = 0; i < expected.length; i++) { - let found = false; - for (let j = 0; j < actual.length; j++) { - if (equal(expected[i], actual[j])) { - found = true; - break; - } - } - if (!found) { - missing.push(expected[i]); - } - } - if (missing.length === 0) { - return; - } - - const msgSuffix = msg ? `: ${msg}` : "."; - msg = `Expected actual: "${format(actual)}" to include: "${ - format(expected) - }"${msgSuffix}\nmissing: ${format(missing)}`; - throw new AssertionError(msg); -} - -/** - * Make an assertion that `actual` match RegExp `expected`. If not - * then throw. - */ -export function assertMatch( - actual: string, - expected: RegExp, - msg?: string, -) { - if (!expected.test(actual)) { - const msgSuffix = msg ? `: ${msg}` : "."; - msg = `Expected actual: "${actual}" to match: "${expected}"${msgSuffix}`; - throw new AssertionError(msg); - } -} - -/** - * Make an assertion that `actual` not match RegExp `expected`. If match - * then throw. - */ -export function assertNotMatch( - actual: string, - expected: RegExp, - msg?: string, -) { - if (expected.test(actual)) { - const msgSuffix = msg ? `: ${msg}` : "."; - msg = - `Expected actual: "${actual}" to not match: "${expected}"${msgSuffix}`; - throw new AssertionError(msg); - } -} - -/** - * Make an assertion that `actual` object is a subset of `expected` object, deeply. - * If not, then throw. - */ -export function assertObjectMatch( - // deno-lint-ignore no-explicit-any - actual: Record, - expected: Record, - msg?: string, -) { - type loose = Record; - - function filter(a: loose, b: loose) { - const seen = new WeakMap(); - return fn(a, b); - - function fn(a: loose, b: loose): loose { - // Prevent infinite loop with circular references with same filter - if ((seen.has(a)) && (seen.get(a) === b)) { - return a; - } - try { - seen.set(a, b); - } catch (err) { - if (err instanceof TypeError) { - throw new TypeError( - `Cannot assertObjectMatch ${ - a === null ? null : `type ${typeof a}` - }`, - ); - } else throw err; - } - // Filter keys and symbols which are present in both actual and expected - const filtered = {} as loose; - const entries = [ - ...Object.getOwnPropertyNames(a), - ...Object.getOwnPropertySymbols(a), - ] - .filter((key) => key in b) - .map((key) => [key, a[key as string]]) as Array<[string, unknown]>; - for (const [key, value] of entries) { - // On array references, build a filtered array and filter nested objects inside - if (Array.isArray(value)) { - const subset = (b as loose)[key]; - if (Array.isArray(subset)) { - filtered[key] = fn({ ...value }, { ...subset }); - continue; - } - } // On regexp references, keep value as it to avoid loosing pattern and flags - else if (value instanceof RegExp) { - filtered[key] = value; - continue; - } // On nested objects references, build a filtered object recursively - else if (typeof value === "object" && value !== null) { - const subset = (b as loose)[key]; - if ((typeof subset === "object") && (subset)) { - // When both operands are maps, build a filtered map with common keys and filter nested objects inside - if ((value instanceof Map) && (subset instanceof Map)) { - filtered[key] = new Map( - [...value].filter(([k]) => subset.has(k)).map(( - [k, v], - ) => [k, typeof v === "object" ? fn(v, subset.get(k)) : v]), - ); - continue; - } - // When both operands are set, build a filtered set with common values - if ((value instanceof Set) && (subset instanceof Set)) { - filtered[key] = new Set([...value].filter((v) => subset.has(v))); - continue; - } - filtered[key] = fn(value as loose, subset as loose); - continue; - } - } - filtered[key] = value; - } - return filtered; - } - } - return assertEquals( - // get the intersection of "actual" and "expected" - // side effect: all the instances' constructor field is "Object" now. - filter(actual, expected), - // set (nested) instances' constructor field to be "Object" without changing expected value. - // see https://github.com/denoland/deno_std/pull/1419 - filter(expected, expected), - msg, - ); -} - -/** - * Forcefully throws a failed assertion - */ -export function fail(msg?: string): never { - const msgSuffix = msg ? `: ${msg}` : "."; - assert(false, `Failed assertion${msgSuffix}`); -} - -/** - * Make an assertion that `error` is an `Error`. - * If not then an error will be thrown. - * An error class and a string that should be included in the - * error message can also be asserted. - */ -export function assertIsError( - error: unknown, - // deno-lint-ignore no-explicit-any - ErrorClass?: new (...args: any[]) => E, - msgIncludes?: string, - msg?: string, -): asserts error is E { - const msgSuffix = msg ? `: ${msg}` : "."; - if (error instanceof Error === false) { - throw new AssertionError( - `Expected "error" to be an Error object${msgSuffix}}`, - ); - } - if (ErrorClass && !(error instanceof ErrorClass)) { - msg = `Expected error to be instance of "${ErrorClass.name}", but was "${ - typeof error === "object" ? error?.constructor?.name : "[not an object]" - }"${msgSuffix}`; - throw new AssertionError(msg); - } - if ( - msgIncludes && (!(error instanceof Error) || - !stripColor(error.message).includes(stripColor(msgIncludes))) - ) { - msg = `Expected error message to include "${msgIncludes}", but got "${ - error instanceof Error ? error.message : "[not an Error]" - }"${msgSuffix}`; - throw new AssertionError(msg); - } -} - -/** - * Executes a function, expecting it to throw. If it does not, then it - * throws. - * - * @example - * ```ts - * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("doesThrow", function (): void { - * assertThrows((): void => { - * throw new TypeError("hello world!"); - * }); - * }); - * - * // This test will not pass. - * Deno.test("fails", function (): void { - * assertThrows((): void => { - * console.log("Hello world"); - * }); - * }); - * ``` - */ -export function assertThrows( - fn: () => unknown, - msg?: string, -): unknown; -/** - * Executes a function, expecting it to throw. If it does not, then it - * throws. An error class and a string that should be included in the - * error message can also be asserted. - * - * @example - * - * ```ts - * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("doesThrow", function (): void { - * assertThrows((): void => { - * throw new TypeError("hello world!"); - * }, TypeError); - * assertThrows( - * (): void => { - * throw new TypeError("hello world!"); - * }, - * TypeError, - * "hello", - * ); - * }); - * - * // This test will not pass. - * Deno.test("fails", function (): void { - * assertThrows((): void => { - * console.log("Hello world"); - * }); - * }); - * ``` - */ -export function assertThrows( - fn: () => unknown, - // deno-lint-ignore no-explicit-any - ErrorClass: new (...args: any[]) => E, - msgIncludes?: string, - msg?: string, -): E; -export function assertThrows( - fn: () => unknown, - errorClassOrMsg?: - // deno-lint-ignore no-explicit-any - | (new (...args: any[]) => E) - | string, - msgIncludesOrMsg?: string, - msg?: string, -): E | Error | unknown { - // deno-lint-ignore no-explicit-any - let ErrorClass: (new (...args: any[]) => E) | undefined = undefined; - let msgIncludes: string | undefined = undefined; - let err; - - if (typeof errorClassOrMsg !== "string") { - if ( - errorClassOrMsg === undefined || - errorClassOrMsg.prototype instanceof Error || - errorClassOrMsg.prototype === Error.prototype - ) { - // deno-lint-ignore no-explicit-any - ErrorClass = errorClassOrMsg as new (...args: any[]) => E; - msgIncludes = msgIncludesOrMsg; - } else { - msg = msgIncludesOrMsg; - } - } else { - msg = errorClassOrMsg; - } - let doesThrow = false; - const msgSuffix = msg ? `: ${msg}` : "."; - try { - fn(); - } catch (error) { - if (ErrorClass) { - if (error instanceof Error === false) { - throw new AssertionError(`A non-Error object was thrown${msgSuffix}`); - } - assertIsError( - error, - ErrorClass, - msgIncludes, - msg, - ); - } - err = error; - doesThrow = true; - } - if (!doesThrow) { - msg = `Expected function to throw${msgSuffix}`; - throw new AssertionError(msg); - } - return err; -} - -/** - * Executes a function which returns a promise, expecting it to reject. - * - * @example - * ```ts - * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("doesThrow", async function () { - * await assertRejects( - * async () => { - * throw new TypeError("hello world!"); - * }, - * ); - * await assertRejects( - * async () => { - * return Promise.reject(new Error()); - * }, - * ); - * }); - * - * // This test will not pass. - * Deno.test("fails", async function () { - * await assertRejects( - * async () => { - * console.log("Hello world"); - * }, - * ); - * }); - * ``` - */ -export function assertRejects( - fn: () => PromiseLike, - msg?: string, -): Promise; -/** - * Executes a function which returns a promise, expecting it to reject. - * If it does not, then it throws. An error class and a string that should be - * included in the error message can also be asserted. - * - * @example - * ```ts - * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; - * - * Deno.test("doesThrow", async function () { - * await assertRejects(async () => { - * throw new TypeError("hello world!"); - * }, TypeError); - * await assertRejects( - * async () => { - * throw new TypeError("hello world!"); - * }, - * TypeError, - * "hello", - * ); - * }); - * - * // This test will not pass. - * Deno.test("fails", async function () { - * await assertRejects( - * async () => { - * console.log("Hello world"); - * }, - * ); - * }); - * ``` - */ -export function assertRejects( - fn: () => PromiseLike, - // deno-lint-ignore no-explicit-any - ErrorClass: new (...args: any[]) => E, - msgIncludes?: string, - msg?: string, -): Promise; -export async function assertRejects( - fn: () => PromiseLike, - errorClassOrMsg?: - // deno-lint-ignore no-explicit-any - | (new (...args: any[]) => E) - | string, - msgIncludesOrMsg?: string, - msg?: string, -): Promise { - // deno-lint-ignore no-explicit-any - let ErrorClass: (new (...args: any[]) => E) | undefined = undefined; - let msgIncludes: string | undefined = undefined; - let err; - - if (typeof errorClassOrMsg !== "string") { - if ( - errorClassOrMsg === undefined || - errorClassOrMsg.prototype instanceof Error || - errorClassOrMsg.prototype === Error.prototype - ) { - // deno-lint-ignore no-explicit-any - ErrorClass = errorClassOrMsg as new (...args: any[]) => E; - msgIncludes = msgIncludesOrMsg; - } - } else { - msg = errorClassOrMsg; - } - let doesThrow = false; - let isPromiseReturned = false; - const msgSuffix = msg ? `: ${msg}` : "."; - try { - const possiblePromise = fn(); - if ( - possiblePromise && - typeof possiblePromise === "object" && - typeof possiblePromise.then === "function" - ) { - isPromiseReturned = true; - await possiblePromise; - } - } catch (error) { - if (!isPromiseReturned) { - throw new AssertionError( - `Function throws when expected to reject${msgSuffix}`, - ); - } - if (ErrorClass) { - if (error instanceof Error === false) { - throw new AssertionError(`A non-Error object was rejected${msgSuffix}`); - } - assertIsError( - error, - ErrorClass, - msgIncludes, - msg, - ); - } - err = error; - doesThrow = true; - } - if (!doesThrow) { - throw new AssertionError( - `Expected function to reject${msgSuffix}`, - ); - } - return err; -} - -/** Use this to stub out methods that will throw when invoked. */ -export function unimplemented(msg?: string): never { - const msgSuffix = msg ? `: ${msg}` : "."; - throw new AssertionError(`Unimplemented${msgSuffix}`); -} - -/** Use this to assert unreachable code. */ -export function unreachable(): never { - throw new AssertionError("unreachable"); -} +export { + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert.ts` instead. + * + * Make an assertion, error will be thrown if `expr` does not have truthy value. + */ + assert, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_almost_equals.ts` instead. + * + * Make an assertion that `actual` and `expected` are almost equal numbers through + * a given tolerance. It can be used to take into account IEEE-754 double-precision + * floating-point representation limitations. + * If the values are not almost equal then throw. + * + * @example + * ```ts + * import { assertAlmostEquals, assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertAlmostEquals(0.1, 0.2); + * + * // Using a custom tolerance value + * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); + * assertThrows(() => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17)); + * ``` + */ + assertAlmostEquals, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_array_includes.ts` instead. + * + * Make an assertion that `actual` includes the `expected` values. + * If not then an error will be thrown. + * + * Type parameter can be specified to ensure values under comparison have the same type. + * + * @example + * ```ts + * import { assertArrayIncludes } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertArrayIncludes([1, 2], [2]) + * ``` + */ + assertArrayIncludes, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_equals.ts` instead. + * + * Make an assertion that `actual` and `expected` are equal, deeply. If not + * deeply equal, then throw. + * + * Type parameter can be specified to ensure values under comparison have the same type. + * + * @example + * ```ts + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * Deno.test("example", function (): void { + * assertEquals("world", "world"); + * assertEquals({ hello: "world" }, { hello: "world" }); + * }); + * ``` + */ + assertEquals, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_exists.ts` instead. + * + * Make an assertion that actual is not null or undefined. + * If not then throw. + */ + assertExists, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_false.ts` instead. + * + * Make an assertion, error will be thrown if `expr` have truthy value. + */ + assertFalse, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_instance_of.ts` instead. + * + * Make an assertion that `obj` is an instance of `type`. + * If not then throw. + */ + assertInstanceOf, + /** @deprecated (will be removed after 1.0.0) Import from `std/assert/assertion_error.ts` instead. */ + AssertionError, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_is_error.ts` instead. + * + * Make an assertion that `error` is an `Error`. + * If not then an error will be thrown. + * An error class and a string that should be included in the + * error message can also be asserted. + */ + assertIsError, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_match.ts` instead. + * + * Make an assertion that `actual` match RegExp `expected`. If not + * then throw. + */ + assertMatch, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_not_equals.ts` instead. + * + * Make an assertion that `actual` and `expected` are not equal, deeply. + * If not then throw. + * + * Type parameter can be specified to ensure values under comparison have the same type. + * + * @example + * ```ts + * import { assertNotEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertNotEquals(1, 2) + * ``` + */ + assertNotEquals, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_not_instance_of.ts` instead. + * + * Make an assertion that `obj` is not an instance of `type`. + * If so, then throw. + */ + assertNotInstanceOf, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_not_match.ts` instead. + * + * Make an assertion that `actual` object is a subset of `expected` object, deeply. + * If not, then throw. + */ + assertNotMatch, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_not_strict_equals.ts` instead. + * + * Make an assertion that `actual` and `expected` are not strictly equal. + * If the values are strictly equal then throw. + * + * ```ts + * import { assertNotStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * assertNotStrictEquals(1, 1) + * ``` + */ + assertNotStrictEquals, + /** + * Make an assertion that `actual` object is a subset of `expected` object, deeply. + * If not, then throw. + */ + assertObjectMatch, + /** + * Executes a function which returns a promise, expecting it to reject. + * If it does not, then it throws. An error class and a string that should be + * included in the error message can also be asserted. + * + * @example + * ```ts + * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * Deno.test("doesThrow", async function () { + * await assertRejects(async () => { + * throw new TypeError("hello world!"); + * }, TypeError); + * await assertRejects( + * async () => { + * throw new TypeError("hello world!"); + * }, + * TypeError, + * "hello", + * ); + * }); + * + * // This test will not pass. + * Deno.test("fails", async function () { + * await assertRejects( + * async () => { + * console.log("Hello world"); + * }, + * ); + * }); + * ``` + * + * * @example + * ```ts + * import { assertRejects } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * Deno.test("doesThrow", async function () { + * await assertRejects( + * async () => { + * throw new TypeError("hello world!"); + * }, + * ); + * await assertRejects( + * async () => { + * return Promise.reject(new Error()); + * }, + * ); + * }); + * + * // This test will not pass. + * Deno.test("fails", async function () { + * await assertRejects( + * async () => { + * console.log("Hello world"); + * }, + * ); + * }); + * ``` + */ + assertRejects, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_strict_equals.ts` instead. + * + * Make an assertion that `actual` and `expected` are strictly equal. If + * not then throw. + * + * @example + * ```ts + * import { assertStrictEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * Deno.test("isStrictlyEqual", function (): void { + * const a = {}; + * const b = a; + * assertStrictEquals(a, b); + * }); + * + * // This test fails + * Deno.test("isNotStrictlyEqual", function (): void { + * const a = {}; + * const b = {}; + * assertStrictEquals(a, b); + * }); + * ``` + */ + assertStrictEquals, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_string_includes.ts` instead. + * + * Make an assertion that actual includes expected. If not + * then throw. + */ + assertStringIncludes, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/assert_throws.ts` instead. + * + * Executes a function, expecting it to throw. If it does not, then it + * throws. An error class and a string that should be included in the + * error message can also be asserted. + * + * @example + * ```ts + * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * Deno.test("doesThrow", function (): void { + * assertThrows((): void => { + * throw new TypeError("hello world!"); + * }, TypeError); + * assertThrows( + * (): void => { + * throw new TypeError("hello world!"); + * }, + * TypeError, + * "hello", + * ); + * }); + * + * // This test will not pass. + * Deno.test("fails", function (): void { + * assertThrows((): void => { + * console.log("Hello world"); + * }); + * }); + * ``` + * + * @example + * ```ts + * import { assertThrows } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * + * Deno.test("doesThrow", function (): void { + * assertThrows((): void => { + * throw new TypeError("hello world!"); + * }); + * }); + * + * // This test will not pass. + * Deno.test("fails", function (): void { + * assertThrows((): void => { + * console.log("Hello world"); + * }); + * }); + * ``` + */ + assertThrows, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/equal.ts` instead. + * + * Deep equality comparison used in assertions + * @param c actual value + * @param d expected value + */ + equal, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/fail.ts` instead. + * + * Forcefully throws a failed assertion + */ + fail, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/unimplemented.ts` instead. + * + * Use this to stub out methods that will throw when invoked. + */ + unimplemented, + /** + * @deprecated (will be removed after 1.0.0) Import from `std/assert/unreachable.ts` instead. + * + * Use this to assert unreachable code. + */ + unreachable, +} from "../assert/mod.ts"; diff --git a/testing/asserts_test.ts b/testing/asserts_test.ts deleted file mode 100644 index 53949dabbe41..000000000000 --- a/testing/asserts_test.ts +++ /dev/null @@ -1,1593 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { - assert, - assertAlmostEquals, - assertArrayIncludes, - assertEquals, - assertExists, - assertFalse, - assertInstanceOf, - AssertionError, - assertIsError, - assertMatch, - assertNotEquals, - assertNotInstanceOf, - assertNotMatch, - assertNotStrictEquals, - assertObjectMatch, - assertRejects, - assertStrictEquals, - assertStringIncludes, - assertThrows, - equal, - fail, - unimplemented, - unreachable, -} from "./asserts.ts"; -import { bold, gray, green, red, stripColor, yellow } from "../fmt/colors.ts"; - -Deno.test("EqualDifferentZero", () => { - assert(equal(0, -0)); - assert(equal(0, +0)); - assert(equal(+0, -0)); - assert(equal([0], [-0])); - assert(equal(["hello", 12.21, 0], ["hello", 12.21, -0])); - assert(equal(["hello", 12.21, 0], ["hello", 12.21, +0])); - assert(equal(["hello", 12.21, -0], ["hello", 12.21, +0])); - assert(equal({ msg: "hello", case: 0 }, { msg: "hello", case: -0 })); - assert(equal({ msg: "hello", array: [0] }, { msg: "hello", array: [-0] })); -}); - -Deno.test("Equal", function () { - assert(equal("world", "world")); - assert(!equal("hello", "world")); - assertFalse(equal("hello", "world")); - assert(equal(5, 5)); - assert(!equal(5, 6)); - assertFalse(equal(5, 6)); - assert(equal(NaN, NaN)); - assert(equal({ hello: "world" }, { hello: "world" })); - assert(!equal({ world: "hello" }, { hello: "world" })); - assertFalse(equal({ world: "hello" }, { hello: "world" })); - assert( - equal( - { hello: "world", hi: { there: "everyone" } }, - { hello: "world", hi: { there: "everyone" } }, - ), - ); - assert( - !equal( - { hello: "world", hi: { there: "everyone" } }, - { hello: "world", hi: { there: "everyone else" } }, - ), - ); - assertFalse( - equal( - { hello: "world", hi: { there: "everyone" } }, - { hello: "world", hi: { there: "everyone else" } }, - ), - ); - assert(equal({ [Symbol.for("foo")]: "bar" }, { [Symbol.for("foo")]: "bar" })); - assert(!equal({ [Symbol("foo")]: "bar" }, { [Symbol("foo")]: "bar" })); - assertFalse(equal({ [Symbol("foo")]: "bar" }, { [Symbol("foo")]: "bar" })); - - assert(equal(/deno/, /deno/)); - assert(!equal(/deno/, /node/)); - assertFalse(equal(/deno/, /node/)); - assert(equal(new Date(2019, 0, 3), new Date(2019, 0, 3))); - assert(!equal(new Date(2019, 0, 3), new Date(2019, 1, 3))); - assertFalse(equal(new Date(2019, 0, 3), new Date(2019, 1, 3))); - assert( - !equal( - new Date(2019, 0, 3, 4, 20, 1, 10), - new Date(2019, 0, 3, 4, 20, 1, 20), - ), - ); - assertFalse( - equal( - new Date(2019, 0, 3, 4, 20, 1, 10), - new Date(2019, 0, 3, 4, 20, 1, 20), - ), - ); - assert(equal(new Date("Invalid"), new Date("Invalid"))); - assert(!equal(new Date("Invalid"), new Date(2019, 0, 3))); - assertFalse(equal(new Date("Invalid"), new Date(2019, 0, 3))); - assert(!equal(new Date("Invalid"), new Date(2019, 0, 3, 4, 20, 1, 10))); - assertFalse(equal(new Date("Invalid"), new Date(2019, 0, 3, 4, 20, 1, 10))); - assert(equal(new Set([1]), new Set([1]))); - assert(!equal(new Set([1]), new Set([2]))); - assertFalse(equal(new Set([1]), new Set([2]))); - assert(equal(new Set([1, 2, 3]), new Set([3, 2, 1]))); - assert(equal(new Set([1, new Set([2, 3])]), new Set([new Set([3, 2]), 1]))); - assert(!equal(new Set([1, 2]), new Set([3, 2, 1]))); - assertFalse(equal(new Set([1, 2]), new Set([3, 2, 1]))); - assert(!equal(new Set([1, 2, 3]), new Set([4, 5, 6]))); - assertFalse(equal(new Set([1, 2, 3]), new Set([4, 5, 6]))); - assert(equal(new Set("denosaurus"), new Set("denosaurussss"))); - assert(equal(new Map(), new Map())); - assert( - equal( - new Map([ - ["foo", "bar"], - ["baz", "baz"], - ]), - new Map([ - ["foo", "bar"], - ["baz", "baz"], - ]), - ), - ); - assert( - equal( - new Map([["foo", new Map([["bar", "baz"]])]]), - new Map([["foo", new Map([["bar", "baz"]])]]), - ), - ); - assert( - equal( - new Map([["foo", { bar: "baz" }]]), - new Map([["foo", { bar: "baz" }]]), - ), - ); - assert( - equal( - new Map([ - ["foo", "bar"], - ["baz", "qux"], - ]), - new Map([ - ["baz", "qux"], - ["foo", "bar"], - ]), - ), - ); - assert(equal(new Map([["foo", ["bar"]]]), new Map([["foo", ["bar"]]]))); - assert(!equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]]))); - assertFalse(equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]]))); - assertFalse(equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]]))); - assert( - !equal( - new Map([["foo", "bar"]]), - new Map([ - ["foo", "bar"], - ["bar", "baz"], - ]), - ), - ); - assertFalse( - equal( - new Map([["foo", "bar"]]), - new Map([ - ["foo", "bar"], - ["bar", "baz"], - ]), - ), - ); - assert( - !equal( - new Map([["foo", new Map([["bar", "baz"]])]]), - new Map([["foo", new Map([["bar", "qux"]])]]), - ), - ); - assert(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, true]]))); - assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, false]]))); - assertFalse(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, false]]))); - assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 2 }, true]]))); - assertFalse(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 2 }, true]]))); - assert(equal([1, 2, 3], [1, 2, 3])); - assert(equal([1, [2, 3]], [1, [2, 3]])); - assert(!equal([1, 2, 3, 4], [1, 2, 3])); - assertFalse(equal([1, 2, 3, 4], [1, 2, 3])); - assert(!equal([1, 2, 3, 4], [1, 2, 3])); - assertFalse(equal([1, 2, 3, 4], [1, 2, 3])); - assert(!equal([1, 2, 3, 4], [1, 4, 2, 3])); - assertFalse(equal([1, 2, 3, 4], [1, 4, 2, 3])); - assert(equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([1, 2, 3, 4]))); - assert(!equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([2, 1, 4, 3]))); - assertFalse( - equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([2, 1, 4, 3])), - ); - assert( - equal(new URL("https://example.test"), new URL("https://example.test")), - ); - assert( - !equal( - new URL("https://example.test"), - new URL("https://example.test/with-path"), - ), - ); - assertFalse( - equal( - new URL("https://example.test"), - new URL("https://example.test/with-path"), - ), - ); - assert( - !equal({ a: undefined, b: undefined }, { a: undefined, c: undefined }), - ); - assertFalse( - equal({ a: undefined, b: undefined }, { a: undefined, c: undefined }), - ); - assertFalse(equal({ a: undefined, b: undefined }, { a: undefined })); - assertThrows(() => equal(new WeakMap(), new WeakMap())); - assertThrows(() => equal(new WeakSet(), new WeakSet())); - assert(!equal(new WeakMap(), new WeakSet())); - assertFalse(equal(new WeakMap(), new WeakSet())); - assert( - equal(new WeakRef({ hello: "world" }), new WeakRef({ hello: "world" })), - ); - assert( - !equal(new WeakRef({ world: "hello" }), new WeakRef({ hello: "world" })), - ); - assertFalse( - equal(new WeakRef({ world: "hello" }), new WeakRef({ hello: "world" })), - ); - assert(!equal({ hello: "world" }, new WeakRef({ hello: "world" }))); - assertFalse(equal({ hello: "world" }, new WeakRef({ hello: "world" }))); - assert( - !equal( - new WeakRef({ hello: "world" }), - new (class extends WeakRef {})({ hello: "world" }), - ), - ); - assertFalse( - equal( - new WeakRef({ hello: "world" }), - new (class extends WeakRef {})({ hello: "world" }), - ), - ); - assert( - !equal( - new WeakRef({ hello: "world" }), - new (class extends WeakRef { - foo = "bar"; - })({ hello: "world" }), - ), - ); - assertFalse( - equal( - new WeakRef({ hello: "world" }), - new (class extends WeakRef { - foo = "bar"; - })({ hello: "world" }), - ), - ); - - assert( - !equal( - new (class A { - #hello = "world"; - })(), - new (class B { - #hello = "world"; - })(), - ), - ); - - assertFalse( - equal( - new (class A { - #hello = "world"; - })(), - new (class B { - #hello = "world"; - })(), - ), - ); -}); - -Deno.test("EqualCircular", () => { - const objA: { prop?: unknown } = {}; - objA.prop = objA; - const objB: { prop?: unknown } = {}; - objB.prop = objB; - assert(equal(objA, objB)); - - const mapA = new Map(); - mapA.set("prop", mapA); - const mapB = new Map(); - mapB.set("prop", mapB); - assert(equal(mapA, mapB)); -}); - -Deno.test("NotEquals", function () { - const a = { foo: "bar" }; - const b = { bar: "foo" }; - assertNotEquals(a, b); - assertNotEquals("Denosaurus", "Tyrannosaurus"); - assertNotEquals( - new Date(2019, 0, 3, 4, 20, 1, 10), - new Date(2019, 0, 3, 4, 20, 1, 20), - ); - assertNotEquals(new Date("invalid"), new Date(2019, 0, 3, 4, 20, 1, 20)); - let didThrow; - try { - assertNotEquals("Raptor", "Raptor"); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); -}); - -Deno.test("AssertExists", function () { - assertExists("Denosaurus"); - assertExists(false); - assertExists(0); - assertExists(""); - assertExists(-0); - assertExists(0); - assertExists(NaN); - - const value = new URLSearchParams({ value: "test" }).get("value"); - assertExists(value); - assertEquals(value.length, 4); - - let didThrow; - try { - assertExists(undefined); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - didThrow = false; - try { - assertExists(null); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); -}); - -Deno.test("AssertStringContains", function () { - assertStringIncludes("Denosaurus", "saur"); - assertStringIncludes("Denosaurus", "Deno"); - assertStringIncludes("Denosaurus", "rus"); - let didThrow; - try { - assertStringIncludes("Denosaurus", "Raptor"); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); -}); - -Deno.test("ArrayContains", function () { - const fixture = ["deno", "iz", "luv"]; - const fixtureObject = [{ deno: "luv" }, { deno: "Js" }]; - assertArrayIncludes(fixture, ["deno"]); - assertArrayIncludes(fixtureObject, [{ deno: "luv" }]); - assertArrayIncludes( - Uint8Array.from([1, 2, 3, 4]), - Uint8Array.from([1, 2, 3]), - ); - assertThrows( - () => assertArrayIncludes(fixtureObject, [{ deno: "node" }]), - AssertionError, - `Expected actual: "[ - { - deno: "luv", - }, - { - deno: "Js", - }, -]" to include: "[ - { - deno: "node", - }, -]". -missing: [ - { - deno: "node", - }, -]`, - ); -}); - -Deno.test("AssertStringContainsThrow", function () { - let didThrow = false; - try { - assertStringIncludes("Denosaurus from Jurassic", "Raptor"); - } catch (e) { - assert(e instanceof AssertionError); - assert( - e.message === - `Expected actual: "Denosaurus from Jurassic" to contain: "Raptor".`, - ); - didThrow = true; - } - assert(didThrow); -}); - -Deno.test("AssertStringMatching", function () { - assertMatch("foobar@deno.com", RegExp(/[a-zA-Z]+@[a-zA-Z]+.com/)); -}); - -Deno.test("AssertStringMatchingThrows", function () { - let didThrow = false; - try { - assertMatch("Denosaurus from Jurassic", RegExp(/Raptor/)); - } catch (e) { - assert(e instanceof AssertionError); - assert( - e.message === - `Expected actual: "Denosaurus from Jurassic" to match: "/Raptor/".`, - ); - didThrow = true; - } - assert(didThrow); -}); - -Deno.test("AssertStringNotMatching", function () { - assertNotMatch("foobar.deno.com", RegExp(/[a-zA-Z]+@[a-zA-Z]+.com/)); -}); - -Deno.test("AssertStringNotMatchingThrows", function () { - let didThrow = false; - try { - assertNotMatch("Denosaurus from Jurassic", RegExp(/from/)); - } catch (e) { - assert(e instanceof AssertionError); - assert( - e.message === - `Expected actual: "Denosaurus from Jurassic" to not match: "/from/".`, - ); - didThrow = true; - } - assert(didThrow); -}); - -Deno.test("AssertObjectMatching", function () { - const sym = Symbol("foo"); - const a = { foo: true, bar: false }; - const b = { ...a, baz: a }; - const c = { ...b, qux: b }; - const d = { corge: c, grault: c }; - const e = { foo: true } as { [key: string]: unknown }; - e.bar = e; - const f = { [sym]: true, bar: false }; - interface r { - foo: boolean; - bar: boolean; - } - const g: r = { foo: true, bar: false }; - const h = { foo: [1, 2, 3], bar: true }; - const i = { foo: [a, e], bar: true }; - const j = { foo: [[1, 2, 3]], bar: true }; - const k = { foo: [[1, [2, [3]]]], bar: true }; - const l = { foo: [[1, [2, [a, e, j, k]]]], bar: true }; - const m = { foo: /abc+/i, bar: [/abc/g, /abc/m] }; - const n = { - foo: new Set(["foo", "bar"]), - bar: new Map([ - ["foo", 1], - ["bar", 2], - ]), - baz: new Map([ - ["a", a], - ["b", b], - ]), - }; - - // Simple subset - assertObjectMatch(a, { - foo: true, - }); - // Subset with another subset - assertObjectMatch(b, { - foo: true, - baz: { bar: false }, - }); - // Subset with multiple subsets - assertObjectMatch(c, { - foo: true, - baz: { bar: false }, - qux: { - baz: { foo: true }, - }, - }); - // Subset with same object reference as subset - assertObjectMatch(d, { - corge: { - foo: true, - qux: { bar: false }, - }, - grault: { - bar: false, - qux: { foo: true }, - }, - }); - // Subset with circular reference - assertObjectMatch(e, { - foo: true, - bar: { - bar: { - bar: { - foo: true, - }, - }, - }, - }); - // Subset with interface - assertObjectMatch(g, { bar: false }); - // Subset with same symbol - assertObjectMatch(f, { - [sym]: true, - }); - // Subset with array inside - assertObjectMatch(h, { foo: [] }); - assertObjectMatch(h, { foo: [1, 2] }); - assertObjectMatch(h, { foo: [1, 2, 3] }); - assertObjectMatch(i, { foo: [{ bar: false }] }); - assertObjectMatch(i, { - foo: [{ bar: false }, { bar: { bar: { bar: { foo: true } } } }], - }); - // Subset with nested array inside - assertObjectMatch(j, { foo: [[1, 2, 3]] }); - assertObjectMatch(k, { foo: [[1, [2, [3]]]] }); - assertObjectMatch(l, { foo: [[1, [2, [a, e, j, k]]]] }); - // Regexp - assertObjectMatch(m, { foo: /abc+/i }); - assertObjectMatch(m, { bar: [/abc/g, /abc/m] }); - //Built-in data structures - assertObjectMatch(n, { foo: new Set(["foo"]) }); - assertObjectMatch(n, { bar: new Map([["bar", 2]]) }); - assertObjectMatch(n, { baz: new Map([["b", b]]) }); - assertObjectMatch(n, { baz: new Map([["b", { foo: true }]]) }); - - // Missing key - { - let didThrow; - try { - assertObjectMatch( - { - foo: true, - }, - { - foo: true, - bar: false, - }, - ); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - } - // Simple subset - { - let didThrow; - try { - assertObjectMatch(a, { - foo: false, - }); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - } - // Subset with another subset - { - let didThrow; - try { - assertObjectMatch(b, { - foo: true, - baz: { bar: true }, - }); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - } - // Subset with multiple subsets - { - let didThrow; - try { - assertObjectMatch(c, { - foo: true, - baz: { bar: false }, - qux: { - baz: { foo: false }, - }, - }); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - } - // Subset with same object reference as subset - { - let didThrow; - try { - assertObjectMatch(d, { - corge: { - foo: true, - qux: { bar: true }, - }, - grault: { - bar: false, - qux: { foo: false }, - }, - }); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - } - // Subset with circular reference - { - let didThrow; - try { - assertObjectMatch(e, { - foo: true, - bar: { - bar: { - bar: { - foo: false, - }, - }, - }, - }); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - } - // Subset with symbol key but with string key subset - { - let didThrow; - try { - assertObjectMatch(f, { - foo: true, - }); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - } - // Subset with array inside but doesn't match key subset - { - let didThrow; - try { - assertObjectMatch(i, { - foo: [1, 2, 3, 4], - }); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - } - { - let didThrow; - try { - assertObjectMatch(i, { - foo: [{ bar: true }, { foo: false }], - }); - didThrow = false; - } catch (e) { - assert(e instanceof AssertionError); - didThrow = true; - } - assertEquals(didThrow, true); - } - // actual/expected value as instance of class - { - class A { - a: number; - constructor(a: number) { - this.a = a; - } - } - assertObjectMatch({ test: new A(1) }, { test: { a: 1 } }); - assertObjectMatch({ test: { a: 1 } }, { test: { a: 1 } }); - assertObjectMatch({ test: { a: 1 } }, { test: new A(1) }); - assertObjectMatch({ test: new A(1) }, { test: new A(1) }); - } - { - // actual/expected contains same instance of Map/TypedArray/etc - const body = new Uint8Array([0, 1, 2]); - assertObjectMatch({ body, foo: "foo" }, { body }); - } - { - // match subsets of arrays - assertObjectMatch( - { positions: [[1, 2, 3, 4]] }, - { - positions: [[1, 2, 3]], - }, - ); - } - //Regexp - assertThrows(() => assertObjectMatch(m, { foo: /abc+/ }), AssertionError); - assertThrows(() => assertObjectMatch(m, { foo: /abc*/i }), AssertionError); - assertThrows( - () => assertObjectMatch(m, { bar: [/abc/m, /abc/g] }), - AssertionError, - ); - //Built-in data structures - assertThrows( - () => assertObjectMatch(n, { foo: new Set(["baz"]) }), - AssertionError, - ); - assertThrows( - () => assertObjectMatch(n, { bar: new Map([["bar", 3]]) }), - AssertionError, - ); - assertThrows( - () => assertObjectMatch(n, { baz: new Map([["a", { baz: true }]]) }), - AssertionError, - ); - // null in the first argument throws an assertion error, rather than a TypeError: Invalid value used as weak map key - assertThrows( - () => assertObjectMatch({ foo: null }, { foo: { bar: 42 } }), - AssertionError, - ); - assertObjectMatch({ foo: null, bar: null }, { foo: null }); - assertObjectMatch({ foo: undefined, bar: null }, { foo: undefined }); - assertThrows( - () => assertObjectMatch({ foo: undefined, bar: null }, { foo: null }), - AssertionError, - ); - // Non mapable primative types should throw a readable type error - assertThrows( - // @ts-expect-error Argument of type 'null' is not assignable to parameter of type 'Record' - () => assertObjectMatch(null, { foo: 42 }), - TypeError, - "assertObjectMatch", - ); - // @ts-expect-error Argument of type 'null' is not assignable to parameter of type 'Record' - assertThrows(() => assertObjectMatch(null, { foo: 42 }), TypeError, "null"); // since typeof null is "object", want to make sure user knows the bad value is "null" - assertThrows( - // @ts-expect-error Argument of type 'undefined' is not assignable to parameter of type 'Record' - () => assertObjectMatch(undefined, { foo: 42 }), - TypeError, - "assertObjectMatch", - ); - // @ts-expect-error Argument of type 'number' is not assignable to parameter of type 'Record' - assertThrows(() => assertObjectMatch(21, 42), TypeError, "assertObjectMatch"); - assertThrows( - // @ts-expect-error Argument of type 'string' is not assignable to parameter of type 'Record' - () => assertObjectMatch("string", "string"), - TypeError, - "assertObjectMatch", - ); -}); - -Deno.test("AssertsUnimplemented", function () { - let didThrow = false; - try { - unimplemented(); - } catch (e) { - assert(e instanceof AssertionError); - assert(e.message === "Unimplemented."); - didThrow = true; - } - assert(didThrow); -}); - -Deno.test("AssertsUnreachable", function () { - let didThrow = false; - try { - unreachable(); - } catch (e) { - assert(e instanceof AssertionError); - assert(e.message === "unreachable"); - didThrow = true; - } - assert(didThrow); -}); - -Deno.test("AssertFail", function () { - assertThrows(fail, AssertionError, "Failed assertion."); - assertThrows( - () => { - fail("foo"); - }, - AssertionError, - "Failed assertion: foo", - ); -}); - -Deno.test("assertThrows with wrong error class", () => { - assertThrows( - () => { - //This next assertThrows will throw an AssertionError due to the wrong - //expected error class - assertThrows( - () => { - fail("foo"); - }, - TypeError, - "Failed assertion: foo", - ); - }, - AssertionError, - `Expected error to be instance of "TypeError", but was "AssertionError"`, - ); -}); - -Deno.test("assertThrows with return type", () => { - assertThrows(() => { - throw new Error(); - }); -}); - -Deno.test("assertRejects with return type", async () => { - await assertRejects(() => { - return Promise.reject(new Error()); - }); -}); - -Deno.test("assertRejects with synchronous function that throws", async () => { - await assertRejects(() => - assertRejects(() => { - throw new Error(); - }) - ); - await assertRejects( - () => - assertRejects(() => { - throw { wrong: "true" }; - }), - AssertionError, - "Function throws when expected to reject.", - ); -}); - -Deno.test("assertRejects with PromiseLike", async () => { - await assertRejects( - () => ({ - then() { - throw new Error("some error"); - }, - }), - Error, - "some error", - ); -}); - -Deno.test("assertThrows with non-error value thrown and error class", () => { - assertThrows( - () => { - assertThrows( - () => { - throw "Panic!"; - }, - Error, - "Panic!", - ); - }, - AssertionError, - "A non-Error object was thrown.", - ); -}); - -Deno.test("assertRejects with non-error value rejected and error class", async () => { - await assertRejects( - () => { - return assertRejects( - () => { - return Promise.reject("Panic!"); - }, - Error, - "Panic!", - ); - }, - AssertionError, - "A non-Error object was rejected.", - ); -}); - -Deno.test("assertThrows with non-error value thrown", () => { - assertThrows( - () => { - throw "Panic!"; - }, - ); - assertThrows( - () => { - throw null; - }, - ); - assertThrows( - () => { - throw undefined; - }, - ); -}); - -Deno.test("assertRejects with non-error value rejected", async () => { - await assertRejects(() => { - return Promise.reject(null); - }); - await assertRejects(() => { - return Promise.reject(undefined); - }); -}); - -Deno.test("assertThrows with error class", () => { - assertThrows( - () => { - throw new Error("foo"); - }, - Error, - "foo", - ); -}); - -Deno.test("assertRejects with error class", async () => { - await assertRejects( - () => { - return Promise.reject(new Error("foo")); - }, - Error, - "foo", - ); -}); - -Deno.test("assertThrows with thrown error returns caught error", () => { - const error = assertThrows( - () => { - throw new Error("foo"); - }, - ); - assert(error instanceof Error); - assertEquals(error.message, "foo"); -}); - -Deno.test("assertThrows with thrown non-error returns caught error", () => { - const stringError = assertThrows( - () => { - throw "Panic!"; - }, - ); - assert(typeof stringError === "string"); - assertEquals(stringError, "Panic!"); - - const numberError = assertThrows( - () => { - throw 1; - }, - ); - assert(typeof numberError === "number"); - assertEquals(numberError, 1); - - const nullError = assertThrows( - () => { - throw null; - }, - ); - assert(nullError === null); - - const undefinedError = assertThrows( - () => { - throw undefined; - }, - ); - assert(typeof undefinedError === "undefined"); - assertEquals(undefinedError, undefined); -}); - -Deno.test("assertRejectes resolves with caught error", async () => { - const error = await assertRejects( - () => { - return Promise.reject(new Error("foo")); - }, - ); - assert(error instanceof Error); - assertEquals(error.message, "foo"); -}); - -const createHeader = (): string[] => [ - "", - "", - ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${ - green( - bold("Expected"), - ) - }`, - "", - "", -]; - -const added: (s: string) => string = (s: string): string => - green(bold(stripColor(s))); -const removed: (s: string) => string = (s: string): string => - red(bold(stripColor(s))); - -Deno.test({ - name: "pass case", - fn() { - assertEquals({ a: 10 }, { a: 10 }); - assertEquals(true, true); - assertEquals(10, 10); - assertEquals("abc", "abc"); - assertEquals({ a: 10, b: { c: "1" } }, { a: 10, b: { c: "1" } }); - assertEquals(new Date("invalid"), new Date("invalid")); - }, -}); - -Deno.test({ - name: "failed with number", - fn() { - assertThrows( - () => assertEquals(1, 2), - AssertionError, - [ - "Values are not equal.", - ...createHeader(), - removed(`- ${yellow("1")}`), - added(`+ ${yellow("2")}`), - "", - ].join("\n"), - ); - }, -}); - -Deno.test({ - name: "failed with number vs string", - fn() { - assertThrows( - () => assertEquals(1, "1"), - AssertionError, - [ - "Values are not equal.", - ...createHeader(), - removed(`- ${yellow("1")}`), - added(`+ "1"`), - ].join("\n"), - ); - }, -}); - -Deno.test({ - name: "failed with array", - fn() { - assertThrows( - () => assertEquals([1, "2", 3], ["1", "2", 3]), - AssertionError, - ` - [ -- 1, -+ "1", - "2", - 3, - ]`, - ); - }, -}); - -Deno.test({ - name: "failed with object", - fn() { - assertThrows( - () => assertEquals({ a: 1, b: "2", c: 3 }, { a: 1, b: 2, c: [3] }), - AssertionError, - ` - { - a: 1, -+ b: 2, -+ c: [ -+ 3, -+ ], -- b: "2", -- c: 3, - }`, - ); - }, -}); - -Deno.test({ - name: "failed with date", - fn() { - assertThrows( - () => - assertEquals( - new Date(2019, 0, 3, 4, 20, 1, 10), - new Date(2019, 0, 3, 4, 20, 1, 20), - ), - AssertionError, - [ - "Values are not equal.", - ...createHeader(), - removed(`- ${new Date(2019, 0, 3, 4, 20, 1, 10).toISOString()}`), - added(`+ ${new Date(2019, 0, 3, 4, 20, 1, 20).toISOString()}`), - "", - ].join("\n"), - ); - assertThrows( - () => - assertEquals(new Date("invalid"), new Date(2019, 0, 3, 4, 20, 1, 20)), - AssertionError, - [ - "Values are not equal.", - ...createHeader(), - removed(`- ${new Date("invalid")}`), - added(`+ ${new Date(2019, 0, 3, 4, 20, 1, 20).toISOString()}`), - "", - ].join("\n"), - ); - }, -}); - -Deno.test({ - name: "failed with custom msg", - fn() { - assertThrows( - () => assertEquals(1, 2, "CUSTOM MESSAGE"), - AssertionError, - [ - "Values are not equal: CUSTOM MESSAGE", - ...createHeader(), - removed(`- ${yellow("1")}`), - added(`+ ${yellow("2")}`), - "", - ].join("\n"), - ); - }, -}); - -Deno.test({ - name: "strict types test", - fn() { - const x = { number: 2 }; - - const y = x as Record; - const z = x as unknown; - - // y.number; - // ~~~~~~ - // Property 'number' does not exist on type 'Record'.deno-ts(2339) - - assertStrictEquals(y, x); - y.number; // ok - - // z.number; - // ~ - // Object is of type 'unknown'.deno-ts(2571) - - assertStrictEquals(z, x); - z.number; // ok - }, -}); - -Deno.test({ - name: "strict pass case", - fn() { - assertStrictEquals(true, true); - assertStrictEquals(10, 10); - assertStrictEquals("abc", "abc"); - assertStrictEquals(NaN, NaN); - - const xs = [1, false, "foo"]; - const ys = xs; - assertStrictEquals(xs, ys); - - const x = { a: 1 }; - const y = x; - assertStrictEquals(x, y); - }, -}); - -Deno.test({ - name: "strict failed with structure diff", - fn() { - assertThrows( - () => assertStrictEquals({ a: 1, b: 2 }, { a: 1, c: [3] }), - AssertionError, - ` - { - a: 1, -+ c: [ -+ 3, -+ ], -- b: 2, - }`, - ); - }, -}); - -Deno.test({ - name: "strict failed with reference diff", - fn() { - assertThrows( - () => assertStrictEquals({ a: 1, b: 2 }, { a: 1, b: 2 }), - AssertionError, - `Values have the same structure but are not reference-equal. - - { - a: 1, - b: 2, - }`, - ); - }, -}); - -Deno.test({ - name: "strict failed with custom msg", - fn() { - assertThrows( - () => assertStrictEquals({ a: 1 }, { a: 1 }, "CUSTOM MESSAGE"), - AssertionError, - `Values have the same structure but are not reference-equal: CUSTOM MESSAGE - - { - a: 1, - }`, - ); - }, -}); - -Deno.test({ - name: "strictly unequal pass case", - fn() { - assertNotStrictEquals(true, false); - assertNotStrictEquals(10, 11); - assertNotStrictEquals("abc", "xyz"); - assertNotStrictEquals(1, "1"); - assertNotStrictEquals(-0, +0); - - const xs = [1, false, "foo"]; - const ys = [1, true, "bar"]; - assertNotStrictEquals(xs, ys); - - const x = { a: 1 }; - const y = { a: 2 }; - assertNotStrictEquals(x, y); - }, -}); - -Deno.test({ - name: "strictly unequal fail case", - fn() { - assertThrows(() => assertNotStrictEquals(1, 1), AssertionError); - assertThrows(() => assertNotStrictEquals(NaN, NaN), AssertionError); - }, -}); - -Deno.test("assert almost equals number", () => { - //Default precision - assertAlmostEquals(-0, +0); - assertAlmostEquals(Math.PI, Math.PI); - assertAlmostEquals(0.1 + 0.2, 0.3); - assertAlmostEquals(NaN, NaN); - assertAlmostEquals(Number.NaN, Number.NaN); - assertThrows(() => assertAlmostEquals(1, 2)); - assertThrows(() => assertAlmostEquals(1, 1.1)); - - //Higher precision - assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); - assertThrows( - () => assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17), - AssertionError, - `Expected actual: "${ - ( - 0.1 + 0.2 - ).toExponential() - }" to be close to "${(0.3).toExponential()}"`, - ); - - //Special cases - assertAlmostEquals(Infinity, Infinity); - assertThrows( - () => assertAlmostEquals(0, Infinity), - AssertionError, - 'Expected actual: "0" to be close to "Infinity"', - ); - assertThrows( - () => assertAlmostEquals(-Infinity, +Infinity), - AssertionError, - 'Expected actual: "-Infinity" to be close to "Infinity"', - ); - assertThrows( - () => assertAlmostEquals(Infinity, NaN), - AssertionError, - 'Expected actual: "Infinity" to be close to "NaN"', - ); -}); - -Deno.test({ - name: "assertInstanceOf", - fn() { - class TestClass1 {} - class TestClass2 {} - class TestClass3 {} - - // Regular types - assertInstanceOf(new Date(), Date); - assertInstanceOf(new Number(), Number); - assertInstanceOf(Promise.resolve(), Promise); - assertInstanceOf(new TestClass1(), TestClass1); - - // Throwing cases - assertThrows( - () => assertInstanceOf(new Date(), RegExp), - AssertionError, - `Expected object to be an instance of "RegExp" but was "Date".`, - ); - assertThrows( - () => assertInstanceOf(5, Date), - AssertionError, - `Expected object to be an instance of "Date" but was "number".`, - ); - assertThrows( - () => assertInstanceOf(new TestClass1(), TestClass2), - AssertionError, - `Expected object to be an instance of "TestClass2" but was "TestClass1".`, - ); - - // Custom message - assertThrows( - () => assertInstanceOf(new Date(), RegExp, "Custom message"), - AssertionError, - "Custom message", - ); - - // Edge cases - assertThrows( - () => assertInstanceOf(5, Number), - AssertionError, - `Expected object to be an instance of "Number" but was "number".`, - ); - - let TestClassWithSameName: new () => unknown; - { - class TestClass3 {} - TestClassWithSameName = TestClass3; - } - assertThrows( - () => assertInstanceOf(new TestClassWithSameName(), TestClass3), - AssertionError, - `Expected object to be an instance of "TestClass3".`, - ); - - assertThrows( - () => assertInstanceOf(TestClass1, TestClass1), - AssertionError, - `Expected object to be an instance of "TestClass1" but was not an instanced object.`, - ); - assertThrows( - () => assertInstanceOf(() => {}, TestClass1), - AssertionError, - `Expected object to be an instance of "TestClass1" but was not an instanced object.`, - ); - assertThrows( - () => assertInstanceOf(null, TestClass1), - AssertionError, - `Expected object to be an instance of "TestClass1" but was "null".`, - ); - assertThrows( - () => assertInstanceOf(undefined, TestClass1), - AssertionError, - `Expected object to be an instance of "TestClass1" but was "undefined".`, - ); - assertThrows( - () => assertInstanceOf({}, TestClass1), - AssertionError, - `Expected object to be an instance of "TestClass1" but was "Object".`, - ); - assertThrows( - () => assertInstanceOf(Object.create(null), TestClass1), - AssertionError, - `Expected object to be an instance of "TestClass1" but was "Object".`, - ); - - // Test TypeScript types functionality, wrapped in a function that never runs - // deno-lint-ignore no-unused-vars - function typeScriptTests() { - class ClassWithProperty { - property = "prop1"; - } - const testInstance = new ClassWithProperty() as unknown; - - // @ts-expect-error: `testInstance` is `unknown` so setting its property before `assertInstanceOf` should give a type error. - testInstance.property = "prop2"; - - assertInstanceOf(testInstance, ClassWithProperty); - - // Now `testInstance` should be of type `ClassWithProperty` - testInstance.property = "prop3"; - - let x = 5 as unknown; - - // @ts-expect-error: `x` is `unknown` so adding to it shouldn't work - x += 5; - assertInstanceOf(x, Number); - - // @ts-expect-error: `x` is now `Number` rather than `number`, so this should still give a type error. - x += 5; - } - }, -}); - -Deno.test({ - name: "assertNotInstanceOf", - fn() { - assertNotInstanceOf("not a number", Number); - assertNotInstanceOf(42, String); - assertNotInstanceOf(new URL("http://example.com"), Boolean); - }, -}); - -Deno.test({ - name: "assert* functions with specified type parameter", - fn() { - assertEquals("hello", "hello"); - assertNotEquals(1, 2); - assertArrayIncludes([true, false], [true]); - const value = { x: 1 }; - assertStrictEquals(value, value); - assertNotStrictEquals(value, { x: 1 }); - }, -}); - -Deno.test( - "assertEquals compares objects structurally if one object's constructor is undefined and the other is Object", - () => { - const a = Object.create(null); - a.prop = "test"; - const b = { - prop: "test", - }; - - assertEquals(a, b); - assertEquals(b, a); - }, -); - -Deno.test("assertEquals diff for differently ordered objects", () => { - assertThrows( - () => { - assertEquals( - { - aaaaaaaaaaaaaaaaaaaaaaaa: 0, - bbbbbbbbbbbbbbbbbbbbbbbb: 0, - ccccccccccccccccccccccc: 0, - }, - { - ccccccccccccccccccccccc: 1, - aaaaaaaaaaaaaaaaaaaaaaaa: 0, - bbbbbbbbbbbbbbbbbbbbbbbb: 0, - }, - ); - }, - AssertionError, - ` - { - aaaaaaaaaaaaaaaaaaaaaaaa: 0, - bbbbbbbbbbbbbbbbbbbbbbbb: 0, -- ccccccccccccccccccccccc: 0, -+ ccccccccccccccccccccccc: 1, - }`, - ); -}); - -Deno.test("Assert Throws Parent Error", () => { - assertThrows( - () => { - throw new AssertionError("Fail!"); - }, - Error, - "Fail!", - ); -}); - -Deno.test("Assert Throws Async Parent Error", async () => { - await assertRejects( - () => { - return Promise.reject(new AssertionError("Fail!")); - }, - Error, - "Fail!", - ); -}); - -Deno.test( - "Assert Throws Async promise rejected with custom Error", - async () => { - class CustomError extends Error {} - class AnotherCustomError extends Error {} - await assertRejects( - () => - assertRejects( - () => Promise.reject(new AnotherCustomError("failed")), - CustomError, - "fail", - ), - AssertionError, - 'Expected error to be instance of "CustomError", but was "AnotherCustomError".', - ); - }, -); - -Deno.test("Assert Is Error Non-Error Fail", () => { - assertThrows( - () => assertIsError("Panic!", undefined, "Panic!"), - AssertionError, - `Expected "error" to be an Error object.`, - ); - - assertThrows( - () => assertIsError(null), - AssertionError, - `Expected "error" to be an Error object.`, - ); - - assertThrows( - () => assertIsError(undefined), - AssertionError, - `Expected "error" to be an Error object.`, - ); -}); - -Deno.test("Assert Is Error Parent Error", () => { - assertIsError(new AssertionError("Fail!"), Error, "Fail!"); -}); - -Deno.test("Assert Is Error with custom Error", () => { - class CustomError extends Error {} - class AnotherCustomError extends Error {} - assertIsError(new CustomError("failed"), CustomError, "fail"); - assertThrows( - () => assertIsError(new AnotherCustomError("failed"), CustomError, "fail"), - AssertionError, - 'Expected error to be instance of "CustomError", but was "AnotherCustomError".', - ); -}); - -Deno.test("Assert False with falsy values", () => { - assertFalse(false); - assertFalse(0); - assertFalse(""); - assertFalse(null); - assertFalse(undefined); -}); - -Deno.test("Assert False with truthy values", () => { - assertThrows(() => assertFalse(true)); - assertThrows(() => assertFalse(1)); - assertThrows(() => assertFalse("a")); - assertThrows(() => assertFalse({})); - assertThrows(() => assertFalse([])); -}); - -Deno.test("assertEquals same Set with object keys", () => { - const data = [ - { - id: "_1p7ZED73OF98VbT1SzSkjn", - type: { id: "_ETGENUS" }, - name: "Thuja", - friendlyId: "g-thuja", - }, - { - id: "_567qzghxZmeQ9pw3q09bd3", - type: { id: "_ETGENUS" }, - name: "Pinus", - friendlyId: "g-pinus", - }, - ]; - assertEquals(data, data); - assertEquals(new Set(data), new Set(data)); -}); diff --git a/testing/bdd.ts b/testing/bdd.ts index b78ebf73497a..f9ca081cdd54 100644 --- a/testing/bdd.ts +++ b/testing/bdd.ts @@ -92,7 +92,7 @@ * assertEquals, * assertStrictEquals, * assertThrows, - * } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * } from "https://deno.land/std@$STD_VERSION/assert/mod.ts"; * import { User } from "https://deno.land/std@$STD_VERSION/testing/bdd_examples/user.ts"; * * Deno.test("User.users initially empty", () => { @@ -137,7 +137,7 @@ * assertEquals, * assertStrictEquals, * assertThrows, - * } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * } from "https://deno.land/std@$STD_VERSION/assert/mod.ts"; * import { * afterEach, * beforeEach, @@ -199,7 +199,7 @@ * assertEquals, * assertStrictEquals, * assertThrows, - * } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * } from "https://deno.land/std@$STD_VERSION/assert/mod.ts"; * import { * describe, * it, @@ -259,7 +259,7 @@ * assertEquals, * assertStrictEquals, * assertThrows, - * } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * } from "https://deno.land/std@$STD_VERSION/assert/mod.ts"; * import { * describe, * it, diff --git a/testing/fast_check_example.ts b/testing/fast_check_example.ts index 68a202df214d..7823bd3f41a0 100644 --- a/testing/fast_check_example.ts +++ b/testing/fast_check_example.ts @@ -23,10 +23,7 @@ import fc from "https://cdn.skypack.dev/fast-check@3.10.0"; import { groupBy } from "../collections/group_by.ts"; -import { - assert, - assertEquals, -} from "https://deno.land/std@0.90.0/testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; /********************** contains() *************************************/ const contains = (text: string, pattern: string): boolean => diff --git a/testing/mock.ts b/testing/mock.ts index d96fb8a5bf5e..b3a9dbe1f06e 100644 --- a/testing/mock.ts +++ b/testing/mock.ts @@ -41,7 +41,7 @@ * assertSpyCalls, * spy, * } from "https://deno.land/std@$STD_VERSION/testing/mock.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * import { * multiply, * square, @@ -94,7 +94,7 @@ * assertSpyCalls, * spy, * } from "https://deno.land/std@$STD_VERSION/testing/mock.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * import { * _internals, * square, @@ -178,7 +178,7 @@ * returnsNext, * stub, * } from "https://deno.land/std@$STD_VERSION/testing/mock.ts"; - * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts"; + * import { assertEquals } from "https://deno.land/std@$STD_VERSION/assert/assert_equals.ts"; * import { * _internals, * randomMultiple, diff --git a/testing/snapshot.ts b/testing/snapshot.ts index ca616428d661..112f67d7327c 100644 --- a/testing/snapshot.ts +++ b/testing/snapshot.ts @@ -140,7 +140,7 @@ import { fromFileUrl, parse, resolve, toFileUrl } from "../path/mod.ts"; import { ensureFile, ensureFileSync } from "../fs/mod.ts"; import { bold, green, red } from "../fmt/colors.ts"; import { assert, AssertionError, equal } from "./asserts.ts"; -import { buildMessage, diff, diffstr } from "./_diff.ts"; +import { buildMessage, diff, diffstr } from "../_util/diff.ts"; const CAN_NOT_DISPLAY = "[Cannot display]"; const SNAPSHOT_DIR = "__snapshots__"; diff --git a/toml/parse_test.ts b/toml/parse_test.ts index e356ee652c73..e830ac7da03e 100644 --- a/toml/parse_test.ts +++ b/toml/parse_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { ArrayValue, BareKey, diff --git a/toml/test.ts b/toml/test.ts index c4a0bcd44453..ba45794e5dab 100644 --- a/toml/test.ts +++ b/toml/test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { existsSync } from "../fs/exists.ts"; import * as path from "../path/mod.ts"; import { parse, stringify } from "./mod.ts"; diff --git a/uuid/constants_test.ts b/uuid/constants_test.ts index da911f8ba63a..fd2012fc52b0 100644 --- a/uuid/constants_test.ts +++ b/uuid/constants_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals } from "../testing/asserts.ts"; +import { assertEquals } from "../assert/mod.ts"; import { NAMESPACE_DNS, NAMESPACE_OID, diff --git a/uuid/test.ts b/uuid/test.ts index fa9b5059056e..2232e068f267 100644 --- a/uuid/test.ts +++ b/uuid/test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assert, assertEquals, assertThrows } from "../assert/mod.ts"; import { isNil, NIL_UUID, validate, version } from "./mod.ts"; Deno.test("[UUID] isNil", () => { diff --git a/uuid/v1_test.ts b/uuid/v1_test.ts index d279f5be0294..d72053d3cee6 100644 --- a/uuid/v1_test.ts +++ b/uuid/v1_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { generate, validate } from "./v1.ts"; Deno.test("[UUID] is_valid_uuid_v1", () => { diff --git a/uuid/v3.ts b/uuid/v3.ts index 233014e3356d..121802e1ee2e 100644 --- a/uuid/v3.ts +++ b/uuid/v3.ts @@ -3,7 +3,7 @@ import { bytesToUuid, uuidToBytes } from "./_common.ts"; import { concat } from "../bytes/concat.ts"; -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; import { crypto } from "../crypto/crypto.ts"; const UUID_RE = diff --git a/uuid/v3_test.ts b/uuid/v3_test.ts index d5e9ce55c292..ab8954602980 100644 --- a/uuid/v3_test.ts +++ b/uuid/v3_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { generate, validate } from "./v3.ts"; const NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341"; diff --git a/uuid/v4_test.ts b/uuid/v4_test.ts index a6852e76320b..10b1367a1717 100644 --- a/uuid/v4_test.ts +++ b/uuid/v4_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert } from "../testing/asserts.ts"; +import { assert } from "../assert/mod.ts"; import { validate } from "./v4.ts"; Deno.test("[UUID] is_valid_uuid_v4", () => { diff --git a/uuid/v5.ts b/uuid/v5.ts index f69ba50c8e01..a5272ac1f075 100644 --- a/uuid/v5.ts +++ b/uuid/v5.ts @@ -3,7 +3,7 @@ import { bytesToUuid, uuidToBytes } from "./_common.ts"; import { concat } from "../bytes/concat.ts"; -import { assert } from "../_util/asserts.ts"; +import { assert } from "../assert/assert.ts"; const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; diff --git a/uuid/v5_test.ts b/uuid/v5_test.ts index 67cb46e9bac3..36a89c07855b 100644 --- a/uuid/v5_test.ts +++ b/uuid/v5_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals } from "../assert/mod.ts"; import { generate, validate } from "./v5.ts"; const NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341"; diff --git a/wasi/snapshot_preview1_test.ts b/wasi/snapshot_preview1_test.ts index bbb437b416b1..ecce32f5985e 100644 --- a/wasi/snapshot_preview1_test.ts +++ b/wasi/snapshot_preview1_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import Context from "./snapshot_preview1.ts"; -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { copy } from "../fs/copy.ts"; import * as path from "../path/mod.ts"; import { writeAll } from "../streams/write_all.ts"; diff --git a/yaml/parse_test.ts b/yaml/parse_test.ts index c199c98a77f6..f1e8c97f880b 100644 --- a/yaml/parse_test.ts +++ b/yaml/parse_test.ts @@ -4,7 +4,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import { parse, parseAll } from "./parse.ts"; -import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assert, assertEquals, assertThrows } from "../assert/mod.ts"; import { DEFAULT_SCHEMA, EXTENDED_SCHEMA } from "./schema/mod.ts"; import { YAMLError } from "./_error.ts"; import { Type } from "./type.ts"; diff --git a/yaml/stringify_test.ts b/yaml/stringify_test.ts index dc68e02c214d..e7ec6361bef9 100644 --- a/yaml/stringify_test.ts +++ b/yaml/stringify_test.ts @@ -3,7 +3,7 @@ // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../assert/mod.ts"; import { stringify } from "./stringify.ts"; import { YAMLError } from "./_error.ts"; import { DEFAULT_SCHEMA, EXTENDED_SCHEMA } from "./schema/mod.ts";