feat(ext/console): Add string abbreviation size option for "Deno.inspect" (#14384)

This commit is contained in:
Ben Heidemann 2022-04-25 12:59:15 +01:00 committed by GitHub
parent 6dcf3a447c
commit ddbfa1418c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View file

@ -1938,3 +1938,22 @@ Deno.test(function inspectColors() {
assertEquals(Deno.inspect(1), "1");
assertStringIncludes(Deno.inspect(1, { colors: true }), "\x1b[");
});
Deno.test(function inspectStringAbbreviation() {
const LONG_STRING =
"This is a really long string which will be abbreviated with ellipsis.";
const obj = {
str: LONG_STRING,
};
const arr = [LONG_STRING];
assertEquals(
Deno.inspect(obj, { strAbbreviateSize: 10 }),
'{ str: "This is a ..." }',
);
assertEquals(
Deno.inspect(arr, { strAbbreviateSize: 10 }),
'[ "This is a ..." ]',
);
});