From bbb5d0fc0115178c5efba01cf700c6d729f5b4a6 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 30 Sep 2020 03:59:50 +0100 Subject: [PATCH] feat(cli/console): Add Deno.InspectOptions::colors (denoland/deno#7742) Ref: https://github.com/denoland/deno/pull/7516#pullrequestreview-489567120 --- fmt/printf_test.ts | 23 +++++++---------------- testing/asserts.ts | 4 ++-- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/fmt/printf_test.ts b/fmt/printf_test.ts index 81e172f81d32..e4399812b1ed 100644 --- a/fmt/printf_test.ts +++ b/fmt/printf_test.ts @@ -7,7 +7,6 @@ import { sprintf } from "./printf.ts"; import { assertEquals } from "../testing/asserts.ts"; -import { cyan, yellow } from "./colors.ts"; const S = sprintf; @@ -607,12 +606,12 @@ Deno.test("testWeirdos", function (): void { Deno.test("formatV", function (): void { const a = { a: { a: { a: { a: { a: { a: { a: {} } } } } } } }; assertEquals(S("%v", a), "[object Object]"); - assertEquals(S("%#v", a), `{ a: { a: { a: { a: ${cyan("[Object]")} } } } }`); + assertEquals(S("%#v", a), `{ a: { a: { a: { a: [Object] } } } }`); assertEquals( S("%#.8v", a), "{ a: { a: { a: { a: { a: { a: { a: {} } } } } } } }", ); - assertEquals(S("%#.1v", a), `{ a: ${cyan("[Object]")} }`); + assertEquals(S("%#.1v", a), `{ a: [Object] }`); }); Deno.test("formatJ", function (): void { @@ -625,9 +624,7 @@ Deno.test("flagLessThan", function (): void { const aArray = [a, a, a]; assertEquals( S("%<#.1v", aArray), - `[ { a: ${cyan("[Object]")} }, { a: ${cyan("[Object]")} }, { a: ${ - cyan("[Object]") - } } ]`, + `[ { a: [Object] }, { a: [Object] }, { a: [Object] } ]`, ); const fArray = [1.2345, 0.98765, 123456789.5678]; assertEquals(S("%<.2f", fArray), "[ 1.23, 0.99, 123456789.57 ]"); @@ -649,27 +646,21 @@ Deno.test("testErrors", function (): void { assertEquals(S("%.*f", "a", 1.1), "%!(BAD PREC 'a')"); assertEquals( S("%.[2]*f", 1.23, "p"), - `%!(BAD PREC 'p')%!(EXTRA '${yellow("1.23")}')`, + `%!(BAD PREC 'p')%!(EXTRA '1.23')`, ); assertEquals(S("%.[2]*[1]f Yippie!", 1.23, "p"), "%!(BAD PREC 'p') Yippie!"); assertEquals(S("%[1]*.2f", "a", "p"), "%!(BAD WIDTH 'a')"); - assertEquals( - S("A", "a", "p"), - `A%!(EXTRA '\x1b[32m"a"\x1b[39m' '\x1b[32m"p"\x1b[39m')`, - ); - assertEquals( - S("%[2]s %[2]s", "a", "p"), - `p p%!(EXTRA '\x1b[32m"a"\x1b[39m')`, - ); + assertEquals(S("A", "a", "p"), `A%!(EXTRA '"a"' '"p"')`); + assertEquals(S("%[2]s %[2]s", "a", "p"), `p p%!(EXTRA '"a"')`); // remains to be determined how to handle bad indices ... // (realistically) the entire error handling is still up for grabs. assertEquals(S("%[hallo]s %d %d %d", 1, 2, 3, 4), "%!(BAD INDEX) 2 3 4"); assertEquals( S("%[5]s", 1, 2, 3, 4), - `%!(BAD INDEX)%!(EXTRA '${yellow("2")}' '${yellow("3")}' '${yellow("4")}')`, + `%!(BAD INDEX)%!(EXTRA '2' '3' '4')`, ); assertEquals(S("%[5]f"), "%!(BAD INDEX)"); assertEquals(S("%.[5]f"), "%!(BAD INDEX)"); diff --git a/testing/asserts.ts b/testing/asserts.ts index 05bb995ab320..889a622fd923 100644 --- a/testing/asserts.ts +++ b/testing/asserts.ts @@ -21,13 +21,13 @@ export class AssertionError extends Error { export function _format(v: unknown): string { return globalThis.Deno - ? stripColor(Deno.inspect(v, { + ? Deno.inspect(v, { depth: Infinity, sorted: true, trailingComma: true, compact: false, iterableLimit: Infinity, - })) + }) : `"${String(v).replace(/(?=["\\])/g, "\\")}"`; }