import { equal } from "./equal.ts";import { format } from "./_format.ts";import { AssertionError } from "./assertion_error.ts";
export function assertArrayIncludes<T>( actual: ArrayLike<T>, expected: ArrayLike<T>, 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);}