diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-04-15 15:12:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-15 10:12:42 -0400 |
commit | 926db017d99d076110aeb70fe4fc6df56f58d09c (patch) | |
tree | 076c71ec9b923632a4f7f5db60de1bfe070989f0 /std/testing/asserts.ts | |
parent | cb64cf3ce2ea46883fa8bc2b4242dfd07e4551e5 (diff) |
Remove std/testing/format.ts (#4749)
Diffstat (limited to 'std/testing/asserts.ts')
-rw-r--r-- | std/testing/asserts.ts | 15 |
1 files changed, 7 insertions, 8 deletions
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"), |