formacao
This commit is contained in:
+41
-28
@@ -2,7 +2,6 @@ import { plugins, format } from '@vitest/pretty-format';
|
||||
import c from 'tinyrainbow';
|
||||
import { stringify } from './display.js';
|
||||
import { deepClone, getOwnProperties, getType as getType$1 } from './helpers.js';
|
||||
import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js';
|
||||
import './constants.js';
|
||||
|
||||
/**
|
||||
@@ -333,7 +332,6 @@ function diff_cleanupSemanticLossless(diffs) {
|
||||
* @param {!Array.<!diff_match_patch.Diff>} diffs Array of diff tuples.
|
||||
*/
|
||||
function diff_cleanupMerge(diffs) {
|
||||
var _diffs$at;
|
||||
// Add a dummy entry at the end.
|
||||
diffs.push(new Diff(DIFF_EQUAL, ""));
|
||||
let pointer = 0;
|
||||
@@ -404,7 +402,7 @@ function diff_cleanupMerge(diffs) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (((_diffs$at = diffs.at(-1)) === null || _diffs$at === void 0 ? void 0 : _diffs$at[1]) === "") {
|
||||
if (diffs.at(-1)?.[1] === "") {
|
||||
diffs.pop();
|
||||
}
|
||||
// Second pass: look for single edits surrounded on both sides by equalities
|
||||
@@ -495,6 +493,10 @@ function diff_cleanupSemanticScore_(one, two) {
|
||||
const NO_DIFF_MESSAGE = "Compared values have no visual difference.";
|
||||
const SIMILAR_MESSAGE = "Compared values serialize to the same structure.\n" + "Printing internal object structure without calling `toJSON` instead.";
|
||||
|
||||
function getDefaultExportFromCjs(x) {
|
||||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
||||
}
|
||||
|
||||
var build = {};
|
||||
|
||||
var hasRequiredBuild;
|
||||
@@ -1623,8 +1625,8 @@ function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCo
|
||||
}
|
||||
// Compare two arrays of strings line-by-line.
|
||||
function diffLinesRaw(aLines, bLines, options) {
|
||||
const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
|
||||
const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
|
||||
const truncate = options?.truncateThreshold ?? false;
|
||||
const truncateThreshold = Math.max(Math.floor(options?.truncateThreshold ?? 0), 0);
|
||||
const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
|
||||
const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
|
||||
const truncated = aLength !== aLines.length || bLength !== bLines.length;
|
||||
@@ -1697,8 +1699,8 @@ function getNewLineSymbol(string) {
|
||||
return string.includes("\r\n") ? "\r\n" : "\n";
|
||||
}
|
||||
function diffStrings(a, b, options) {
|
||||
const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
|
||||
const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
|
||||
const truncate = options?.truncateThreshold ?? false;
|
||||
const truncateThreshold = Math.max(Math.floor(options?.truncateThreshold ?? 0), 0);
|
||||
let aLength = a.length;
|
||||
let bLength = b.length;
|
||||
if (truncate) {
|
||||
@@ -1966,6 +1968,7 @@ const FALLBACK_FORMAT_OPTIONS = {
|
||||
maxDepth: 8,
|
||||
plugins: PLUGINS
|
||||
};
|
||||
const DEFAULT_MEMORIZE = (_, v) => v;
|
||||
// Generate a string that will highlight the difference between two values
|
||||
// with green and red. (similar to how github does code diffing)
|
||||
/**
|
||||
@@ -1974,7 +1977,7 @@ const FALLBACK_FORMAT_OPTIONS = {
|
||||
* @param options Diff options
|
||||
* @returns {string | null} a string diff
|
||||
*/
|
||||
function diff(a, b, options) {
|
||||
function diff(a, b, options, memorize = DEFAULT_MEMORIZE) {
|
||||
if (Object.is(a, b)) {
|
||||
return "";
|
||||
}
|
||||
@@ -2008,10 +2011,10 @@ function diff(a, b, options) {
|
||||
function truncate(s) {
|
||||
return s.length <= MAX_LENGTH ? s : `${s.slice(0, MAX_LENGTH)}...`;
|
||||
}
|
||||
aDisplay = truncate(aDisplay);
|
||||
bDisplay = truncate(bDisplay);
|
||||
const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)} \n${aDisplay}`;
|
||||
const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)} \n${bDisplay}`;
|
||||
aDisplay = memorize("expected", truncate(aDisplay));
|
||||
bDisplay = memorize("actual", truncate(bDisplay));
|
||||
const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}\n${aDisplay}`;
|
||||
const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}\n${bDisplay}`;
|
||||
return `${aDiff}\n\n${bDiff}`;
|
||||
}
|
||||
if (omitDifference) {
|
||||
@@ -2020,15 +2023,21 @@ function diff(a, b, options) {
|
||||
switch (aType) {
|
||||
case "string": return diffLinesUnified(a.split("\n"), b.split("\n"), options);
|
||||
case "boolean":
|
||||
case "number": return comparePrimitive(a, b, options);
|
||||
case "map": return compareObjects(sortMap(a), sortMap(b), options);
|
||||
case "set": return compareObjects(sortSet(a), sortSet(b), options);
|
||||
default: return compareObjects(a, b, options);
|
||||
case "number": return comparePrimitive(a, b, options, memorize);
|
||||
case "map": return compareObjects(sortMap(a), sortMap(b), options, memorize);
|
||||
case "set": return compareObjects(sortSet(a), sortSet(b), options, memorize);
|
||||
default: return compareObjects(a, b, options, memorize);
|
||||
}
|
||||
}
|
||||
function comparePrimitive(a, b, options) {
|
||||
const aFormat = format(a, FORMAT_OPTIONS);
|
||||
const bFormat = format(b, FORMAT_OPTIONS);
|
||||
function createMemorize(memory) {
|
||||
return (pointer, stringifiedValue) => {
|
||||
memory[pointer] = stringifiedValue;
|
||||
return stringifiedValue;
|
||||
};
|
||||
}
|
||||
function comparePrimitive(a, b, options, memorize = DEFAULT_MEMORIZE) {
|
||||
const aFormat = memorize("expected", format(a, FORMAT_OPTIONS));
|
||||
const bFormat = memorize("actual", format(b, FORMAT_OPTIONS));
|
||||
return aFormat === bFormat ? "" : diffLinesUnified(aFormat.split("\n"), bFormat.split("\n"), options);
|
||||
}
|
||||
function sortMap(map) {
|
||||
@@ -2037,12 +2046,12 @@ function sortMap(map) {
|
||||
function sortSet(set) {
|
||||
return new Set(Array.from(set.values()).sort());
|
||||
}
|
||||
function compareObjects(a, b, options) {
|
||||
function compareObjects(a, b, options, memorize = DEFAULT_MEMORIZE) {
|
||||
let difference;
|
||||
let hasThrown = false;
|
||||
try {
|
||||
const formatOptions = getFormatOptions(FORMAT_OPTIONS, options);
|
||||
difference = getObjectsDifference(a, b, formatOptions, options);
|
||||
difference = getObjectsDifference(a, b, formatOptions, options, memorize);
|
||||
} catch {
|
||||
hasThrown = true;
|
||||
}
|
||||
@@ -2051,13 +2060,16 @@ function compareObjects(a, b, options) {
|
||||
// without calling `toJSON`. It's also possible that toJSON might throw.
|
||||
if (difference === undefined || difference === noDiffMessage) {
|
||||
const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
|
||||
difference = getObjectsDifference(a, b, formatOptions, options);
|
||||
difference = getObjectsDifference(a, b, formatOptions, options, memorize);
|
||||
if (difference !== noDiffMessage && !hasThrown) {
|
||||
difference = `${getCommonMessage(SIMILAR_MESSAGE, options)}\n\n${difference}`;
|
||||
}
|
||||
}
|
||||
return difference;
|
||||
}
|
||||
function getDefaultFormatOptions(options) {
|
||||
return getFormatOptions(FORMAT_OPTIONS, options);
|
||||
}
|
||||
function getFormatOptions(formatOptions, options) {
|
||||
const { compareKeys, printBasicPrototype, maxDepth } = normalizeDiffOptions(options);
|
||||
return {
|
||||
@@ -2067,7 +2079,7 @@ function getFormatOptions(formatOptions, options) {
|
||||
maxDepth: maxDepth ?? formatOptions.maxDepth
|
||||
};
|
||||
}
|
||||
function getObjectsDifference(a, b, formatOptions, options) {
|
||||
function getObjectsDifference(a, b, formatOptions, options, memorize = DEFAULT_MEMORIZE) {
|
||||
const formatOptionsZeroIndent = {
|
||||
...formatOptions,
|
||||
indent: 0
|
||||
@@ -2077,8 +2089,8 @@ function getObjectsDifference(a, b, formatOptions, options) {
|
||||
if (aCompare === bCompare) {
|
||||
return getCommonMessage(NO_DIFF_MESSAGE, options);
|
||||
} else {
|
||||
const aDisplay = format(a, formatOptions);
|
||||
const bDisplay = format(b, formatOptions);
|
||||
const aDisplay = memorize("expected", format(a, formatOptions));
|
||||
const bDisplay = memorize("actual", format(b, formatOptions));
|
||||
return diffLinesUnified2(aDisplay.split("\n"), bDisplay.split("\n"), aCompare.split("\n"), bCompare.split("\n"), options);
|
||||
}
|
||||
}
|
||||
@@ -2092,7 +2104,7 @@ function isReplaceable(obj1, obj2) {
|
||||
const obj2Type = getType$1(obj2);
|
||||
return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
|
||||
}
|
||||
function printDiffOrStringify(received, expected, options) {
|
||||
function printDiffOrStringify(received, expected, options, memory) {
|
||||
const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
|
||||
if (typeof expected === "string" && typeof received === "string" && expected.length > 0 && received.length > 0 && expected.length <= MAX_DIFF_STRING_LENGTH && received.length <= MAX_DIFF_STRING_LENGTH && expected !== received) {
|
||||
if (expected.includes("\n") || received.includes("\n")) {
|
||||
@@ -2109,7 +2121,8 @@ function printDiffOrStringify(received, expected, options) {
|
||||
const clonedExpected = deepClone(expected, { forceWritable: true });
|
||||
const clonedReceived = deepClone(received, { forceWritable: true });
|
||||
const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(clonedReceived, clonedExpected);
|
||||
const difference = diff(replacedExpected, replacedActual, options);
|
||||
const memorize = memory ? createMemorize(memory) : DEFAULT_MEMORIZE;
|
||||
const difference = diff(replacedExpected, replacedActual, options, memorize);
|
||||
return difference;
|
||||
// }
|
||||
// const printLabel = getLabelPrinter(aAnnotation, bAnnotation)
|
||||
@@ -2196,4 +2209,4 @@ function getCommonAndChangedSubstrings(diffs, op, hasCommonDiff) {
|
||||
return diffs.reduce((reduced, diff) => reduced + (diff[0] === DIFF_EQUAL ? diff[1] : diff[0] === op ? hasCommonDiff ? c.inverse(diff[1]) : diff[1] : ""), "");
|
||||
}
|
||||
|
||||
export { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff, diff, diffLinesRaw, diffLinesUnified, diffLinesUnified2, diffStringsRaw, diffStringsUnified, getLabelPrinter, printDiffOrStringify, replaceAsymmetricMatcher };
|
||||
export { DIFF_DELETE, DIFF_EQUAL, DIFF_INSERT, Diff, diff, diffLinesRaw, diffLinesUnified, diffLinesUnified2, diffStringsRaw, diffStringsUnified, getDefaultFormatOptions, getLabelPrinter, printDiffOrStringify, replaceAsymmetricMatcher };
|
||||
|
||||
Reference in New Issue
Block a user