From 926db017d99d076110aeb70fe4fc6df56f58d09c Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 15 Apr 2020 15:12:42 +0100 Subject: Remove std/testing/format.ts (#4749) --- std/testing/asserts.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'std/testing/asserts.ts') diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts index b44b20a94..21d699e5c 100644 --- a/std/testing/asserts.ts +++ b/std/testing/asserts.ts @@ -1,7 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { red, green, white, gray, bold } from "../fmt/colors.ts"; import diff, { DiffType, DiffResult } from "./diff.ts"; -import { format } from "./format.ts"; const CAN_NOT_DISPLAY = "[Cannot display]"; @@ -17,12 +16,12 @@ export class AssertionError extends Error { } } -function createStr(v: unknown): string { - try { - return format(v); - } catch (e) { - return red(CAN_NOT_DISPLAY); +function format(v: unknown): string { + let string = Deno.inspect(v); + if (typeof v == "string") { + string = `"${string.replace(/(?=["\\])/g, "\\")}"`; } + return string; } function createColor(diffType: DiffType): (s: string) => string { @@ -150,8 +149,8 @@ export function assertEquals( return; } let message = ""; - const actualString = createStr(actual); - const expectedString = createStr(expected); + const actualString = format(actual); + const expectedString = format(expected); try { const diffResult = diff( actualString.split("\n"), -- cgit v1.2.3