mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
feat(ext/console): Compact empty iterables when calling Deno.inspect with compact false (#14387)
This commit is contained in:
parent
e24b8f075e
commit
dc4ab1d934
2 changed files with 75 additions and 4 deletions
|
@ -1939,6 +1939,71 @@ Deno.test(function inspectColors() {
|
||||||
assertStringIncludes(Deno.inspect(1, { colors: true }), "\x1b[");
|
assertStringIncludes(Deno.inspect(1, { colors: true }), "\x1b[");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test(function inspectEmptyArray() {
|
||||||
|
const arr: string[] = [];
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
Deno.inspect(arr, {
|
||||||
|
compact: false,
|
||||||
|
trailingComma: true,
|
||||||
|
}),
|
||||||
|
"[\n]",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test(function inspectDeepEmptyArray() {
|
||||||
|
const obj = {
|
||||||
|
arr: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
Deno.inspect(obj, {
|
||||||
|
compact: false,
|
||||||
|
trailingComma: true,
|
||||||
|
}),
|
||||||
|
`{
|
||||||
|
arr: [
|
||||||
|
],
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test(function inspectEmptyMap() {
|
||||||
|
const map = new Map();
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
Deno.inspect(map, {
|
||||||
|
compact: false,
|
||||||
|
trailingComma: true,
|
||||||
|
}),
|
||||||
|
"Map {\n}",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test(function inspectEmptyMap() {
|
||||||
|
const set = new Set();
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
Deno.inspect(set, {
|
||||||
|
compact: false,
|
||||||
|
trailingComma: true,
|
||||||
|
}),
|
||||||
|
"Set {\n}",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test(function inspectEmptyMap() {
|
||||||
|
const typedArray = new Uint8Array(0);
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
Deno.inspect(typedArray, {
|
||||||
|
compact: false,
|
||||||
|
trailingComma: true,
|
||||||
|
}),
|
||||||
|
"Uint8Array(0) [\n]",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test(function inspectStringAbbreviation() {
|
Deno.test(function inspectStringAbbreviation() {
|
||||||
const LONG_STRING =
|
const LONG_STRING =
|
||||||
"This is a really long string which will be abbreviated with ellipsis.";
|
"This is a really long string which will be abbreviated with ellipsis.";
|
||||||
|
|
|
@ -465,12 +465,18 @@
|
||||||
const entryIndentation = `,\n${
|
const entryIndentation = `,\n${
|
||||||
StringPrototypeRepeat(DEFAULT_INDENT, level + 1)
|
StringPrototypeRepeat(DEFAULT_INDENT, level + 1)
|
||||||
}`;
|
}`;
|
||||||
const closingIndentation = `${inspectOptions.trailingComma ? "," : ""}\n${
|
const closingDelimIndentation = StringPrototypeRepeat(
|
||||||
StringPrototypeRepeat(DEFAULT_INDENT, level)
|
DEFAULT_INDENT,
|
||||||
}`;
|
level,
|
||||||
|
);
|
||||||
|
const closingIndentation = `${
|
||||||
|
inspectOptions.trailingComma ? "," : ""
|
||||||
|
}\n${closingDelimIndentation}`;
|
||||||
|
|
||||||
let iContent;
|
let iContent;
|
||||||
if (options.group && entries.length > MIN_GROUP_LENGTH) {
|
if (entries.length === 0 && !inspectOptions.compact) {
|
||||||
|
iContent = `\n${closingDelimIndentation}`;
|
||||||
|
} else if (options.group && entries.length > MIN_GROUP_LENGTH) {
|
||||||
const groups = groupEntries(entries, level, value);
|
const groups = groupEntries(entries, level, value);
|
||||||
iContent = `${initIndentation}${
|
iContent = `${initIndentation}${
|
||||||
ArrayPrototypeJoin(groups, entryIndentation)
|
ArrayPrototypeJoin(groups, entryIndentation)
|
||||||
|
|
Loading…
Add table
Reference in a new issue