@executablemd/testing 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/esm/core/mod.js +55 -0
  3. package/esm/core/src/api.js +31 -0
  4. package/esm/core/src/collect.js +24 -0
  5. package/esm/core/src/component-api.js +47 -0
  6. package/esm/core/src/content-context.js +23 -0
  7. package/esm/core/src/deno-compiler.js +51 -0
  8. package/esm/core/src/errors.js +13 -0
  9. package/esm/core/src/eval-context.js +13 -0
  10. package/esm/core/src/eval-handler.js +79 -0
  11. package/esm/core/src/eval-interpolate.js +63 -0
  12. package/esm/core/src/eval-transform.js +378 -0
  13. package/esm/core/src/execute.js +378 -0
  14. package/esm/core/src/expand.js +988 -0
  15. package/esm/core/src/frontmatter.js +98 -0
  16. package/esm/core/src/heal.js +29 -0
  17. package/esm/core/src/interpolate.js +39 -0
  18. package/esm/core/src/modifiers/daemon.js +60 -0
  19. package/esm/core/src/modifiers/persist.js +35 -0
  20. package/esm/core/src/modifiers/timeout.js +55 -0
  21. package/esm/core/src/modifiers.js +113 -0
  22. package/esm/core/src/output/normalize.js +33 -0
  23. package/esm/core/src/output/terminal.js +20 -0
  24. package/esm/core/src/render.js +30 -0
  25. package/esm/core/src/replay-stream.js +58 -0
  26. package/esm/core/src/sample-api.js +45 -0
  27. package/esm/core/src/scanner.js +632 -0
  28. package/esm/core/src/temp-file-compiler.js +68 -0
  29. package/esm/core/src/types.js +7 -0
  30. package/esm/core/src/validate.js +82 -0
  31. package/esm/durable-streams/combinators.js +227 -0
  32. package/esm/durable-streams/context.js +13 -0
  33. package/esm/durable-streams/divergence.js +56 -0
  34. package/esm/durable-streams/each.js +193 -0
  35. package/esm/durable-streams/effect.js +273 -0
  36. package/esm/durable-streams/ephemeral.js +80 -0
  37. package/esm/durable-streams/errors.js +92 -0
  38. package/esm/durable-streams/http-stream.js +207 -0
  39. package/esm/durable-streams/mod.js +34 -0
  40. package/esm/durable-streams/operations.js +88 -0
  41. package/esm/durable-streams/replay-guard.js +87 -0
  42. package/esm/durable-streams/replay-index.js +132 -0
  43. package/esm/durable-streams/run.js +137 -0
  44. package/esm/durable-streams/serialize.js +65 -0
  45. package/esm/durable-streams/stream.js +56 -0
  46. package/esm/durable-streams/types.js +10 -0
  47. package/esm/package.json +3 -0
  48. package/esm/runtime/apis.js +237 -0
  49. package/esm/runtime/find-free-port.js +33 -0
  50. package/esm/runtime/mod.js +20 -0
  51. package/esm/testing/npm/src/_dnt.polyfills.js +1 -0
  52. package/esm/testing/npm/src/_dnt.shims.js +57 -0
  53. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/almost_equals.js +47 -0
  54. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/array_includes.js +65 -0
  55. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/assert.js +23 -0
  56. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/assertion_error.js +30 -0
  57. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/equal.js +194 -0
  58. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/equals.js +61 -0
  59. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/exists.js +27 -0
  60. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/fail.js +20 -0
  61. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/false.js +23 -0
  62. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/greater.js +29 -0
  63. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.js +29 -0
  64. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/instance_of.js +52 -0
  65. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/is_error.js +53 -0
  66. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/less.js +28 -0
  67. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/less_or_equal.js +29 -0
  68. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/match.js +26 -0
  69. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/mod.js +45 -0
  70. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/not_equals.js +39 -0
  71. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/not_instance_of.js +29 -0
  72. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/not_match.js +26 -0
  73. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.js +32 -0
  74. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/object_match.js +177 -0
  75. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/rejects.js +53 -0
  76. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/strict_equals.js +58 -0
  77. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/string_includes.js +26 -0
  78. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/throws.js +44 -0
  79. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/unimplemented.js +20 -0
  80. package/esm/testing/npm/src/deps/jsr.io/@std/assert/1.0.19/unreachable.js +20 -0
  81. package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/build_message.js +116 -0
  82. package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/diff.js +277 -0
  83. package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/diff_str.js +181 -0
  84. package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/format.js +70 -0
  85. package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/styles.js +207 -0
  86. package/esm/testing/npm/src/deps/jsr.io/@std/internal/1.0.14/types.js +3 -0
  87. package/esm/testing/npm/src/mod.js +27 -0
  88. package/esm/testing/npm/src/src/assertions.js +250 -0
  89. package/esm/testing/npm/src/src/handlers.js +245 -0
  90. package/esm/testing/npm/src/src/journal.js +152 -0
  91. package/esm/testing/npm/src/src/test-api.js +33 -0
  92. package/esm/testing/npm/src/src/use-testing.js +79 -0
  93. package/esm/testing/npm/src/src/vocabulary.js +111 -0
  94. package/package.json +35 -0
  95. package/types/_dnt.polyfills.d.ts +6 -0
  96. package/types/_dnt.shims.d.ts +1 -0
  97. package/types/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts +29 -0
  98. package/types/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts +28 -0
  99. package/types/deps/jsr.io/@std/assert/1.0.19/assert.d.ts +16 -0
  100. package/types/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts +25 -0
  101. package/types/deps/jsr.io/@std/assert/1.0.19/equal.d.ts +24 -0
  102. package/types/deps/jsr.io/@std/assert/1.0.19/equals.d.ts +36 -0
  103. package/types/deps/jsr.io/@std/assert/1.0.19/exists.d.ts +17 -0
  104. package/types/deps/jsr.io/@std/assert/1.0.19/fail.d.ts +14 -0
  105. package/types/deps/jsr.io/@std/assert/1.0.19/false.d.ts +18 -0
  106. package/types/deps/jsr.io/@std/assert/1.0.19/greater.d.ts +19 -0
  107. package/types/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts +19 -0
  108. package/types/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts +22 -0
  109. package/types/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts +24 -0
  110. package/types/deps/jsr.io/@std/assert/1.0.19/less.d.ts +18 -0
  111. package/types/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts +19 -0
  112. package/types/deps/jsr.io/@std/assert/1.0.19/match.d.ts +17 -0
  113. package/types/deps/jsr.io/@std/assert/1.0.19/mod.d.ts +43 -0
  114. package/types/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts +26 -0
  115. package/types/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts +19 -0
  116. package/types/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts +17 -0
  117. package/types/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts +22 -0
  118. package/types/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts +28 -0
  119. package/types/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts +41 -0
  120. package/types/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts +23 -0
  121. package/types/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts +17 -0
  122. package/types/deps/jsr.io/@std/assert/1.0.19/throws.d.ts +44 -0
  123. package/types/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts +14 -0
  124. package/types/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts +14 -0
  125. package/types/deps/jsr.io/@std/internal/1.0.14/build_message.d.ts +79 -0
  126. package/types/deps/jsr.io/@std/internal/1.0.14/diff.d.ts +139 -0
  127. package/types/deps/jsr.io/@std/internal/1.0.14/diff_str.d.ts +98 -0
  128. package/types/deps/jsr.io/@std/internal/1.0.14/format.d.ts +28 -0
  129. package/types/deps/jsr.io/@std/internal/1.0.14/styles.d.ts +158 -0
  130. package/types/deps/jsr.io/@std/internal/1.0.14/types.d.ts +24 -0
  131. package/types/mod.d.ts +29 -0
  132. package/types/src/assertions.d.ts +55 -0
  133. package/types/src/handlers.d.ts +18 -0
  134. package/types/src/journal.d.ts +29 -0
  135. package/types/src/test-api.d.ts +54 -0
  136. package/types/src/use-testing.d.ts +25 -0
  137. package/types/src/vocabulary.d.ts +34 -0
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are almost equal numbers
3
+ * through a given tolerance. It can be used to take into account IEEE-754
4
+ * double-precision floating-point representation limitations. If the values
5
+ * are not almost equal then throw.
6
+ *
7
+ * The default tolerance is one hundred thousandth of a percent of the
8
+ * expected value.
9
+ *
10
+ * @example Usage
11
+ * ```ts ignore
12
+ * import { assertAlmostEquals } from "@std/assert";
13
+ *
14
+ * assertAlmostEquals(0.01, 0.02); // Throws
15
+ * assertAlmostEquals(1e-8, 1e-9); // Throws
16
+ * assertAlmostEquals(1.000000001e-8, 1.000000002e-8); // Doesn't throw
17
+ * assertAlmostEquals(0.01, 0.02, 0.1); // Doesn't throw
18
+ * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); // Doesn't throw
19
+ * assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17); // Throws
20
+ * ```
21
+ *
22
+ * @param actual The actual value to compare.
23
+ * @param expected The expected value to compare.
24
+ * @param tolerance The tolerance to consider the values almost equal. The
25
+ * default is one hundred thousandth of a percent of the expected value.
26
+ * @param msg The optional message to include in the error.
27
+ * @throws {AssertionError} If the values are not almost equal.
28
+ */
29
+ export declare function assertAlmostEquals(actual: number, expected: number, tolerance?: number, msg?: string): void;
@@ -0,0 +1,28 @@
1
+ /** An array-like object (`Array`, `Uint8Array`, `NodeList`, etc.) that is not a string */
2
+ export type ArrayLikeArg<T> = ArrayLike<T> & object;
3
+ /**
4
+ * Asserts that `actual` contains all values in `expected`, using deep equality
5
+ * for non-primitive values.
6
+ *
7
+ * @example Usage with primitives
8
+ * ```ts ignore
9
+ * import { assertArrayIncludes } from "@std/assert";
10
+ *
11
+ * assertArrayIncludes([1, 2, 3], [2, 3]); // Passes
12
+ * assertArrayIncludes([1, 2, 3], [4]); // Throws
13
+ * ```
14
+ *
15
+ * @example Usage with objects (deep equality)
16
+ * ```ts ignore
17
+ * import { assertArrayIncludes } from "@std/assert";
18
+ *
19
+ * assertArrayIncludes([{ a: 1 }, { b: 2 }], [{ a: 1 }]); // Passes
20
+ * ```
21
+ *
22
+ * @typeParam T The element type of the arrays.
23
+ * @param actual The array-like object to search within.
24
+ * @param expected The values that must be present in `actual`.
25
+ * @param msg Optional message to display on failure.
26
+ * @throws {AssertionError} If any value in `expected` is not found in `actual`.
27
+ */
28
+ export declare function assertArrayIncludes<T>(actual: ArrayLikeArg<T>, expected: ArrayLikeArg<T>, msg?: string): void;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Make an assertion, an error will be thrown if `expr` does not have a truthy value.
3
+ *
4
+ * @example Usage
5
+ * ```ts ignore
6
+ * import { assert } from "@std/assert";
7
+ *
8
+ * assert("hello".includes("ello")); // Doesn't throw
9
+ * assert("hello".includes("world")); // Throws
10
+ * ```
11
+ *
12
+ * @param expr The expression to test.
13
+ * @param msg The optional message to display if the assertion fails.
14
+ * @throws {AssertionError} If `expr` is falsy.
15
+ */
16
+ export declare function assert(expr: unknown, msg?: string): asserts expr;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Error thrown when an assertion fails.
3
+ *
4
+ * @example Usage
5
+ * ```ts ignore
6
+ * import { AssertionError } from "@std/assert";
7
+ *
8
+ * try {
9
+ * throw new AssertionError("foo", { cause: "bar" });
10
+ * } catch (error) {
11
+ * if (error instanceof AssertionError) {
12
+ * error.message === "foo"; // true
13
+ * error.cause === "bar"; // true
14
+ * }
15
+ * }
16
+ * ```
17
+ */
18
+ export declare class AssertionError extends Error {
19
+ /** Constructs a new instance.
20
+ *
21
+ * @param message The error message.
22
+ * @param options Additional options. This argument is still unstable. It may change in the future release.
23
+ */
24
+ constructor(message: string, options?: ErrorOptions);
25
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Deep equality comparison used in assertions.
3
+ *
4
+ * This function is based on value equality, but for some cases (such as data
5
+ * that can only be read asynchronously or function properties) value equality
6
+ * is not possible to determine. In such cases, reference equality is used
7
+ * instead, which may cause false negatives for objects such as `Blob`s or
8
+ * `Request`s.
9
+ *
10
+ * @param a The actual value
11
+ * @param b The expected value
12
+ * @returns `true` if the values are deeply equal, `false` otherwise
13
+ *
14
+ * @throws {TypeError} If either value is a `WeakMap` or `WeakSet`.
15
+ *
16
+ * @example Usage
17
+ * ```ts
18
+ * import { equal } from "@std/assert/equal";
19
+ *
20
+ * equal({ foo: "bar" }, { foo: "bar" }); // Returns `true`
21
+ * equal({ foo: "bar" }, { foo: "baz" }); // Returns `false`
22
+ * ```
23
+ */
24
+ export declare function equal(a: unknown, b: unknown): boolean;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are equal, deeply. If not
3
+ * deeply equal, then throw.
4
+ *
5
+ * Type parameter can be specified to ensure values under comparison have the
6
+ * same type.
7
+ *
8
+ * Note: This function is based on value equality, but for some cases (such as
9
+ * data that can only be read asynchronously or function properties) value
10
+ * equality is not possible to determine. In such cases, reference equality is
11
+ * used instead, which may cause false negatives for objects such as `Blob`s or
12
+ * `Request`s.
13
+ *
14
+ * @example Usage
15
+ * ```ts ignore
16
+ * import { assertEquals } from "@std/assert";
17
+ *
18
+ * assertEquals("world", "world"); // Doesn't throw
19
+ * assertEquals("hello", "world"); // Throws
20
+ * ```
21
+ * @example Compare `Blob` objects
22
+ * ```ts ignore
23
+ * import { assertEquals } from "@std/assert";
24
+ *
25
+ * const bytes1 = await new Blob(["foo"]).bytes();
26
+ * const bytes2 = await new Blob(["foo"]).bytes();
27
+ *
28
+ * assertEquals(bytes1, bytes2);
29
+ * ```
30
+ *
31
+ * @typeParam T The type of the values to compare. This is usually inferred.
32
+ * @param actual The actual value to compare.
33
+ * @param expected The expected value to compare.
34
+ * @param msg The optional message to display if the assertion fails.
35
+ */
36
+ export declare function assertEquals<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Make an assertion that actual is not null or undefined.
3
+ * If not then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertExists } from "@std/assert";
8
+ *
9
+ * assertExists("something"); // Doesn't throw
10
+ * assertExists(undefined); // Throws
11
+ * ```
12
+ *
13
+ * @typeParam T The type of the actual value.
14
+ * @param actual The actual value to check.
15
+ * @param msg The optional message to include in the error if the assertion fails.
16
+ */
17
+ export declare function assertExists<T>(actual: T, msg?: string): asserts actual is NonNullable<T>;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Forcefully throws a failed assertion.
3
+ *
4
+ * @example Usage
5
+ * ```ts ignore
6
+ * import { fail } from "@std/assert";
7
+ *
8
+ * fail("Deliberately failed!"); // Throws
9
+ * ```
10
+ *
11
+ * @param msg Optional message to include in the error.
12
+ * @returns Never returns, always throws.
13
+ */
14
+ export declare function fail(msg?: string): never;
@@ -0,0 +1,18 @@
1
+ /** Assertion condition for {@linkcode assertFalse}. */
2
+ export type Falsy = false | 0 | 0n | "" | null | undefined;
3
+ /**
4
+ * Make an assertion, an error will be thrown if `expr` has a truthy value.
5
+ *
6
+ * @example Usage
7
+ * ```ts ignore
8
+ * import { assertFalse } from "@std/assert";
9
+ *
10
+ * assertFalse(false); // Doesn't throw
11
+ * assertFalse(true); // Throws
12
+ * ```
13
+ *
14
+ * @param expr The expression to test.
15
+ * @param msg The optional message to display if the assertion fails.
16
+ * @throws {AssertionError} If `expr` is truthy.
17
+ */
18
+ export declare function assertFalse(expr: unknown, msg?: string): asserts expr is Falsy;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Make an assertion that `actual` is greater than `expected`.
3
+ * If not then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertGreater } from "@std/assert";
8
+ *
9
+ * assertGreater(2, 1); // Doesn't throw
10
+ * assertGreater(1, 1); // Throws
11
+ * assertGreater(0, 1); // Throws
12
+ * ```
13
+ *
14
+ * @typeParam T The type of the values to compare.
15
+ * @param actual The actual value to compare.
16
+ * @param expected The expected value to compare.
17
+ * @param msg The optional message to display if the assertion fails.
18
+ */
19
+ export declare function assertGreater<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Make an assertion that `actual` is greater than or equal to `expected`.
3
+ * If not then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertGreaterOrEqual } from "@std/assert";
8
+ *
9
+ * assertGreaterOrEqual(2, 1); // Doesn't throw
10
+ * assertGreaterOrEqual(1, 1); // Doesn't throw
11
+ * assertGreaterOrEqual(0, 1); // Throws
12
+ * ```
13
+ *
14
+ * @typeParam T The type of the values to compare.
15
+ * @param actual The actual value to compare.
16
+ * @param expected The expected value to compare.
17
+ * @param msg The optional message to display if the assertion fails.
18
+ */
19
+ export declare function assertGreaterOrEqual<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,22 @@
1
+ /** Any constructor */
2
+ export type AnyConstructor = new (...args: any[]) => any;
3
+ /** Gets constructor type */
4
+ export type GetConstructorType<T extends AnyConstructor> = InstanceType<T>;
5
+ /**
6
+ * Make an assertion that `obj` is an instance of `type`.
7
+ * If not then throw.
8
+ *
9
+ * @example Usage
10
+ * ```ts ignore
11
+ * import { assertInstanceOf } from "@std/assert";
12
+ *
13
+ * assertInstanceOf(new Date(), Date); // Doesn't throw
14
+ * assertInstanceOf(new Date(), Number); // Throws
15
+ * ```
16
+ *
17
+ * @typeParam T The expected type of the object.
18
+ * @param actual The object to check.
19
+ * @param expectedType The expected class constructor.
20
+ * @param msg The optional message to display if the assertion fails.
21
+ */
22
+ export declare function assertInstanceOf<T extends abstract new (...args: any[]) => any>(actual: unknown, expectedType: T, msg?: string): asserts actual is InstanceType<T>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Make an assertion that `error` is an `Error`.
3
+ * If not then an error will be thrown.
4
+ * An error class and a string that should be included in the
5
+ * error message can also be asserted.
6
+ *
7
+ * @example Usage
8
+ * ```ts ignore
9
+ * import { assertIsError } from "@std/assert";
10
+ *
11
+ * assertIsError(null); // Throws
12
+ * assertIsError(new RangeError("Out of range")); // Doesn't throw
13
+ * assertIsError(new RangeError("Out of range"), SyntaxError); // Throws
14
+ * assertIsError(new RangeError("Out of range"), SyntaxError, "Out of range"); // Doesn't throw
15
+ * assertIsError(new RangeError("Out of range"), SyntaxError, "Within range"); // Throws
16
+ * ```
17
+ *
18
+ * @typeParam E The type of the error to assert.
19
+ * @param error The error to assert.
20
+ * @param ErrorClass The optional error class to assert.
21
+ * @param msgMatches The optional string or RegExp to assert in the error message.
22
+ * @param msg The optional message to display if the assertion fails.
23
+ */
24
+ export declare function assertIsError<E extends Error = Error>(error: unknown, ErrorClass?: abstract new (...args: any[]) => E, msgMatches?: string | RegExp, msg?: string): asserts error is E;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Make an assertion that `actual` is less than `expected`.
3
+ * If not then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertLess } from "@std/assert";
8
+ *
9
+ * assertLess(1, 2); // Doesn't throw
10
+ * assertLess(2, 1); // Throws
11
+ * ```
12
+ *
13
+ * @typeParam T The type of the values to compare.
14
+ * @param actual The actual value to compare.
15
+ * @param expected The expected value to compare.
16
+ * @param msg The optional message to display if the assertion fails.
17
+ */
18
+ export declare function assertLess<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Make an assertion that `actual` is less than or equal to `expected`.
3
+ * If not then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertLessOrEqual } from "@std/assert";
8
+ *
9
+ * assertLessOrEqual(1, 2); // Doesn't throw
10
+ * assertLessOrEqual(1, 1); // Doesn't throw
11
+ * assertLessOrEqual(1, 0); // Throws
12
+ * ```
13
+ *
14
+ * @typeParam T The type of the values to compare.
15
+ * @param actual The actual value to compare.
16
+ * @param expected The expected value to compare.
17
+ * @param msg The optional message to display if the assertion fails.
18
+ */
19
+ export declare function assertLessOrEqual<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Make an assertion that `actual` match RegExp `expected`. If not
3
+ * then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertMatch } from "@std/assert";
8
+ *
9
+ * assertMatch("Raptor", /Raptor/); // Doesn't throw
10
+ * assertMatch("Denosaurus", /Raptor/); // Throws
11
+ * ```
12
+ *
13
+ * @param actual The actual value to be matched.
14
+ * @param expected The expected pattern to match.
15
+ * @param msg The optional message to display if the assertion fails.
16
+ */
17
+ export declare function assertMatch(actual: string, expected: RegExp, msg?: string): void;
@@ -0,0 +1,43 @@
1
+ /** A library of assertion functions.
2
+ * If the assertion is false an `AssertionError` will be thrown which will
3
+ * result in pretty-printed diff of the failing assertion.
4
+ *
5
+ * This module is browser compatible, but do not rely on good formatting of
6
+ * values for AssertionError messages in browsers.
7
+ *
8
+ * ```ts ignore
9
+ * import { assert } from "@std/assert";
10
+ *
11
+ * assert("I am truthy"); // Doesn't throw
12
+ * assert(false); // Throws `AssertionError`
13
+ * ```
14
+ *
15
+ * @module
16
+ */
17
+ export * from "./almost_equals.js";
18
+ export * from "./array_includes.js";
19
+ export * from "./equals.js";
20
+ export * from "./exists.js";
21
+ export * from "./false.js";
22
+ export * from "./greater_or_equal.js";
23
+ export * from "./greater.js";
24
+ export * from "./instance_of.js";
25
+ export * from "./is_error.js";
26
+ export * from "./less_or_equal.js";
27
+ export * from "./less.js";
28
+ export * from "./match.js";
29
+ export * from "./not_equals.js";
30
+ export * from "./not_instance_of.js";
31
+ export * from "./not_match.js";
32
+ export * from "./not_strict_equals.js";
33
+ export * from "./object_match.js";
34
+ export * from "./rejects.js";
35
+ export * from "./strict_equals.js";
36
+ export * from "./string_includes.js";
37
+ export * from "./throws.js";
38
+ export * from "./assert.js";
39
+ export * from "./assertion_error.js";
40
+ export * from "./equal.js";
41
+ export * from "./fail.js";
42
+ export * from "./unimplemented.js";
43
+ export * from "./unreachable.js";
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are not equal, deeply.
3
+ * If not then throw.
4
+ *
5
+ * Type parameter can be specified to ensure values under comparison have the same type.
6
+ *
7
+ * Note: This function is based on value equality, but for some cases (such as
8
+ * data that can only be read asynchronously or function properties) value
9
+ * equality is not possible to determine. In such cases, reference equality is
10
+ * used instead, which may cause false negatives for objects such as `Blob`s or
11
+ * `Request`s.
12
+ *
13
+ * @example Usage
14
+ * ```ts ignore
15
+ * import { assertNotEquals } from "@std/assert";
16
+ *
17
+ * assertNotEquals(1, 2); // Doesn't throw
18
+ * assertNotEquals(1, 1); // Throws
19
+ * ```
20
+ *
21
+ * @typeParam T The type of the values to compare.
22
+ * @param actual The actual value to compare.
23
+ * @param expected The expected value to compare.
24
+ * @param msg The optional message to display if the assertion fails.
25
+ */
26
+ export declare function assertNotEquals<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Make an assertion that `obj` is not an instance of `type`.
3
+ * If so, then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertNotInstanceOf } from "@std/assert";
8
+ *
9
+ * assertNotInstanceOf(new Date(), Number); // Doesn't throw
10
+ * assertNotInstanceOf(new Date(), Date); // Throws
11
+ * ```
12
+ *
13
+ * @typeParam A The type of the object to check.
14
+ * @typeParam T The type of the class to check against.
15
+ * @param actual The object to check.
16
+ * @param unexpectedType The class constructor to check against.
17
+ * @param msg The optional message to display if the assertion fails.
18
+ */
19
+ export declare function assertNotInstanceOf<A, T>(actual: A, unexpectedType: abstract new (...args: any[]) => T, msg?: string): asserts actual is Exclude<A, T>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Make an assertion that `actual` not match RegExp `expected`. If match
3
+ * then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertNotMatch } from "@std/assert";
8
+ *
9
+ * assertNotMatch("Denosaurus", /Raptor/); // Doesn't throw
10
+ * assertNotMatch("Raptor", /Raptor/); // Throws
11
+ * ```
12
+ *
13
+ * @param actual The actual value to match.
14
+ * @param expected The expected value to not match.
15
+ * @param msg The optional message to display if the assertion fails.
16
+ */
17
+ export declare function assertNotMatch(actual: string, expected: RegExp, msg?: string): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are not strictly equal, using
3
+ * {@linkcode Object.is} for equality comparison. If the values are strictly
4
+ * equal then throw.
5
+ *
6
+ * @example Usage
7
+ * ```ts ignore
8
+ * import { assertNotStrictEquals } from "@std/assert";
9
+ *
10
+ * assertNotStrictEquals(1, 1); // Throws
11
+ * assertNotStrictEquals(1, 2); // Doesn't throw
12
+ *
13
+ * assertNotStrictEquals(0, 0); // Throws
14
+ * assertNotStrictEquals(0, -0); // Doesn't throw
15
+ * ```
16
+ *
17
+ * @typeParam T The type of the values to compare.
18
+ * @param actual The actual value to compare.
19
+ * @param expected The expected value to compare.
20
+ * @param msg The optional message to display if the assertion fails.
21
+ */
22
+ export declare function assertNotStrictEquals<T>(actual: T, expected: T, msg?: string): void;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Make an assertion that `expected` object is a subset of `actual` object,
3
+ * deeply. If not, then throw a diff of the objects, with mismatching
4
+ * properties highlighted.
5
+ *
6
+ * @example Usage
7
+ * ```ts ignore
8
+ * import { assertObjectMatch } from "@std/assert";
9
+ *
10
+ * assertObjectMatch({ foo: "bar" }, { foo: "bar" }); // Doesn't throw
11
+ * assertObjectMatch({ foo: "bar" }, { foo: "baz" }); // Throws
12
+ * assertObjectMatch({ foo: 1, bar: 2 }, { foo: 1 }); // Doesn't throw
13
+ * assertObjectMatch({ foo: 1 }, { foo: 1, bar: 2 }); // Throws
14
+ * ```
15
+ *
16
+ * @example Usage with nested objects
17
+ * ```ts ignore
18
+ * import { assertObjectMatch } from "@std/assert";
19
+ *
20
+ * assertObjectMatch({ foo: { bar: 3, baz: 4 } }, { foo: { bar: 3 } }); // Doesn't throw
21
+ * assertObjectMatch({ foo: { bar: 3 } }, { foo: { bar: 3, baz: 4 } }); // Throws
22
+ * ```
23
+ *
24
+ * @param actual The actual value to be matched.
25
+ * @param expected The expected value to match.
26
+ * @param msg The optional message to display if the assertion fails.
27
+ */
28
+ export declare function assertObjectMatch(actual: Record<PropertyKey, any>, expected: Record<PropertyKey, unknown>, msg?: string): void;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Executes a function which returns a promise, expecting it to reject.
3
+ *
4
+ * To assert that a synchronous function throws, use {@linkcode assertThrows}.
5
+ *
6
+ * @example Usage
7
+ * ```ts ignore
8
+ * import { assertRejects } from "@std/assert";
9
+ *
10
+ * await assertRejects(async () => Promise.reject(new Error())); // Doesn't throw
11
+ * await assertRejects(async () => console.log("Hello world")); // Throws
12
+ * ```
13
+ *
14
+ * @param fn The function to execute.
15
+ * @param msg The optional message to display if the assertion fails.
16
+ * @returns The promise which resolves to the thrown error.
17
+ */
18
+ export declare function assertRejects(fn: () => PromiseLike<unknown>, msg?: string): Promise<unknown>;
19
+ /**
20
+ * Executes a function which returns a promise, expecting it to reject.
21
+ * If it does not, then it throws. An error class and a string that should be
22
+ * included in the error message can also be asserted.
23
+ *
24
+ * To assert that a synchronous function throws, use {@linkcode assertThrows}.
25
+ *
26
+ * @example Usage
27
+ * ```ts ignore
28
+ * import { assertRejects } from "@std/assert";
29
+ *
30
+ * await assertRejects(async () => Promise.reject(new Error()), Error); // Doesn't throw
31
+ * await assertRejects(async () => Promise.reject(new Error()), SyntaxError); // Throws
32
+ * ```
33
+ *
34
+ * @typeParam E The error class to assert.
35
+ * @param fn The function to execute.
36
+ * @param ErrorClass The error class to assert.
37
+ * @param msgIncludes The string that should be included in the error message.
38
+ * @param msg The optional message to display if the assertion fails.
39
+ * @returns The promise which resolves to the thrown error.
40
+ */
41
+ export declare function assertRejects<E extends Error = Error>(fn: () => PromiseLike<unknown>, ErrorClass: abstract new (...args: any[]) => E, msgIncludes?: string, msg?: string): Promise<E>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Make an assertion that `actual` and `expected` are strictly equal, using
3
+ * {@linkcode Object.is} for equality comparison. If not, then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertStrictEquals } from "@std/assert";
8
+ *
9
+ * const a = {};
10
+ * const b = a;
11
+ * assertStrictEquals(a, b); // Doesn't throw
12
+ *
13
+ * const c = {};
14
+ * const d = {};
15
+ * assertStrictEquals(c, d); // Throws
16
+ * ```
17
+ *
18
+ * @typeParam T The type of the expected value.
19
+ * @param actual The actual value to compare.
20
+ * @param expected The expected value to compare.
21
+ * @param msg The optional message to display if the assertion fails.
22
+ */
23
+ export declare function assertStrictEquals<T>(actual: unknown, expected: T, msg?: string): asserts actual is T;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Make an assertion that actual includes expected. If not
3
+ * then throw.
4
+ *
5
+ * @example Usage
6
+ * ```ts ignore
7
+ * import { assertStringIncludes } from "@std/assert";
8
+ *
9
+ * assertStringIncludes("Hello", "ello"); // Doesn't throw
10
+ * assertStringIncludes("Hello", "world"); // Throws
11
+ * ```
12
+ *
13
+ * @param actual The actual string to check for inclusion.
14
+ * @param expected The expected string to check for inclusion.
15
+ * @param msg The optional message to display if the assertion fails.
16
+ */
17
+ export declare function assertStringIncludes(actual: string, expected: string, msg?: string): void;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Executes a function, expecting it to throw. If it does not, then it
3
+ * throws.
4
+ *
5
+ * To assert that an asynchronous function rejects, use
6
+ * {@linkcode assertRejects}.
7
+ *
8
+ * @example Usage
9
+ * ```ts ignore
10
+ * import { assertThrows } from "@std/assert";
11
+ *
12
+ * assertThrows(() => { throw new TypeError("hello world!"); }); // Doesn't throw
13
+ * assertThrows(() => console.log("hello world!")); // Throws
14
+ * ```
15
+ *
16
+ * @param fn The function to execute.
17
+ * @param msg The optional message to display if the assertion fails.
18
+ * @returns The error that was thrown.
19
+ */
20
+ export declare function assertThrows(fn: () => unknown, msg?: string): unknown;
21
+ /**
22
+ * Executes a function, expecting it to throw. If it does not, then it
23
+ * throws. An error class and a string that should be included in the
24
+ * error message can also be asserted.
25
+ *
26
+ * To assert that an asynchronous function rejects, use
27
+ * {@linkcode assertRejects}.
28
+ *
29
+ * @example Usage
30
+ * ```ts ignore
31
+ * import { assertThrows } from "@std/assert";
32
+ *
33
+ * assertThrows(() => { throw new TypeError("hello world!"); }, TypeError); // Doesn't throw
34
+ * assertThrows(() => { throw new TypeError("hello world!"); }, RangeError); // Throws
35
+ * ```
36
+ *
37
+ * @typeParam E The error class to assert.
38
+ * @param fn The function to execute.
39
+ * @param ErrorClass The error class to assert.
40
+ * @param msgIncludes The string that should be included in the error message.
41
+ * @param msg The optional message to display if the assertion fails.
42
+ * @returns The error that was thrown.
43
+ */
44
+ export declare function assertThrows<E extends Error = Error>(fn: () => unknown, ErrorClass: abstract new (...args: any[]) => E, msgIncludes?: string, msg?: string): E;