Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove std/testing/format.ts #4749

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions std/testing/asserts.ts
Original file line number Diff line number Diff line change
@@ -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]";

Expand All @@ -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 {
Expand Down Expand Up @@ -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"),
Expand Down
21 changes: 5 additions & 16 deletions std/testing/asserts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
unimplemented,
unreachable,
} from "./asserts.ts";
import { red, green, white, gray, bold } from "../fmt/colors.ts";
import { red, green, gray, bold } from "../fmt/colors.ts";
const { test } = Deno;

test(function testingEqual(): void {
Expand Down Expand Up @@ -302,12 +302,8 @@ test({
AssertionError,
[
...createHeader(),
white(" Array ["),
removed(`- 1,`),
added(`+ "1",`),
white(' "2",'),
white(" 3,"),
white(" ]"),
removed(`- [ 1, "2", 3 ]`),
added(`+ [ "1", "2", 3 ]`),
"",
].join("\n")
);
Expand All @@ -322,15 +318,8 @@ test({
AssertionError,
[
...createHeader(),
white(" Object {"),
white(` "a": 1,`),
added(`+ "b": 2,`),
added(`+ "c": Array [`),
added(`+ 3,`),
added(`+ ],`),
removed(`- "b": "2",`),
removed(`- "c": 3,`),
white(" }"),
removed(`- { a: 1, b: "2", c: 3 }`),
added(`+ { a: 1, b: 2, c: [ 3 ] }`),
"",
].join("\n")
);
Expand Down
Loading