2024-01-29 08:55:56 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
// This file is copied from `std/assert`.
|
|
|
|
|
2024-07-02 04:07:46 +00:00
|
|
|
import { AssertionError } from "@std/assert/assertion-error";
|
2024-02-06 07:41:42 +00:00
|
|
|
import { buildNotEqualErrorMessage } from "./_build_message.ts";
|
2024-01-29 08:55:56 +00:00
|
|
|
import { equal } from "./_equal.ts";
|
2024-02-27 21:57:25 +00:00
|
|
|
import type { EqualOptions } from "./_types.ts";
|
2024-01-29 08:55:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2024-09-19 23:29:31 +00:00
|
|
|
* ```ts ignore
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
* import { assertNotEquals } from "@std/assert";
|
2024-01-29 08:55:56 +00:00
|
|
|
*
|
|
|
|
* assertNotEquals(1, 2); // Doesn't throw
|
|
|
|
* assertNotEquals(1, 1); // Throws
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
export function assertNotEquals<T>(
|
|
|
|
actual: T,
|
|
|
|
expected: T,
|
refactor(archive,async,cli,csv,dotenv,encoding,expect,fmt,front-matter,fs,http,internal,log,net,path,semver,testing,text,webgpu,yaml): enable `"exactOptionalPropertyTypes"` option (#5892)
2024-09-04 05:15:01 +00:00
|
|
|
options: EqualOptions = {},
|
2024-01-29 08:55:56 +00:00
|
|
|
) {
|
2024-02-06 07:41:42 +00:00
|
|
|
if (!equal(actual, expected, options)) {
|
2024-01-29 08:55:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-02-06 07:41:42 +00:00
|
|
|
|
refactor(archive,async,cli,csv,dotenv,encoding,expect,fmt,front-matter,fs,http,internal,log,net,path,semver,testing,text,webgpu,yaml): enable `"exactOptionalPropertyTypes"` option (#5892)
2024-09-04 05:15:01 +00:00
|
|
|
const message = buildNotEqualErrorMessage(actual, expected, options);
|
2024-02-06 07:41:42 +00:00
|
|
|
throw new AssertionError(message);
|
2024-01-29 08:55:56 +00:00
|
|
|
}
|