@rstest/core 0.9.3 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +0 -228
- package/dist/0~8843.js +33 -17
- package/dist/0~browserLoader.js +1 -1
- package/dist/0~browser~1.js +4 -4
- package/dist/0~checkThresholds.js +1 -1
- package/dist/0~console.js +1 -1
- package/dist/0~fake-timers.js +1483 -0
- package/dist/0~generate.js +4 -3
- package/dist/0~happyDom.js +1 -1
- package/dist/0~jsdom.js +1 -1
- package/dist/0~listTests.js +14 -10
- package/dist/0~loadEsModule.js +3 -1
- package/dist/0~loadModule.js +1 -1
- package/dist/0~runTests.js +17 -6
- package/dist/0~snapshot.js +2140 -0
- package/dist/0~snapshot.js.LICENSE.txt +7 -0
- package/dist/0~utils.js +1 -1
- package/dist/1949.js +2919 -9808
- package/dist/1949.js.LICENSE.txt +1 -49
- package/dist/3145.js +363 -63
- package/dist/4411.js +232 -47
- package/dist/6830.js +61 -9
- package/dist/7552.js +22 -4918
- package/dist/7704.js +1 -2
- package/dist/9743.js +1982 -0
- package/dist/9784.js +1343 -0
- package/dist/{7552.js.LICENSE.txt → 9784.js.LICENSE.txt} +19 -8
- package/dist/browser-runtime/2~fake-timers.js +1653 -0
- package/dist/browser-runtime/2~snapshot.js +2138 -0
- package/dist/browser-runtime/2~snapshot.js.LICENSE.txt +7 -0
- package/dist/browser-runtime/723.js +2055 -10605
- package/dist/browser-runtime/723.js.LICENSE.txt +0 -17
- package/dist/browser-runtime/index.d.ts +189 -11
- package/dist/browser-runtime/rslib-runtime.js +0 -7
- package/dist/browser.d.ts +39 -5
- package/dist/browser.js +2 -2
- package/dist/globalSetupWorker.js +1 -1
- package/dist/index.d.ts +39 -5
- package/dist/mockRuntimeCode.js +2 -0
- package/dist/worker.d.ts +31 -5
- package/dist/worker.js +32 -11
- package/package.json +21 -22
package/dist/9743.js
ADDED
|
@@ -0,0 +1,1982 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
3
|
+
import { format as dist_format, dist_plugins, node_u } from "./9784.js";
|
|
4
|
+
var diff_namespaceObject = {};
|
|
5
|
+
__webpack_require__.r(diff_namespaceObject);
|
|
6
|
+
__webpack_require__.d(diff_namespaceObject, {
|
|
7
|
+
DIFF_DELETE: ()=>DIFF_DELETE,
|
|
8
|
+
DIFF_EQUAL: ()=>DIFF_EQUAL,
|
|
9
|
+
DIFF_INSERT: ()=>DIFF_INSERT,
|
|
10
|
+
Diff: ()=>Diff,
|
|
11
|
+
diff: ()=>diff_diff,
|
|
12
|
+
diffLinesRaw: ()=>diffLinesRaw,
|
|
13
|
+
diffLinesUnified: ()=>diffLinesUnified,
|
|
14
|
+
diffLinesUnified2: ()=>diffLinesUnified2,
|
|
15
|
+
diffStringsRaw: ()=>diffStringsRaw,
|
|
16
|
+
diffStringsUnified: ()=>diffStringsUnified,
|
|
17
|
+
getLabelPrinter: ()=>getLabelPrinter,
|
|
18
|
+
printDiffOrStringify: ()=>printDiffOrStringify,
|
|
19
|
+
replaceAsymmetricMatcher: ()=>replaceAsymmetricMatcher
|
|
20
|
+
});
|
|
21
|
+
const ansiColors = {
|
|
22
|
+
bold: [
|
|
23
|
+
'1',
|
|
24
|
+
'22'
|
|
25
|
+
],
|
|
26
|
+
dim: [
|
|
27
|
+
'2',
|
|
28
|
+
'22'
|
|
29
|
+
],
|
|
30
|
+
italic: [
|
|
31
|
+
'3',
|
|
32
|
+
'23'
|
|
33
|
+
],
|
|
34
|
+
underline: [
|
|
35
|
+
'4',
|
|
36
|
+
'24'
|
|
37
|
+
],
|
|
38
|
+
inverse: [
|
|
39
|
+
'7',
|
|
40
|
+
'27'
|
|
41
|
+
],
|
|
42
|
+
hidden: [
|
|
43
|
+
'8',
|
|
44
|
+
'28'
|
|
45
|
+
],
|
|
46
|
+
strike: [
|
|
47
|
+
'9',
|
|
48
|
+
'29'
|
|
49
|
+
],
|
|
50
|
+
black: [
|
|
51
|
+
'30',
|
|
52
|
+
'39'
|
|
53
|
+
],
|
|
54
|
+
red: [
|
|
55
|
+
'31',
|
|
56
|
+
'39'
|
|
57
|
+
],
|
|
58
|
+
green: [
|
|
59
|
+
'32',
|
|
60
|
+
'39'
|
|
61
|
+
],
|
|
62
|
+
yellow: [
|
|
63
|
+
'33',
|
|
64
|
+
'39'
|
|
65
|
+
],
|
|
66
|
+
blue: [
|
|
67
|
+
'34',
|
|
68
|
+
'39'
|
|
69
|
+
],
|
|
70
|
+
magenta: [
|
|
71
|
+
'35',
|
|
72
|
+
'39'
|
|
73
|
+
],
|
|
74
|
+
cyan: [
|
|
75
|
+
'36',
|
|
76
|
+
'39'
|
|
77
|
+
],
|
|
78
|
+
white: [
|
|
79
|
+
'37',
|
|
80
|
+
'39'
|
|
81
|
+
],
|
|
82
|
+
brightblack: [
|
|
83
|
+
'30;1',
|
|
84
|
+
'39'
|
|
85
|
+
],
|
|
86
|
+
brightred: [
|
|
87
|
+
'31;1',
|
|
88
|
+
'39'
|
|
89
|
+
],
|
|
90
|
+
brightgreen: [
|
|
91
|
+
'32;1',
|
|
92
|
+
'39'
|
|
93
|
+
],
|
|
94
|
+
brightyellow: [
|
|
95
|
+
'33;1',
|
|
96
|
+
'39'
|
|
97
|
+
],
|
|
98
|
+
brightblue: [
|
|
99
|
+
'34;1',
|
|
100
|
+
'39'
|
|
101
|
+
],
|
|
102
|
+
brightmagenta: [
|
|
103
|
+
'35;1',
|
|
104
|
+
'39'
|
|
105
|
+
],
|
|
106
|
+
brightcyan: [
|
|
107
|
+
'36;1',
|
|
108
|
+
'39'
|
|
109
|
+
],
|
|
110
|
+
brightwhite: [
|
|
111
|
+
'37;1',
|
|
112
|
+
'39'
|
|
113
|
+
],
|
|
114
|
+
grey: [
|
|
115
|
+
'90',
|
|
116
|
+
'39'
|
|
117
|
+
]
|
|
118
|
+
};
|
|
119
|
+
const styles = {
|
|
120
|
+
special: 'cyan',
|
|
121
|
+
number: 'yellow',
|
|
122
|
+
bigint: 'yellow',
|
|
123
|
+
boolean: 'yellow',
|
|
124
|
+
undefined: 'grey',
|
|
125
|
+
null: 'bold',
|
|
126
|
+
string: 'green',
|
|
127
|
+
symbol: 'green',
|
|
128
|
+
date: 'magenta',
|
|
129
|
+
regexp: 'red'
|
|
130
|
+
};
|
|
131
|
+
const truncator = '…';
|
|
132
|
+
function colorise(value, styleType) {
|
|
133
|
+
const color = ansiColors[styles[styleType]] || ansiColors[styleType] || '';
|
|
134
|
+
if (!color) return String(value);
|
|
135
|
+
return `\u001b[${color[0]}m${String(value)}\u001b[${color[1]}m`;
|
|
136
|
+
}
|
|
137
|
+
function normaliseOptions({ showHidden = false, depth = 2, colors = false, customInspect = true, showProxy = false, maxArrayLength = 1 / 0, breakLength = 1 / 0, seen = [], truncate = 1 / 0, stylize = String } = {}, inspect) {
|
|
138
|
+
const options = {
|
|
139
|
+
showHidden: Boolean(showHidden),
|
|
140
|
+
depth: Number(depth),
|
|
141
|
+
colors: Boolean(colors),
|
|
142
|
+
customInspect: Boolean(customInspect),
|
|
143
|
+
showProxy: Boolean(showProxy),
|
|
144
|
+
maxArrayLength: Number(maxArrayLength),
|
|
145
|
+
breakLength: Number(breakLength),
|
|
146
|
+
truncate: Number(truncate),
|
|
147
|
+
seen,
|
|
148
|
+
inspect,
|
|
149
|
+
stylize
|
|
150
|
+
};
|
|
151
|
+
if (options.colors) options.stylize = colorise;
|
|
152
|
+
return options;
|
|
153
|
+
}
|
|
154
|
+
function isHighSurrogate(char) {
|
|
155
|
+
return char >= '\ud800' && char <= '\udbff';
|
|
156
|
+
}
|
|
157
|
+
function helpers_truncate(string, length, tail = truncator) {
|
|
158
|
+
string = String(string);
|
|
159
|
+
const tailLength = tail.length;
|
|
160
|
+
const stringLength = string.length;
|
|
161
|
+
if (tailLength > length && stringLength > tailLength) return tail;
|
|
162
|
+
if (stringLength > length && stringLength > tailLength) {
|
|
163
|
+
let end = length - tailLength;
|
|
164
|
+
if (end > 0 && isHighSurrogate(string[end - 1])) end -= 1;
|
|
165
|
+
return `${string.slice(0, end)}${tail}`;
|
|
166
|
+
}
|
|
167
|
+
return string;
|
|
168
|
+
}
|
|
169
|
+
function inspectList(list, options, inspectItem, separator = ', ') {
|
|
170
|
+
inspectItem = inspectItem || options.inspect;
|
|
171
|
+
const size = list.length;
|
|
172
|
+
if (0 === size) return '';
|
|
173
|
+
const originalLength = options.truncate;
|
|
174
|
+
let output = '';
|
|
175
|
+
let peek = '';
|
|
176
|
+
let truncated = '';
|
|
177
|
+
for(let i = 0; i < size; i += 1){
|
|
178
|
+
const last = i + 1 === list.length;
|
|
179
|
+
const secondToLast = i + 2 === list.length;
|
|
180
|
+
truncated = `${truncator}(${list.length - i})`;
|
|
181
|
+
const value = list[i];
|
|
182
|
+
options.truncate = originalLength - output.length - (last ? 0 : separator.length);
|
|
183
|
+
const string = peek || inspectItem(value, options) + (last ? '' : separator);
|
|
184
|
+
const nextLength = output.length + string.length;
|
|
185
|
+
const truncatedLength = nextLength + truncated.length;
|
|
186
|
+
if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) break;
|
|
187
|
+
if (!last && !secondToLast && truncatedLength > originalLength) break;
|
|
188
|
+
peek = last ? '' : inspectItem(list[i + 1], options) + (secondToLast ? '' : separator);
|
|
189
|
+
if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) break;
|
|
190
|
+
output += string;
|
|
191
|
+
if (!last && !secondToLast && nextLength + peek.length >= originalLength) {
|
|
192
|
+
truncated = `${truncator}(${list.length - i - 1})`;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
truncated = '';
|
|
196
|
+
}
|
|
197
|
+
return `${output}${truncated}`;
|
|
198
|
+
}
|
|
199
|
+
function quoteComplexKey(key) {
|
|
200
|
+
if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) return key;
|
|
201
|
+
return JSON.stringify(key).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
|
|
202
|
+
}
|
|
203
|
+
function inspectProperty([key, value], options) {
|
|
204
|
+
options.truncate -= 2;
|
|
205
|
+
if ('string' == typeof key) key = quoteComplexKey(key);
|
|
206
|
+
else if ('number' != typeof key) key = `[${options.inspect(key, options)}]`;
|
|
207
|
+
options.truncate -= key.length;
|
|
208
|
+
value = options.inspect(value, options);
|
|
209
|
+
return `${key}: ${value}`;
|
|
210
|
+
}
|
|
211
|
+
function inspectArray(array, options) {
|
|
212
|
+
const nonIndexProperties = Object.keys(array).slice(array.length);
|
|
213
|
+
if (!array.length && !nonIndexProperties.length) return '[]';
|
|
214
|
+
options.truncate -= 4;
|
|
215
|
+
const listContents = inspectList(array, options);
|
|
216
|
+
options.truncate -= listContents.length;
|
|
217
|
+
let propertyContents = '';
|
|
218
|
+
if (nonIndexProperties.length) propertyContents = inspectList(nonIndexProperties.map((key)=>[
|
|
219
|
+
key,
|
|
220
|
+
array[key]
|
|
221
|
+
]), options, inspectProperty);
|
|
222
|
+
return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ''} ]`;
|
|
223
|
+
}
|
|
224
|
+
const getArrayName = (array)=>{
|
|
225
|
+
if ('function' == typeof Buffer && array instanceof Buffer) return 'Buffer';
|
|
226
|
+
if (array[Symbol.toStringTag]) return array[Symbol.toStringTag];
|
|
227
|
+
return array.constructor.name;
|
|
228
|
+
};
|
|
229
|
+
function inspectTypedArray(array, options) {
|
|
230
|
+
const name = getArrayName(array);
|
|
231
|
+
options.truncate -= name.length + 4;
|
|
232
|
+
const nonIndexProperties = Object.keys(array).slice(array.length);
|
|
233
|
+
if (!array.length && !nonIndexProperties.length) return `${name}[]`;
|
|
234
|
+
let output = '';
|
|
235
|
+
for(let i = 0; i < array.length; i++){
|
|
236
|
+
const string = `${options.stylize(helpers_truncate(array[i], options.truncate), 'number')}${i === array.length - 1 ? '' : ', '}`;
|
|
237
|
+
options.truncate -= string.length;
|
|
238
|
+
if (array[i] !== array.length && options.truncate <= 3) {
|
|
239
|
+
output += `…(${array.length - array[i] + 1})`;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
output += string;
|
|
243
|
+
}
|
|
244
|
+
let propertyContents = '';
|
|
245
|
+
if (nonIndexProperties.length) propertyContents = inspectList(nonIndexProperties.map((key)=>[
|
|
246
|
+
key,
|
|
247
|
+
array[key]
|
|
248
|
+
]), options, inspectProperty);
|
|
249
|
+
return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ''} ]`;
|
|
250
|
+
}
|
|
251
|
+
function inspectDate(dateObject, options) {
|
|
252
|
+
const stringRepresentation = dateObject.toJSON();
|
|
253
|
+
if (null === stringRepresentation) return 'Invalid Date';
|
|
254
|
+
const split = stringRepresentation.split('T');
|
|
255
|
+
const date = split[0];
|
|
256
|
+
return options.stylize(`${date}T${helpers_truncate(split[1], options.truncate - date.length - 1)}`, 'date');
|
|
257
|
+
}
|
|
258
|
+
function inspectFunction(func, options) {
|
|
259
|
+
const functionType = func[Symbol.toStringTag] || 'Function';
|
|
260
|
+
const name = func.name;
|
|
261
|
+
if (!name) return options.stylize(`[${functionType}]`, 'special');
|
|
262
|
+
return options.stylize(`[${functionType} ${helpers_truncate(name, options.truncate - 11)}]`, 'special');
|
|
263
|
+
}
|
|
264
|
+
function inspectMapEntry([key, value], options) {
|
|
265
|
+
options.truncate -= 4;
|
|
266
|
+
key = options.inspect(key, options);
|
|
267
|
+
options.truncate -= key.length;
|
|
268
|
+
value = options.inspect(value, options);
|
|
269
|
+
return `${key} => ${value}`;
|
|
270
|
+
}
|
|
271
|
+
function mapToEntries(map) {
|
|
272
|
+
const entries = [];
|
|
273
|
+
map.forEach((value, key)=>{
|
|
274
|
+
entries.push([
|
|
275
|
+
key,
|
|
276
|
+
value
|
|
277
|
+
]);
|
|
278
|
+
});
|
|
279
|
+
return entries;
|
|
280
|
+
}
|
|
281
|
+
function inspectMap(map, options) {
|
|
282
|
+
if (0 === map.size) return 'Map{}';
|
|
283
|
+
options.truncate -= 7;
|
|
284
|
+
return `Map{ ${inspectList(mapToEntries(map), options, inspectMapEntry)} }`;
|
|
285
|
+
}
|
|
286
|
+
const number_isNaN = Number.isNaN || ((i)=>i !== i);
|
|
287
|
+
function inspectNumber(number, options) {
|
|
288
|
+
if (number_isNaN(number)) return options.stylize('NaN', 'number');
|
|
289
|
+
if (number === 1 / 0) return options.stylize('Infinity', 'number');
|
|
290
|
+
if (number === -1 / 0) return options.stylize('-Infinity', 'number');
|
|
291
|
+
if (0 === number) return options.stylize(1 / number === 1 / 0 ? '+0' : '-0', 'number');
|
|
292
|
+
return options.stylize(helpers_truncate(String(number), options.truncate), 'number');
|
|
293
|
+
}
|
|
294
|
+
function inspectBigInt(number, options) {
|
|
295
|
+
let nums = helpers_truncate(number.toString(), options.truncate - 1);
|
|
296
|
+
if ("…" !== nums) nums += 'n';
|
|
297
|
+
return options.stylize(nums, 'bigint');
|
|
298
|
+
}
|
|
299
|
+
function inspectRegExp(value, options) {
|
|
300
|
+
const flags = value.toString().split('/')[2];
|
|
301
|
+
const sourceLength = options.truncate - (2 + flags.length);
|
|
302
|
+
const source = value.source;
|
|
303
|
+
return options.stylize(`/${helpers_truncate(source, sourceLength)}/${flags}`, 'regexp');
|
|
304
|
+
}
|
|
305
|
+
function arrayFromSet(set) {
|
|
306
|
+
const values = [];
|
|
307
|
+
set.forEach((value)=>{
|
|
308
|
+
values.push(value);
|
|
309
|
+
});
|
|
310
|
+
return values;
|
|
311
|
+
}
|
|
312
|
+
function inspectSet(set, options) {
|
|
313
|
+
if (0 === set.size) return 'Set{}';
|
|
314
|
+
options.truncate -= 7;
|
|
315
|
+
return `Set{ ${inspectList(arrayFromSet(set), options)} }`;
|
|
316
|
+
}
|
|
317
|
+
const stringEscapeChars = new RegExp("['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", 'g');
|
|
318
|
+
const escapeCharacters = {
|
|
319
|
+
'\b': '\\b',
|
|
320
|
+
'\t': '\\t',
|
|
321
|
+
'\n': '\\n',
|
|
322
|
+
'\f': '\\f',
|
|
323
|
+
'\r': '\\r',
|
|
324
|
+
"'": "\\'",
|
|
325
|
+
'\\': '\\\\'
|
|
326
|
+
};
|
|
327
|
+
const hex = 16;
|
|
328
|
+
const unicodeLength = 4;
|
|
329
|
+
function string_escape(char) {
|
|
330
|
+
return escapeCharacters[char] || `\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-unicodeLength)}`;
|
|
331
|
+
}
|
|
332
|
+
function inspectString(string, options) {
|
|
333
|
+
if (stringEscapeChars.test(string)) string = string.replace(stringEscapeChars, string_escape);
|
|
334
|
+
return options.stylize(`'${helpers_truncate(string, options.truncate - 2)}'`, 'string');
|
|
335
|
+
}
|
|
336
|
+
function inspectSymbol(value) {
|
|
337
|
+
if ("description" in Symbol.prototype) return value.description ? `Symbol(${value.description})` : 'Symbol()';
|
|
338
|
+
return value.toString();
|
|
339
|
+
}
|
|
340
|
+
let getPromiseValue = ()=>'Promise{…}';
|
|
341
|
+
try {
|
|
342
|
+
const { getPromiseDetails, kPending, kRejected } = process.binding('util');
|
|
343
|
+
if (Array.isArray(getPromiseDetails(Promise.resolve()))) getPromiseValue = (value, options)=>{
|
|
344
|
+
const [state, innerValue] = getPromiseDetails(value);
|
|
345
|
+
if (state === kPending) return 'Promise{<pending>}';
|
|
346
|
+
return `Promise${state === kRejected ? '!' : ''}{${options.inspect(innerValue, options)}}`;
|
|
347
|
+
};
|
|
348
|
+
} catch (notNode) {}
|
|
349
|
+
const promise = getPromiseValue;
|
|
350
|
+
function inspectObject(object, options) {
|
|
351
|
+
const properties = Object.getOwnPropertyNames(object);
|
|
352
|
+
const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : [];
|
|
353
|
+
if (0 === properties.length && 0 === symbols.length) return '{}';
|
|
354
|
+
options.truncate -= 4;
|
|
355
|
+
options.seen = options.seen || [];
|
|
356
|
+
if (options.seen.includes(object)) return '[Circular]';
|
|
357
|
+
options.seen.push(object);
|
|
358
|
+
const propertyContents = inspectList(properties.map((key)=>[
|
|
359
|
+
key,
|
|
360
|
+
object[key]
|
|
361
|
+
]), options, inspectProperty);
|
|
362
|
+
const symbolContents = inspectList(symbols.map((key)=>[
|
|
363
|
+
key,
|
|
364
|
+
object[key]
|
|
365
|
+
]), options, inspectProperty);
|
|
366
|
+
options.seen.pop();
|
|
367
|
+
let sep = '';
|
|
368
|
+
if (propertyContents && symbolContents) sep = ', ';
|
|
369
|
+
return `{ ${propertyContents}${sep}${symbolContents} }`;
|
|
370
|
+
}
|
|
371
|
+
const toStringTag = "u" > typeof Symbol && Symbol.toStringTag ? Symbol.toStringTag : false;
|
|
372
|
+
function inspectClass(value, options) {
|
|
373
|
+
let name = '';
|
|
374
|
+
if (toStringTag && toStringTag in value) name = value[toStringTag];
|
|
375
|
+
name = name || value.constructor.name;
|
|
376
|
+
if (!name || '_class' === name) name = '<Anonymous Class>';
|
|
377
|
+
options.truncate -= name.length;
|
|
378
|
+
return `${name}${inspectObject(value, options)}`;
|
|
379
|
+
}
|
|
380
|
+
function inspectArguments(args, options) {
|
|
381
|
+
if (0 === args.length) return 'Arguments[]';
|
|
382
|
+
options.truncate -= 13;
|
|
383
|
+
return `Arguments[ ${inspectList(args, options)} ]`;
|
|
384
|
+
}
|
|
385
|
+
const errorKeys = [
|
|
386
|
+
'stack',
|
|
387
|
+
'line',
|
|
388
|
+
'column',
|
|
389
|
+
'name',
|
|
390
|
+
'message',
|
|
391
|
+
'fileName',
|
|
392
|
+
'lineNumber',
|
|
393
|
+
'columnNumber',
|
|
394
|
+
'number',
|
|
395
|
+
"description",
|
|
396
|
+
'cause'
|
|
397
|
+
];
|
|
398
|
+
function error_inspectObject(error, options) {
|
|
399
|
+
const properties = Object.getOwnPropertyNames(error).filter((key)=>-1 === errorKeys.indexOf(key));
|
|
400
|
+
const name = error.name;
|
|
401
|
+
options.truncate -= name.length;
|
|
402
|
+
let message = '';
|
|
403
|
+
if ('string' == typeof error.message) message = helpers_truncate(error.message, options.truncate);
|
|
404
|
+
else properties.unshift('message');
|
|
405
|
+
message = message ? `: ${message}` : '';
|
|
406
|
+
options.truncate -= message.length + 5;
|
|
407
|
+
options.seen = options.seen || [];
|
|
408
|
+
if (options.seen.includes(error)) return '[Circular]';
|
|
409
|
+
options.seen.push(error);
|
|
410
|
+
const propertyContents = inspectList(properties.map((key)=>[
|
|
411
|
+
key,
|
|
412
|
+
error[key]
|
|
413
|
+
]), options, inspectProperty);
|
|
414
|
+
return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ''}`;
|
|
415
|
+
}
|
|
416
|
+
function inspectAttribute([key, value], options) {
|
|
417
|
+
options.truncate -= 3;
|
|
418
|
+
if (!value) return `${options.stylize(String(key), 'yellow')}`;
|
|
419
|
+
return `${options.stylize(String(key), 'yellow')}=${options.stylize(`"${value}"`, 'string')}`;
|
|
420
|
+
}
|
|
421
|
+
function inspectNodeCollection(collection, options) {
|
|
422
|
+
return inspectList(collection, options, inspectNode, '\n');
|
|
423
|
+
}
|
|
424
|
+
function inspectNode(node, options) {
|
|
425
|
+
switch(node.nodeType){
|
|
426
|
+
case 1:
|
|
427
|
+
return inspectHTML(node, options);
|
|
428
|
+
case 3:
|
|
429
|
+
return options.inspect(node.data, options);
|
|
430
|
+
default:
|
|
431
|
+
return options.inspect(node, options);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function inspectHTML(element, options) {
|
|
435
|
+
const properties = element.getAttributeNames();
|
|
436
|
+
const name = element.tagName.toLowerCase();
|
|
437
|
+
const head = options.stylize(`<${name}`, 'special');
|
|
438
|
+
const headClose = options.stylize(">", 'special');
|
|
439
|
+
const tail = options.stylize(`</${name}>`, 'special');
|
|
440
|
+
options.truncate -= 2 * name.length + 5;
|
|
441
|
+
let propertyContents = '';
|
|
442
|
+
if (properties.length > 0) {
|
|
443
|
+
propertyContents += ' ';
|
|
444
|
+
propertyContents += inspectList(properties.map((key)=>[
|
|
445
|
+
key,
|
|
446
|
+
element.getAttribute(key)
|
|
447
|
+
]), options, inspectAttribute, ' ');
|
|
448
|
+
}
|
|
449
|
+
options.truncate -= propertyContents.length;
|
|
450
|
+
const truncate = options.truncate;
|
|
451
|
+
let children = inspectNodeCollection(element.children, options);
|
|
452
|
+
if (children && children.length > truncate) children = `…(${element.children.length})`;
|
|
453
|
+
return `${head}${propertyContents}${headClose}${children}${tail}`;
|
|
454
|
+
}
|
|
455
|
+
const symbolsSupported = 'function' == typeof Symbol && 'function' == typeof Symbol.for;
|
|
456
|
+
const chaiInspect = symbolsSupported ? Symbol.for('chai/inspect') : '@@chai/inspect';
|
|
457
|
+
const nodeInspect = Symbol.for('nodejs.util.inspect.custom');
|
|
458
|
+
const constructorMap = new WeakMap();
|
|
459
|
+
const stringTagMap = {};
|
|
460
|
+
const baseTypesMap = {
|
|
461
|
+
undefined: (value, options)=>options.stylize('undefined', 'undefined'),
|
|
462
|
+
null: (value, options)=>options.stylize('null', 'null'),
|
|
463
|
+
boolean: (value, options)=>options.stylize(String(value), 'boolean'),
|
|
464
|
+
Boolean: (value, options)=>options.stylize(String(value), 'boolean'),
|
|
465
|
+
number: inspectNumber,
|
|
466
|
+
Number: inspectNumber,
|
|
467
|
+
bigint: inspectBigInt,
|
|
468
|
+
BigInt: inspectBigInt,
|
|
469
|
+
string: inspectString,
|
|
470
|
+
String: inspectString,
|
|
471
|
+
function: inspectFunction,
|
|
472
|
+
Function: inspectFunction,
|
|
473
|
+
symbol: inspectSymbol,
|
|
474
|
+
Symbol: inspectSymbol,
|
|
475
|
+
Array: inspectArray,
|
|
476
|
+
Date: inspectDate,
|
|
477
|
+
Map: inspectMap,
|
|
478
|
+
Set: inspectSet,
|
|
479
|
+
RegExp: inspectRegExp,
|
|
480
|
+
Promise: promise,
|
|
481
|
+
WeakSet: (value, options)=>options.stylize('WeakSet{…}', 'special'),
|
|
482
|
+
WeakMap: (value, options)=>options.stylize('WeakMap{…}', 'special'),
|
|
483
|
+
Arguments: inspectArguments,
|
|
484
|
+
Int8Array: inspectTypedArray,
|
|
485
|
+
Uint8Array: inspectTypedArray,
|
|
486
|
+
Uint8ClampedArray: inspectTypedArray,
|
|
487
|
+
Int16Array: inspectTypedArray,
|
|
488
|
+
Uint16Array: inspectTypedArray,
|
|
489
|
+
Int32Array: inspectTypedArray,
|
|
490
|
+
Uint32Array: inspectTypedArray,
|
|
491
|
+
Float32Array: inspectTypedArray,
|
|
492
|
+
Float64Array: inspectTypedArray,
|
|
493
|
+
Generator: ()=>'',
|
|
494
|
+
DataView: ()=>'',
|
|
495
|
+
ArrayBuffer: ()=>'',
|
|
496
|
+
Error: error_inspectObject,
|
|
497
|
+
HTMLCollection: inspectNodeCollection,
|
|
498
|
+
NodeList: inspectNodeCollection
|
|
499
|
+
};
|
|
500
|
+
const inspectCustom = (value, options, type)=>{
|
|
501
|
+
if (chaiInspect in value && 'function' == typeof value[chaiInspect]) return value[chaiInspect](options);
|
|
502
|
+
if (nodeInspect in value && 'function' == typeof value[nodeInspect]) return value[nodeInspect](options.depth, options);
|
|
503
|
+
if ('inspect' in value && 'function' == typeof value.inspect) return value.inspect(options.depth, options);
|
|
504
|
+
if ('constructor' in value && constructorMap.has(value.constructor)) return constructorMap.get(value.constructor)(value, options);
|
|
505
|
+
if (stringTagMap[type]) return stringTagMap[type](value, options);
|
|
506
|
+
return '';
|
|
507
|
+
};
|
|
508
|
+
const lib_toString = Object.prototype.toString;
|
|
509
|
+
function lib_inspect(value, opts = {}) {
|
|
510
|
+
const options = normaliseOptions(opts, lib_inspect);
|
|
511
|
+
const { customInspect } = options;
|
|
512
|
+
let type = null === value ? 'null' : typeof value;
|
|
513
|
+
if ('object' === type) type = lib_toString.call(value).slice(8, -1);
|
|
514
|
+
if (type in baseTypesMap) return baseTypesMap[type](value, options);
|
|
515
|
+
if (customInspect && value) {
|
|
516
|
+
const output = inspectCustom(value, options, type);
|
|
517
|
+
if (output) {
|
|
518
|
+
if ('string' == typeof output) return output;
|
|
519
|
+
return lib_inspect(output, options);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const proto = value ? Object.getPrototypeOf(value) : false;
|
|
523
|
+
if (proto === Object.prototype || null === proto) return inspectObject(value, options);
|
|
524
|
+
if (value && 'function' == typeof HTMLElement && value instanceof HTMLElement) return inspectHTML(value, options);
|
|
525
|
+
if ('constructor' in value) {
|
|
526
|
+
if (value.constructor !== Object) return inspectClass(value, options);
|
|
527
|
+
return inspectObject(value, options);
|
|
528
|
+
}
|
|
529
|
+
if (value === Object(value)) return inspectObject(value, options);
|
|
530
|
+
return options.stylize(String(value), type);
|
|
531
|
+
}
|
|
532
|
+
const { AsymmetricMatcher: AsymmetricMatcher, DOMCollection: DOMCollection, DOMElement: DOMElement, Immutable: Immutable, ReactElement: ReactElement, ReactTestComponent: ReactTestComponent } = dist_plugins;
|
|
533
|
+
const PLUGINS = [
|
|
534
|
+
ReactTestComponent,
|
|
535
|
+
ReactElement,
|
|
536
|
+
DOMElement,
|
|
537
|
+
DOMCollection,
|
|
538
|
+
Immutable,
|
|
539
|
+
AsymmetricMatcher
|
|
540
|
+
];
|
|
541
|
+
function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
|
|
542
|
+
const MAX_LENGTH = maxLength ?? 1e4;
|
|
543
|
+
let result;
|
|
544
|
+
try {
|
|
545
|
+
result = dist_format(object, {
|
|
546
|
+
maxDepth,
|
|
547
|
+
escapeString: false,
|
|
548
|
+
plugins: PLUGINS,
|
|
549
|
+
...options
|
|
550
|
+
});
|
|
551
|
+
} catch {
|
|
552
|
+
result = dist_format(object, {
|
|
553
|
+
callToJSON: false,
|
|
554
|
+
maxDepth,
|
|
555
|
+
escapeString: false,
|
|
556
|
+
plugins: PLUGINS,
|
|
557
|
+
...options
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(Math.min(maxDepth, Number.MAX_SAFE_INTEGER) / 2), {
|
|
561
|
+
maxLength,
|
|
562
|
+
...options
|
|
563
|
+
}) : result;
|
|
564
|
+
}
|
|
565
|
+
const formatRegExp = /%[sdjifoOc%]/g;
|
|
566
|
+
function format(...args) {
|
|
567
|
+
if ("string" != typeof args[0]) {
|
|
568
|
+
const objects = [];
|
|
569
|
+
for(let i = 0; i < args.length; i++)objects.push(chunk_commonjsHelpers_inspect(args[i], {
|
|
570
|
+
depth: 0,
|
|
571
|
+
colors: false
|
|
572
|
+
}));
|
|
573
|
+
return objects.join(" ");
|
|
574
|
+
}
|
|
575
|
+
const len = args.length;
|
|
576
|
+
let i = 1;
|
|
577
|
+
const template = args[0];
|
|
578
|
+
let str = String(template).replace(formatRegExp, (x)=>{
|
|
579
|
+
if ("%%" === x) return "%";
|
|
580
|
+
if (i >= len) return x;
|
|
581
|
+
switch(x){
|
|
582
|
+
case "%s":
|
|
583
|
+
{
|
|
584
|
+
const value = args[i++];
|
|
585
|
+
if ("bigint" == typeof value) return `${value.toString()}n`;
|
|
586
|
+
if ("number" == typeof value && 0 === value && 1 / value < 0) return "-0";
|
|
587
|
+
if ("object" == typeof value && null !== value) {
|
|
588
|
+
if ("function" == typeof value.toString && value.toString !== Object.prototype.toString) return value.toString();
|
|
589
|
+
return chunk_commonjsHelpers_inspect(value, {
|
|
590
|
+
depth: 0,
|
|
591
|
+
colors: false
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
return String(value);
|
|
595
|
+
}
|
|
596
|
+
case "%d":
|
|
597
|
+
{
|
|
598
|
+
const value = args[i++];
|
|
599
|
+
if ("bigint" == typeof value) return `${value.toString()}n`;
|
|
600
|
+
return Number(value).toString();
|
|
601
|
+
}
|
|
602
|
+
case "%i":
|
|
603
|
+
{
|
|
604
|
+
const value = args[i++];
|
|
605
|
+
if ("bigint" == typeof value) return `${value.toString()}n`;
|
|
606
|
+
return Number.parseInt(String(value)).toString();
|
|
607
|
+
}
|
|
608
|
+
case "%f":
|
|
609
|
+
return Number.parseFloat(String(args[i++])).toString();
|
|
610
|
+
case "%o":
|
|
611
|
+
return chunk_commonjsHelpers_inspect(args[i++], {
|
|
612
|
+
showHidden: true,
|
|
613
|
+
showProxy: true
|
|
614
|
+
});
|
|
615
|
+
case "%O":
|
|
616
|
+
return chunk_commonjsHelpers_inspect(args[i++]);
|
|
617
|
+
case "%c":
|
|
618
|
+
i++;
|
|
619
|
+
return "";
|
|
620
|
+
case "%j":
|
|
621
|
+
try {
|
|
622
|
+
return JSON.stringify(args[i++]);
|
|
623
|
+
} catch (err) {
|
|
624
|
+
const m = err.message;
|
|
625
|
+
if (m.includes("circular structure") || m.includes("cyclic structures") || m.includes("cyclic object")) return "[Circular]";
|
|
626
|
+
throw err;
|
|
627
|
+
}
|
|
628
|
+
default:
|
|
629
|
+
return x;
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
for(let x = args[i]; i < len; x = args[++i])if (null === x || "object" != typeof x) str += ` ${x}`;
|
|
633
|
+
else str += ` ${chunk_commonjsHelpers_inspect(x)}`;
|
|
634
|
+
return str;
|
|
635
|
+
}
|
|
636
|
+
function chunk_commonjsHelpers_inspect(obj, options = {}) {
|
|
637
|
+
if (0 === options.truncate) options.truncate = 1 / 0;
|
|
638
|
+
return lib_inspect(obj, options);
|
|
639
|
+
}
|
|
640
|
+
function getDefaultExportFromCjs(x) {
|
|
641
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
642
|
+
}
|
|
643
|
+
function assertTypes(value, name, types) {
|
|
644
|
+
const receivedType = typeof value;
|
|
645
|
+
const pass = types.includes(receivedType);
|
|
646
|
+
if (!pass) throw new TypeError(`${name} value must be ${types.join(" or ")}, received "${receivedType}"`);
|
|
647
|
+
}
|
|
648
|
+
function isObject(item) {
|
|
649
|
+
return null != item && "object" == typeof item && !Array.isArray(item);
|
|
650
|
+
}
|
|
651
|
+
function isFinalObj(obj) {
|
|
652
|
+
return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
|
|
653
|
+
}
|
|
654
|
+
function getType(value) {
|
|
655
|
+
return Object.prototype.toString.apply(value).slice(8, -1);
|
|
656
|
+
}
|
|
657
|
+
function collectOwnProperties(obj, collector) {
|
|
658
|
+
const collect = "function" == typeof collector ? collector : (key)=>collector.add(key);
|
|
659
|
+
Object.getOwnPropertyNames(obj).forEach(collect);
|
|
660
|
+
Object.getOwnPropertySymbols(obj).forEach(collect);
|
|
661
|
+
}
|
|
662
|
+
function getOwnProperties(obj) {
|
|
663
|
+
const ownProps = new Set();
|
|
664
|
+
if (isFinalObj(obj)) return [];
|
|
665
|
+
collectOwnProperties(obj, ownProps);
|
|
666
|
+
return Array.from(ownProps);
|
|
667
|
+
}
|
|
668
|
+
const defaultCloneOptions = {
|
|
669
|
+
forceWritable: false
|
|
670
|
+
};
|
|
671
|
+
function deepClone(val, options = defaultCloneOptions) {
|
|
672
|
+
const seen = new WeakMap();
|
|
673
|
+
return clone(val, seen, options);
|
|
674
|
+
}
|
|
675
|
+
function clone(val, seen, options = defaultCloneOptions) {
|
|
676
|
+
let k, out;
|
|
677
|
+
if (seen.has(val)) return seen.get(val);
|
|
678
|
+
if (Array.isArray(val)) {
|
|
679
|
+
out = Array.from({
|
|
680
|
+
length: k = val.length
|
|
681
|
+
});
|
|
682
|
+
seen.set(val, out);
|
|
683
|
+
while(k--)out[k] = clone(val[k], seen, options);
|
|
684
|
+
return out;
|
|
685
|
+
}
|
|
686
|
+
if ("[object Object]" === Object.prototype.toString.call(val)) {
|
|
687
|
+
out = Object.create(Object.getPrototypeOf(val));
|
|
688
|
+
seen.set(val, out);
|
|
689
|
+
const props = getOwnProperties(val);
|
|
690
|
+
for (const k of props){
|
|
691
|
+
const descriptor = Object.getOwnPropertyDescriptor(val, k);
|
|
692
|
+
if (!descriptor) continue;
|
|
693
|
+
const cloned = clone(val[k], seen, options);
|
|
694
|
+
if (options.forceWritable) Object.defineProperty(out, k, {
|
|
695
|
+
enumerable: descriptor.enumerable,
|
|
696
|
+
configurable: true,
|
|
697
|
+
writable: true,
|
|
698
|
+
value: cloned
|
|
699
|
+
});
|
|
700
|
+
else if ("get" in descriptor) Object.defineProperty(out, k, {
|
|
701
|
+
...descriptor,
|
|
702
|
+
get () {
|
|
703
|
+
return cloned;
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
else Object.defineProperty(out, k, {
|
|
707
|
+
...descriptor,
|
|
708
|
+
value: cloned
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
return out;
|
|
712
|
+
}
|
|
713
|
+
return val;
|
|
714
|
+
}
|
|
715
|
+
function noop() {}
|
|
716
|
+
const DIFF_DELETE = -1;
|
|
717
|
+
const DIFF_INSERT = 1;
|
|
718
|
+
const DIFF_EQUAL = 0;
|
|
719
|
+
class Diff {
|
|
720
|
+
0;
|
|
721
|
+
1;
|
|
722
|
+
constructor(op, text){
|
|
723
|
+
this[0] = op;
|
|
724
|
+
this[1] = text;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
function diff_commonPrefix(text1, text2) {
|
|
728
|
+
if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) return 0;
|
|
729
|
+
let pointermin = 0;
|
|
730
|
+
let pointermax = Math.min(text1.length, text2.length);
|
|
731
|
+
let pointermid = pointermax;
|
|
732
|
+
let pointerstart = 0;
|
|
733
|
+
while(pointermin < pointermid){
|
|
734
|
+
if (text1.substring(pointerstart, pointermid) === text2.substring(pointerstart, pointermid)) {
|
|
735
|
+
pointermin = pointermid;
|
|
736
|
+
pointerstart = pointermin;
|
|
737
|
+
} else pointermax = pointermid;
|
|
738
|
+
pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
|
|
739
|
+
}
|
|
740
|
+
return pointermid;
|
|
741
|
+
}
|
|
742
|
+
function diff_commonSuffix(text1, text2) {
|
|
743
|
+
if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) return 0;
|
|
744
|
+
let pointermin = 0;
|
|
745
|
+
let pointermax = Math.min(text1.length, text2.length);
|
|
746
|
+
let pointermid = pointermax;
|
|
747
|
+
let pointerend = 0;
|
|
748
|
+
while(pointermin < pointermid){
|
|
749
|
+
if (text1.substring(text1.length - pointermid, text1.length - pointerend) === text2.substring(text2.length - pointermid, text2.length - pointerend)) {
|
|
750
|
+
pointermin = pointermid;
|
|
751
|
+
pointerend = pointermin;
|
|
752
|
+
} else pointermax = pointermid;
|
|
753
|
+
pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
|
|
754
|
+
}
|
|
755
|
+
return pointermid;
|
|
756
|
+
}
|
|
757
|
+
function diff_commonOverlap_(text1, text2) {
|
|
758
|
+
const text1_length = text1.length;
|
|
759
|
+
const text2_length = text2.length;
|
|
760
|
+
if (0 === text1_length || 0 === text2_length) return 0;
|
|
761
|
+
if (text1_length > text2_length) text1 = text1.substring(text1_length - text2_length);
|
|
762
|
+
else if (text1_length < text2_length) text2 = text2.substring(0, text1_length);
|
|
763
|
+
const text_length = Math.min(text1_length, text2_length);
|
|
764
|
+
if (text1 === text2) return text_length;
|
|
765
|
+
let best = 0;
|
|
766
|
+
let length = 1;
|
|
767
|
+
while(true){
|
|
768
|
+
const pattern = text1.substring(text_length - length);
|
|
769
|
+
const found = text2.indexOf(pattern);
|
|
770
|
+
if (-1 === found) return best;
|
|
771
|
+
length += found;
|
|
772
|
+
if (0 === found || text1.substring(text_length - length) === text2.substring(0, length)) {
|
|
773
|
+
best = length;
|
|
774
|
+
length++;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
function diff_cleanupSemantic(diffs) {
|
|
779
|
+
let changes = false;
|
|
780
|
+
const equalities = [];
|
|
781
|
+
let equalitiesLength = 0;
|
|
782
|
+
let lastEquality = null;
|
|
783
|
+
let pointer = 0;
|
|
784
|
+
let length_insertions1 = 0;
|
|
785
|
+
let length_deletions1 = 0;
|
|
786
|
+
let length_insertions2 = 0;
|
|
787
|
+
let length_deletions2 = 0;
|
|
788
|
+
while(pointer < diffs.length){
|
|
789
|
+
if (diffs[pointer][0] === DIFF_EQUAL) {
|
|
790
|
+
equalities[equalitiesLength++] = pointer;
|
|
791
|
+
length_insertions1 = length_insertions2;
|
|
792
|
+
length_deletions1 = length_deletions2;
|
|
793
|
+
length_insertions2 = 0;
|
|
794
|
+
length_deletions2 = 0;
|
|
795
|
+
lastEquality = diffs[pointer][1];
|
|
796
|
+
} else {
|
|
797
|
+
if (diffs[pointer][0] === DIFF_INSERT) length_insertions2 += diffs[pointer][1].length;
|
|
798
|
+
else length_deletions2 += diffs[pointer][1].length;
|
|
799
|
+
if (lastEquality && lastEquality.length <= Math.max(length_insertions1, length_deletions1) && lastEquality.length <= Math.max(length_insertions2, length_deletions2)) {
|
|
800
|
+
diffs.splice(equalities[equalitiesLength - 1], 0, new Diff(DIFF_DELETE, lastEquality));
|
|
801
|
+
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
|
|
802
|
+
equalitiesLength--;
|
|
803
|
+
equalitiesLength--;
|
|
804
|
+
pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
|
|
805
|
+
length_insertions1 = 0;
|
|
806
|
+
length_deletions1 = 0;
|
|
807
|
+
length_insertions2 = 0;
|
|
808
|
+
length_deletions2 = 0;
|
|
809
|
+
lastEquality = null;
|
|
810
|
+
changes = true;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
pointer++;
|
|
814
|
+
}
|
|
815
|
+
if (changes) diff_cleanupMerge(diffs);
|
|
816
|
+
diff_cleanupSemanticLossless(diffs);
|
|
817
|
+
pointer = 1;
|
|
818
|
+
while(pointer < diffs.length){
|
|
819
|
+
if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
|
|
820
|
+
const deletion = diffs[pointer - 1][1];
|
|
821
|
+
const insertion = diffs[pointer][1];
|
|
822
|
+
const overlap_length1 = diff_commonOverlap_(deletion, insertion);
|
|
823
|
+
const overlap_length2 = diff_commonOverlap_(insertion, deletion);
|
|
824
|
+
if (overlap_length1 >= overlap_length2) {
|
|
825
|
+
if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) {
|
|
826
|
+
diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1)));
|
|
827
|
+
diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlap_length1);
|
|
828
|
+
diffs[pointer + 1][1] = insertion.substring(overlap_length1);
|
|
829
|
+
pointer++;
|
|
830
|
+
}
|
|
831
|
+
} else if (overlap_length2 >= deletion.length / 2 || overlap_length2 >= insertion.length / 2) {
|
|
832
|
+
diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2)));
|
|
833
|
+
diffs[pointer - 1][0] = DIFF_INSERT;
|
|
834
|
+
diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlap_length2);
|
|
835
|
+
diffs[pointer + 1][0] = DIFF_DELETE;
|
|
836
|
+
diffs[pointer + 1][1] = deletion.substring(overlap_length2);
|
|
837
|
+
pointer++;
|
|
838
|
+
}
|
|
839
|
+
pointer++;
|
|
840
|
+
}
|
|
841
|
+
pointer++;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const nonAlphaNumericRegex_ = /[^a-z0-9]/i;
|
|
845
|
+
const whitespaceRegex_ = /\s/;
|
|
846
|
+
const linebreakRegex_ = /[\r\n]/;
|
|
847
|
+
const blanklineEndRegex_ = /\n\r?\n$/;
|
|
848
|
+
const blanklineStartRegex_ = /^\r?\n\r?\n/;
|
|
849
|
+
function diff_cleanupSemanticLossless(diffs) {
|
|
850
|
+
let pointer = 1;
|
|
851
|
+
while(pointer < diffs.length - 1){
|
|
852
|
+
if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
|
|
853
|
+
let equality1 = diffs[pointer - 1][1];
|
|
854
|
+
let edit = diffs[pointer][1];
|
|
855
|
+
let equality2 = diffs[pointer + 1][1];
|
|
856
|
+
const commonOffset = diff_commonSuffix(equality1, edit);
|
|
857
|
+
if (commonOffset) {
|
|
858
|
+
const commonString = edit.substring(edit.length - commonOffset);
|
|
859
|
+
equality1 = equality1.substring(0, equality1.length - commonOffset);
|
|
860
|
+
edit = commonString + edit.substring(0, edit.length - commonOffset);
|
|
861
|
+
equality2 = commonString + equality2;
|
|
862
|
+
}
|
|
863
|
+
let bestEquality1 = equality1;
|
|
864
|
+
let bestEdit = edit;
|
|
865
|
+
let bestEquality2 = equality2;
|
|
866
|
+
let bestScore = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
|
|
867
|
+
while(edit.charAt(0) === equality2.charAt(0)){
|
|
868
|
+
equality1 += edit.charAt(0);
|
|
869
|
+
edit = edit.substring(1) + equality2.charAt(0);
|
|
870
|
+
equality2 = equality2.substring(1);
|
|
871
|
+
const score = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
|
|
872
|
+
if (score >= bestScore) {
|
|
873
|
+
bestScore = score;
|
|
874
|
+
bestEquality1 = equality1;
|
|
875
|
+
bestEdit = edit;
|
|
876
|
+
bestEquality2 = equality2;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
if (diffs[pointer - 1][1] !== bestEquality1) {
|
|
880
|
+
if (bestEquality1) diffs[pointer - 1][1] = bestEquality1;
|
|
881
|
+
else {
|
|
882
|
+
diffs.splice(pointer - 1, 1);
|
|
883
|
+
pointer--;
|
|
884
|
+
}
|
|
885
|
+
diffs[pointer][1] = bestEdit;
|
|
886
|
+
if (bestEquality2) diffs[pointer + 1][1] = bestEquality2;
|
|
887
|
+
else {
|
|
888
|
+
diffs.splice(pointer + 1, 1);
|
|
889
|
+
pointer--;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
pointer++;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
function diff_cleanupMerge(diffs) {
|
|
897
|
+
diffs.push(new Diff(DIFF_EQUAL, ""));
|
|
898
|
+
let pointer = 0;
|
|
899
|
+
let count_delete = 0;
|
|
900
|
+
let count_insert = 0;
|
|
901
|
+
let text_delete = "";
|
|
902
|
+
let text_insert = "";
|
|
903
|
+
let commonlength;
|
|
904
|
+
while(pointer < diffs.length)switch(diffs[pointer][0]){
|
|
905
|
+
case DIFF_INSERT:
|
|
906
|
+
count_insert++;
|
|
907
|
+
text_insert += diffs[pointer][1];
|
|
908
|
+
pointer++;
|
|
909
|
+
break;
|
|
910
|
+
case DIFF_DELETE:
|
|
911
|
+
count_delete++;
|
|
912
|
+
text_delete += diffs[pointer][1];
|
|
913
|
+
pointer++;
|
|
914
|
+
break;
|
|
915
|
+
case DIFF_EQUAL:
|
|
916
|
+
if (count_delete + count_insert > 1) {
|
|
917
|
+
if (0 !== count_delete && 0 !== count_insert) {
|
|
918
|
+
commonlength = diff_commonPrefix(text_insert, text_delete);
|
|
919
|
+
if (0 !== commonlength) {
|
|
920
|
+
if (pointer - count_delete - count_insert > 0 && diffs[pointer - count_delete - count_insert - 1][0] === DIFF_EQUAL) diffs[pointer - count_delete - count_insert - 1][1] += text_insert.substring(0, commonlength);
|
|
921
|
+
else {
|
|
922
|
+
diffs.splice(0, 0, new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength)));
|
|
923
|
+
pointer++;
|
|
924
|
+
}
|
|
925
|
+
text_insert = text_insert.substring(commonlength);
|
|
926
|
+
text_delete = text_delete.substring(commonlength);
|
|
927
|
+
}
|
|
928
|
+
commonlength = diff_commonSuffix(text_insert, text_delete);
|
|
929
|
+
if (0 !== commonlength) {
|
|
930
|
+
diffs[pointer][1] = text_insert.substring(text_insert.length - commonlength) + diffs[pointer][1];
|
|
931
|
+
text_insert = text_insert.substring(0, text_insert.length - commonlength);
|
|
932
|
+
text_delete = text_delete.substring(0, text_delete.length - commonlength);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
pointer -= count_delete + count_insert;
|
|
936
|
+
diffs.splice(pointer, count_delete + count_insert);
|
|
937
|
+
if (text_delete.length) {
|
|
938
|
+
diffs.splice(pointer, 0, new Diff(DIFF_DELETE, text_delete));
|
|
939
|
+
pointer++;
|
|
940
|
+
}
|
|
941
|
+
if (text_insert.length) {
|
|
942
|
+
diffs.splice(pointer, 0, new Diff(DIFF_INSERT, text_insert));
|
|
943
|
+
pointer++;
|
|
944
|
+
}
|
|
945
|
+
pointer++;
|
|
946
|
+
} else if (0 !== pointer && diffs[pointer - 1][0] === DIFF_EQUAL) {
|
|
947
|
+
diffs[pointer - 1][1] += diffs[pointer][1];
|
|
948
|
+
diffs.splice(pointer, 1);
|
|
949
|
+
} else pointer++;
|
|
950
|
+
count_insert = 0;
|
|
951
|
+
count_delete = 0;
|
|
952
|
+
text_delete = "";
|
|
953
|
+
text_insert = "";
|
|
954
|
+
break;
|
|
955
|
+
}
|
|
956
|
+
if ("" === diffs[diffs.length - 1][1]) diffs.pop();
|
|
957
|
+
let changes = false;
|
|
958
|
+
pointer = 1;
|
|
959
|
+
while(pointer < diffs.length - 1){
|
|
960
|
+
if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
|
|
961
|
+
if (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1]) {
|
|
962
|
+
diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length);
|
|
963
|
+
diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
|
|
964
|
+
diffs.splice(pointer - 1, 1);
|
|
965
|
+
changes = true;
|
|
966
|
+
} else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1]) {
|
|
967
|
+
diffs[pointer - 1][1] += diffs[pointer + 1][1];
|
|
968
|
+
diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1];
|
|
969
|
+
diffs.splice(pointer + 1, 1);
|
|
970
|
+
changes = true;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
pointer++;
|
|
974
|
+
}
|
|
975
|
+
if (changes) diff_cleanupMerge(diffs);
|
|
976
|
+
}
|
|
977
|
+
function diff_cleanupSemanticScore_(one, two) {
|
|
978
|
+
if (!one || !two) return 6;
|
|
979
|
+
const char1 = one.charAt(one.length - 1);
|
|
980
|
+
const char2 = two.charAt(0);
|
|
981
|
+
const nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_);
|
|
982
|
+
const nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_);
|
|
983
|
+
const whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex_);
|
|
984
|
+
const whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex_);
|
|
985
|
+
const lineBreak1 = whitespace1 && char1.match(linebreakRegex_);
|
|
986
|
+
const lineBreak2 = whitespace2 && char2.match(linebreakRegex_);
|
|
987
|
+
const blankLine1 = lineBreak1 && one.match(blanklineEndRegex_);
|
|
988
|
+
const blankLine2 = lineBreak2 && two.match(blanklineStartRegex_);
|
|
989
|
+
if (blankLine1 || blankLine2) return 5;
|
|
990
|
+
if (lineBreak1 || lineBreak2) return 4;
|
|
991
|
+
if (nonAlphaNumeric1 && !whitespace1 && whitespace2) return 3;
|
|
992
|
+
if (whitespace1 || whitespace2) return 2;
|
|
993
|
+
if (nonAlphaNumeric1 || nonAlphaNumeric2) return 1;
|
|
994
|
+
return 0;
|
|
995
|
+
}
|
|
996
|
+
const NO_DIFF_MESSAGE = "Compared values have no visual difference.";
|
|
997
|
+
const SIMILAR_MESSAGE = "Compared values serialize to the same structure.\nPrinting internal object structure without calling `toJSON` instead.";
|
|
998
|
+
var build = {};
|
|
999
|
+
var hasRequiredBuild;
|
|
1000
|
+
function requireBuild() {
|
|
1001
|
+
if (hasRequiredBuild) return build;
|
|
1002
|
+
hasRequiredBuild = 1;
|
|
1003
|
+
Object.defineProperty(build, '__esModule', {
|
|
1004
|
+
value: true
|
|
1005
|
+
});
|
|
1006
|
+
build.default = diffSequence;
|
|
1007
|
+
const pkg = 'diff-sequences';
|
|
1008
|
+
const NOT_YET_SET = 0;
|
|
1009
|
+
const countCommonItemsF = (aIndex, aEnd, bIndex, bEnd, isCommon)=>{
|
|
1010
|
+
let nCommon = 0;
|
|
1011
|
+
while(aIndex < aEnd && bIndex < bEnd && isCommon(aIndex, bIndex)){
|
|
1012
|
+
aIndex += 1;
|
|
1013
|
+
bIndex += 1;
|
|
1014
|
+
nCommon += 1;
|
|
1015
|
+
}
|
|
1016
|
+
return nCommon;
|
|
1017
|
+
};
|
|
1018
|
+
const countCommonItemsR = (aStart, aIndex, bStart, bIndex, isCommon)=>{
|
|
1019
|
+
let nCommon = 0;
|
|
1020
|
+
while(aStart <= aIndex && bStart <= bIndex && isCommon(aIndex, bIndex)){
|
|
1021
|
+
aIndex -= 1;
|
|
1022
|
+
bIndex -= 1;
|
|
1023
|
+
nCommon += 1;
|
|
1024
|
+
}
|
|
1025
|
+
return nCommon;
|
|
1026
|
+
};
|
|
1027
|
+
const extendPathsF = (d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF)=>{
|
|
1028
|
+
let iF = 0;
|
|
1029
|
+
let kF = -d;
|
|
1030
|
+
let aFirst = aIndexesF[iF];
|
|
1031
|
+
let aIndexPrev1 = aFirst;
|
|
1032
|
+
aIndexesF[iF] += countCommonItemsF(aFirst + 1, aEnd, bF + aFirst - kF + 1, bEnd, isCommon);
|
|
1033
|
+
const nF = d < iMaxF ? d : iMaxF;
|
|
1034
|
+
for(iF += 1, kF += 2; iF <= nF; iF += 1, kF += 2){
|
|
1035
|
+
if (iF !== d && aIndexPrev1 < aIndexesF[iF]) aFirst = aIndexesF[iF];
|
|
1036
|
+
else {
|
|
1037
|
+
aFirst = aIndexPrev1 + 1;
|
|
1038
|
+
if (aEnd <= aFirst) return iF - 1;
|
|
1039
|
+
}
|
|
1040
|
+
aIndexPrev1 = aIndexesF[iF];
|
|
1041
|
+
aIndexesF[iF] = aFirst + countCommonItemsF(aFirst + 1, aEnd, bF + aFirst - kF + 1, bEnd, isCommon);
|
|
1042
|
+
}
|
|
1043
|
+
return iMaxF;
|
|
1044
|
+
};
|
|
1045
|
+
const extendPathsR = (d, aStart, bStart, bR, isCommon, aIndexesR, iMaxR)=>{
|
|
1046
|
+
let iR = 0;
|
|
1047
|
+
let kR = d;
|
|
1048
|
+
let aFirst = aIndexesR[iR];
|
|
1049
|
+
let aIndexPrev1 = aFirst;
|
|
1050
|
+
aIndexesR[iR] -= countCommonItemsR(aStart, aFirst - 1, bStart, bR + aFirst - kR - 1, isCommon);
|
|
1051
|
+
const nR = d < iMaxR ? d : iMaxR;
|
|
1052
|
+
for(iR += 1, kR -= 2; iR <= nR; iR += 1, kR -= 2){
|
|
1053
|
+
if (iR !== d && aIndexesR[iR] < aIndexPrev1) aFirst = aIndexesR[iR];
|
|
1054
|
+
else {
|
|
1055
|
+
aFirst = aIndexPrev1 - 1;
|
|
1056
|
+
if (aFirst < aStart) return iR - 1;
|
|
1057
|
+
}
|
|
1058
|
+
aIndexPrev1 = aIndexesR[iR];
|
|
1059
|
+
aIndexesR[iR] = aFirst - countCommonItemsR(aStart, aFirst - 1, bStart, bR + aFirst - kR - 1, isCommon);
|
|
1060
|
+
}
|
|
1061
|
+
return iMaxR;
|
|
1062
|
+
};
|
|
1063
|
+
const extendOverlappablePathsF = (d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division)=>{
|
|
1064
|
+
const bF = bStart - aStart;
|
|
1065
|
+
const aLength = aEnd - aStart;
|
|
1066
|
+
const bLength = bEnd - bStart;
|
|
1067
|
+
const baDeltaLength = bLength - aLength;
|
|
1068
|
+
const kMinOverlapF = -baDeltaLength - (d - 1);
|
|
1069
|
+
const kMaxOverlapF = -baDeltaLength + (d - 1);
|
|
1070
|
+
let aIndexPrev1 = NOT_YET_SET;
|
|
1071
|
+
const nF = d < iMaxF ? d : iMaxF;
|
|
1072
|
+
for(let iF = 0, kF = -d; iF <= nF; iF += 1, kF += 2){
|
|
1073
|
+
const insert = 0 === iF || iF !== d && aIndexPrev1 < aIndexesF[iF];
|
|
1074
|
+
const aLastPrev = insert ? aIndexesF[iF] : aIndexPrev1;
|
|
1075
|
+
const aFirst = insert ? aLastPrev : aLastPrev + 1;
|
|
1076
|
+
const bFirst = bF + aFirst - kF;
|
|
1077
|
+
const nCommonF = countCommonItemsF(aFirst + 1, aEnd, bFirst + 1, bEnd, isCommon);
|
|
1078
|
+
const aLast = aFirst + nCommonF;
|
|
1079
|
+
aIndexPrev1 = aIndexesF[iF];
|
|
1080
|
+
aIndexesF[iF] = aLast;
|
|
1081
|
+
if (kMinOverlapF <= kF && kF <= kMaxOverlapF) {
|
|
1082
|
+
const iR = (d - 1 - (kF + baDeltaLength)) / 2;
|
|
1083
|
+
if (iR <= iMaxR && aIndexesR[iR] - 1 <= aLast) {
|
|
1084
|
+
const bLastPrev = bF + aLastPrev - (insert ? kF + 1 : kF - 1);
|
|
1085
|
+
const nCommonR = countCommonItemsR(aStart, aLastPrev, bStart, bLastPrev, isCommon);
|
|
1086
|
+
const aIndexPrevFirst = aLastPrev - nCommonR;
|
|
1087
|
+
const bIndexPrevFirst = bLastPrev - nCommonR;
|
|
1088
|
+
const aEndPreceding = aIndexPrevFirst + 1;
|
|
1089
|
+
const bEndPreceding = bIndexPrevFirst + 1;
|
|
1090
|
+
division.nChangePreceding = d - 1;
|
|
1091
|
+
if (d - 1 === aEndPreceding + bEndPreceding - aStart - bStart) {
|
|
1092
|
+
division.aEndPreceding = aStart;
|
|
1093
|
+
division.bEndPreceding = bStart;
|
|
1094
|
+
} else {
|
|
1095
|
+
division.aEndPreceding = aEndPreceding;
|
|
1096
|
+
division.bEndPreceding = bEndPreceding;
|
|
1097
|
+
}
|
|
1098
|
+
division.nCommonPreceding = nCommonR;
|
|
1099
|
+
if (0 !== nCommonR) {
|
|
1100
|
+
division.aCommonPreceding = aEndPreceding;
|
|
1101
|
+
division.bCommonPreceding = bEndPreceding;
|
|
1102
|
+
}
|
|
1103
|
+
division.nCommonFollowing = nCommonF;
|
|
1104
|
+
if (0 !== nCommonF) {
|
|
1105
|
+
division.aCommonFollowing = aFirst + 1;
|
|
1106
|
+
division.bCommonFollowing = bFirst + 1;
|
|
1107
|
+
}
|
|
1108
|
+
const aStartFollowing = aLast + 1;
|
|
1109
|
+
const bStartFollowing = bFirst + nCommonF + 1;
|
|
1110
|
+
division.nChangeFollowing = d - 1;
|
|
1111
|
+
if (d - 1 === aEnd + bEnd - aStartFollowing - bStartFollowing) {
|
|
1112
|
+
division.aStartFollowing = aEnd;
|
|
1113
|
+
division.bStartFollowing = bEnd;
|
|
1114
|
+
} else {
|
|
1115
|
+
division.aStartFollowing = aStartFollowing;
|
|
1116
|
+
division.bStartFollowing = bStartFollowing;
|
|
1117
|
+
}
|
|
1118
|
+
return true;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
return false;
|
|
1123
|
+
};
|
|
1124
|
+
const extendOverlappablePathsR = (d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division)=>{
|
|
1125
|
+
const bR = bEnd - aEnd;
|
|
1126
|
+
const aLength = aEnd - aStart;
|
|
1127
|
+
const bLength = bEnd - bStart;
|
|
1128
|
+
const baDeltaLength = bLength - aLength;
|
|
1129
|
+
const kMinOverlapR = baDeltaLength - d;
|
|
1130
|
+
const kMaxOverlapR = baDeltaLength + d;
|
|
1131
|
+
let aIndexPrev1 = NOT_YET_SET;
|
|
1132
|
+
const nR = d < iMaxR ? d : iMaxR;
|
|
1133
|
+
for(let iR = 0, kR = d; iR <= nR; iR += 1, kR -= 2){
|
|
1134
|
+
const insert = 0 === iR || iR !== d && aIndexesR[iR] < aIndexPrev1;
|
|
1135
|
+
const aLastPrev = insert ? aIndexesR[iR] : aIndexPrev1;
|
|
1136
|
+
const aFirst = insert ? aLastPrev : aLastPrev - 1;
|
|
1137
|
+
const bFirst = bR + aFirst - kR;
|
|
1138
|
+
const nCommonR = countCommonItemsR(aStart, aFirst - 1, bStart, bFirst - 1, isCommon);
|
|
1139
|
+
const aLast = aFirst - nCommonR;
|
|
1140
|
+
aIndexPrev1 = aIndexesR[iR];
|
|
1141
|
+
aIndexesR[iR] = aLast;
|
|
1142
|
+
if (kMinOverlapR <= kR && kR <= kMaxOverlapR) {
|
|
1143
|
+
const iF = (d + (kR - baDeltaLength)) / 2;
|
|
1144
|
+
if (iF <= iMaxF && aLast - 1 <= aIndexesF[iF]) {
|
|
1145
|
+
const bLast = bFirst - nCommonR;
|
|
1146
|
+
division.nChangePreceding = d;
|
|
1147
|
+
if (d === aLast + bLast - aStart - bStart) {
|
|
1148
|
+
division.aEndPreceding = aStart;
|
|
1149
|
+
division.bEndPreceding = bStart;
|
|
1150
|
+
} else {
|
|
1151
|
+
division.aEndPreceding = aLast;
|
|
1152
|
+
division.bEndPreceding = bLast;
|
|
1153
|
+
}
|
|
1154
|
+
division.nCommonPreceding = nCommonR;
|
|
1155
|
+
if (0 !== nCommonR) {
|
|
1156
|
+
division.aCommonPreceding = aLast;
|
|
1157
|
+
division.bCommonPreceding = bLast;
|
|
1158
|
+
}
|
|
1159
|
+
division.nChangeFollowing = d - 1;
|
|
1160
|
+
if (1 === d) {
|
|
1161
|
+
division.nCommonFollowing = 0;
|
|
1162
|
+
division.aStartFollowing = aEnd;
|
|
1163
|
+
division.bStartFollowing = bEnd;
|
|
1164
|
+
} else {
|
|
1165
|
+
const bLastPrev = bR + aLastPrev - (insert ? kR - 1 : kR + 1);
|
|
1166
|
+
const nCommonF = countCommonItemsF(aLastPrev, aEnd, bLastPrev, bEnd, isCommon);
|
|
1167
|
+
division.nCommonFollowing = nCommonF;
|
|
1168
|
+
if (0 !== nCommonF) {
|
|
1169
|
+
division.aCommonFollowing = aLastPrev;
|
|
1170
|
+
division.bCommonFollowing = bLastPrev;
|
|
1171
|
+
}
|
|
1172
|
+
const aStartFollowing = aLastPrev + nCommonF;
|
|
1173
|
+
const bStartFollowing = bLastPrev + nCommonF;
|
|
1174
|
+
if (d - 1 === aEnd + bEnd - aStartFollowing - bStartFollowing) {
|
|
1175
|
+
division.aStartFollowing = aEnd;
|
|
1176
|
+
division.bStartFollowing = bEnd;
|
|
1177
|
+
} else {
|
|
1178
|
+
division.aStartFollowing = aStartFollowing;
|
|
1179
|
+
division.bStartFollowing = bStartFollowing;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
return true;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
return false;
|
|
1187
|
+
};
|
|
1188
|
+
const divide = (nChange, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, aIndexesR, division)=>{
|
|
1189
|
+
const bF = bStart - aStart;
|
|
1190
|
+
const bR = bEnd - aEnd;
|
|
1191
|
+
const aLength = aEnd - aStart;
|
|
1192
|
+
const bLength = bEnd - bStart;
|
|
1193
|
+
const baDeltaLength = bLength - aLength;
|
|
1194
|
+
let iMaxF = aLength;
|
|
1195
|
+
let iMaxR = aLength;
|
|
1196
|
+
aIndexesF[0] = aStart - 1;
|
|
1197
|
+
aIndexesR[0] = aEnd;
|
|
1198
|
+
if (baDeltaLength % 2 === 0) {
|
|
1199
|
+
const dMin = (nChange || baDeltaLength) / 2;
|
|
1200
|
+
const dMax = (aLength + bLength) / 2;
|
|
1201
|
+
for(let d = 1; d <= dMax; d += 1){
|
|
1202
|
+
iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
|
|
1203
|
+
if (d < dMin) iMaxR = extendPathsR(d, aStart, bStart, bR, isCommon, aIndexesR, iMaxR);
|
|
1204
|
+
else if (extendOverlappablePathsR(d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division)) return;
|
|
1205
|
+
}
|
|
1206
|
+
} else {
|
|
1207
|
+
const dMin = ((nChange || baDeltaLength) + 1) / 2;
|
|
1208
|
+
const dMax = (aLength + bLength + 1) / 2;
|
|
1209
|
+
let d = 1;
|
|
1210
|
+
iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
|
|
1211
|
+
for(d += 1; d <= dMax; d += 1){
|
|
1212
|
+
iMaxR = extendPathsR(d - 1, aStart, bStart, bR, isCommon, aIndexesR, iMaxR);
|
|
1213
|
+
if (d < dMin) iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
|
|
1214
|
+
else if (extendOverlappablePathsF(d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division)) return;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
throw new Error(`${pkg}: no overlap aStart=${aStart} aEnd=${aEnd} bStart=${bStart} bEnd=${bEnd}`);
|
|
1218
|
+
};
|
|
1219
|
+
const findSubsequences = (nChange, aStart, aEnd, bStart, bEnd, transposed, callbacks, aIndexesF, aIndexesR, division)=>{
|
|
1220
|
+
if (bEnd - bStart < aEnd - aStart) {
|
|
1221
|
+
transposed = !transposed;
|
|
1222
|
+
if (transposed && 1 === callbacks.length) {
|
|
1223
|
+
const { foundSubsequence, isCommon } = callbacks[0];
|
|
1224
|
+
callbacks[1] = {
|
|
1225
|
+
foundSubsequence: (nCommon, bCommon, aCommon)=>{
|
|
1226
|
+
foundSubsequence(nCommon, aCommon, bCommon);
|
|
1227
|
+
},
|
|
1228
|
+
isCommon: (bIndex, aIndex)=>isCommon(aIndex, bIndex)
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
const tStart = aStart;
|
|
1232
|
+
const tEnd = aEnd;
|
|
1233
|
+
aStart = bStart;
|
|
1234
|
+
aEnd = bEnd;
|
|
1235
|
+
bStart = tStart;
|
|
1236
|
+
bEnd = tEnd;
|
|
1237
|
+
}
|
|
1238
|
+
const { foundSubsequence, isCommon } = callbacks[transposed ? 1 : 0];
|
|
1239
|
+
divide(nChange, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, aIndexesR, division);
|
|
1240
|
+
const { nChangePreceding, aEndPreceding, bEndPreceding, nCommonPreceding, aCommonPreceding, bCommonPreceding, nCommonFollowing, aCommonFollowing, bCommonFollowing, nChangeFollowing, aStartFollowing, bStartFollowing } = division;
|
|
1241
|
+
if (aStart < aEndPreceding && bStart < bEndPreceding) findSubsequences(nChangePreceding, aStart, aEndPreceding, bStart, bEndPreceding, transposed, callbacks, aIndexesF, aIndexesR, division);
|
|
1242
|
+
if (0 !== nCommonPreceding) foundSubsequence(nCommonPreceding, aCommonPreceding, bCommonPreceding);
|
|
1243
|
+
if (0 !== nCommonFollowing) foundSubsequence(nCommonFollowing, aCommonFollowing, bCommonFollowing);
|
|
1244
|
+
if (aStartFollowing < aEnd && bStartFollowing < bEnd) findSubsequences(nChangeFollowing, aStartFollowing, aEnd, bStartFollowing, bEnd, transposed, callbacks, aIndexesF, aIndexesR, division);
|
|
1245
|
+
};
|
|
1246
|
+
const validateLength = (name, arg)=>{
|
|
1247
|
+
if ('number' != typeof arg) throw new TypeError(`${pkg}: ${name} typeof ${typeof arg} is not a number`);
|
|
1248
|
+
if (!Number.isSafeInteger(arg)) throw new RangeError(`${pkg}: ${name} value ${arg} is not a safe integer`);
|
|
1249
|
+
if (arg < 0) throw new RangeError(`${pkg}: ${name} value ${arg} is a negative integer`);
|
|
1250
|
+
};
|
|
1251
|
+
const validateCallback = (name, arg)=>{
|
|
1252
|
+
const type = typeof arg;
|
|
1253
|
+
if ('function' !== type) throw new TypeError(`${pkg}: ${name} typeof ${type} is not a function`);
|
|
1254
|
+
};
|
|
1255
|
+
function diffSequence(aLength, bLength, isCommon, foundSubsequence) {
|
|
1256
|
+
validateLength('aLength', aLength);
|
|
1257
|
+
validateLength('bLength', bLength);
|
|
1258
|
+
validateCallback('isCommon', isCommon);
|
|
1259
|
+
validateCallback('foundSubsequence', foundSubsequence);
|
|
1260
|
+
const nCommonF = countCommonItemsF(0, aLength, 0, bLength, isCommon);
|
|
1261
|
+
if (0 !== nCommonF) foundSubsequence(nCommonF, 0, 0);
|
|
1262
|
+
if (aLength !== nCommonF || bLength !== nCommonF) {
|
|
1263
|
+
const aStart = nCommonF;
|
|
1264
|
+
const bStart = nCommonF;
|
|
1265
|
+
const nCommonR = countCommonItemsR(aStart, aLength - 1, bStart, bLength - 1, isCommon);
|
|
1266
|
+
const aEnd = aLength - nCommonR;
|
|
1267
|
+
const bEnd = bLength - nCommonR;
|
|
1268
|
+
const nCommonFR = nCommonF + nCommonR;
|
|
1269
|
+
if (aLength !== nCommonFR && bLength !== nCommonFR) {
|
|
1270
|
+
const nChange = 0;
|
|
1271
|
+
const transposed = false;
|
|
1272
|
+
const callbacks = [
|
|
1273
|
+
{
|
|
1274
|
+
foundSubsequence,
|
|
1275
|
+
isCommon
|
|
1276
|
+
}
|
|
1277
|
+
];
|
|
1278
|
+
const aIndexesF = [
|
|
1279
|
+
NOT_YET_SET
|
|
1280
|
+
];
|
|
1281
|
+
const aIndexesR = [
|
|
1282
|
+
NOT_YET_SET
|
|
1283
|
+
];
|
|
1284
|
+
const division = {
|
|
1285
|
+
aCommonFollowing: NOT_YET_SET,
|
|
1286
|
+
aCommonPreceding: NOT_YET_SET,
|
|
1287
|
+
aEndPreceding: NOT_YET_SET,
|
|
1288
|
+
aStartFollowing: NOT_YET_SET,
|
|
1289
|
+
bCommonFollowing: NOT_YET_SET,
|
|
1290
|
+
bCommonPreceding: NOT_YET_SET,
|
|
1291
|
+
bEndPreceding: NOT_YET_SET,
|
|
1292
|
+
bStartFollowing: NOT_YET_SET,
|
|
1293
|
+
nChangeFollowing: NOT_YET_SET,
|
|
1294
|
+
nChangePreceding: NOT_YET_SET,
|
|
1295
|
+
nCommonFollowing: NOT_YET_SET,
|
|
1296
|
+
nCommonPreceding: NOT_YET_SET
|
|
1297
|
+
};
|
|
1298
|
+
findSubsequences(nChange, aStart, aEnd, bStart, bEnd, transposed, callbacks, aIndexesF, aIndexesR, division);
|
|
1299
|
+
}
|
|
1300
|
+
if (0 !== nCommonR) foundSubsequence(nCommonR, aEnd, bEnd);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
return build;
|
|
1304
|
+
}
|
|
1305
|
+
var buildExports = requireBuild();
|
|
1306
|
+
var diffSequences = /*@__PURE__*/ getDefaultExportFromCjs(buildExports);
|
|
1307
|
+
function formatTrailingSpaces(line, trailingSpaceFormatter) {
|
|
1308
|
+
return line.replace(/\s+$/, (match)=>trailingSpaceFormatter(match));
|
|
1309
|
+
}
|
|
1310
|
+
function printDiffLine(line, isFirstOrLast, color, indicator, trailingSpaceFormatter, emptyFirstOrLastLinePlaceholder) {
|
|
1311
|
+
return 0 !== line.length ? color(`${indicator} ${formatTrailingSpaces(line, trailingSpaceFormatter)}`) : " " !== indicator ? color(indicator) : isFirstOrLast && 0 !== emptyFirstOrLastLinePlaceholder.length ? color(`${indicator} ${emptyFirstOrLastLinePlaceholder}`) : "";
|
|
1312
|
+
}
|
|
1313
|
+
function printDeleteLine(line, isFirstOrLast, { aColor, aIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
|
|
1314
|
+
return printDiffLine(line, isFirstOrLast, aColor, aIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
|
|
1315
|
+
}
|
|
1316
|
+
function printInsertLine(line, isFirstOrLast, { bColor, bIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
|
|
1317
|
+
return printDiffLine(line, isFirstOrLast, bColor, bIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
|
|
1318
|
+
}
|
|
1319
|
+
function printCommonLine(line, isFirstOrLast, { commonColor, commonIndicator, commonLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
|
|
1320
|
+
return printDiffLine(line, isFirstOrLast, commonColor, commonIndicator, commonLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
|
|
1321
|
+
}
|
|
1322
|
+
function createPatchMark(aStart, aEnd, bStart, bEnd, { patchColor }) {
|
|
1323
|
+
return patchColor(`@@ -${aStart + 1},${aEnd - aStart} +${bStart + 1},${bEnd - bStart} @@`);
|
|
1324
|
+
}
|
|
1325
|
+
function joinAlignedDiffsNoExpand(diffs, options) {
|
|
1326
|
+
const iLength = diffs.length;
|
|
1327
|
+
const nContextLines = options.contextLines;
|
|
1328
|
+
const nContextLines2 = nContextLines + nContextLines;
|
|
1329
|
+
let jLength = iLength;
|
|
1330
|
+
let hasExcessAtStartOrEnd = false;
|
|
1331
|
+
let nExcessesBetweenChanges = 0;
|
|
1332
|
+
let i = 0;
|
|
1333
|
+
while(i !== iLength){
|
|
1334
|
+
const iStart = i;
|
|
1335
|
+
while(i !== iLength && diffs[i][0] === DIFF_EQUAL)i += 1;
|
|
1336
|
+
if (iStart !== i) if (0 === iStart) {
|
|
1337
|
+
if (i > nContextLines) {
|
|
1338
|
+
jLength -= i - nContextLines;
|
|
1339
|
+
hasExcessAtStartOrEnd = true;
|
|
1340
|
+
}
|
|
1341
|
+
} else if (i === iLength) {
|
|
1342
|
+
const n = i - iStart;
|
|
1343
|
+
if (n > nContextLines) {
|
|
1344
|
+
jLength -= n - nContextLines;
|
|
1345
|
+
hasExcessAtStartOrEnd = true;
|
|
1346
|
+
}
|
|
1347
|
+
} else {
|
|
1348
|
+
const n = i - iStart;
|
|
1349
|
+
if (n > nContextLines2) {
|
|
1350
|
+
jLength -= n - nContextLines2;
|
|
1351
|
+
nExcessesBetweenChanges += 1;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
while(i !== iLength && diffs[i][0] !== DIFF_EQUAL)i += 1;
|
|
1355
|
+
}
|
|
1356
|
+
const hasPatch = 0 !== nExcessesBetweenChanges || hasExcessAtStartOrEnd;
|
|
1357
|
+
if (0 !== nExcessesBetweenChanges) jLength += nExcessesBetweenChanges + 1;
|
|
1358
|
+
else if (hasExcessAtStartOrEnd) jLength += 1;
|
|
1359
|
+
const jLast = jLength - 1;
|
|
1360
|
+
const lines = [];
|
|
1361
|
+
let jPatchMark = 0;
|
|
1362
|
+
if (hasPatch) lines.push("");
|
|
1363
|
+
let aStart = 0;
|
|
1364
|
+
let bStart = 0;
|
|
1365
|
+
let aEnd = 0;
|
|
1366
|
+
let bEnd = 0;
|
|
1367
|
+
const pushCommonLine = (line)=>{
|
|
1368
|
+
const j = lines.length;
|
|
1369
|
+
lines.push(printCommonLine(line, 0 === j || j === jLast, options));
|
|
1370
|
+
aEnd += 1;
|
|
1371
|
+
bEnd += 1;
|
|
1372
|
+
};
|
|
1373
|
+
const pushDeleteLine = (line)=>{
|
|
1374
|
+
const j = lines.length;
|
|
1375
|
+
lines.push(printDeleteLine(line, 0 === j || j === jLast, options));
|
|
1376
|
+
aEnd += 1;
|
|
1377
|
+
};
|
|
1378
|
+
const pushInsertLine = (line)=>{
|
|
1379
|
+
const j = lines.length;
|
|
1380
|
+
lines.push(printInsertLine(line, 0 === j || j === jLast, options));
|
|
1381
|
+
bEnd += 1;
|
|
1382
|
+
};
|
|
1383
|
+
i = 0;
|
|
1384
|
+
while(i !== iLength){
|
|
1385
|
+
let iStart = i;
|
|
1386
|
+
while(i !== iLength && diffs[i][0] === DIFF_EQUAL)i += 1;
|
|
1387
|
+
if (iStart !== i) if (0 === iStart) {
|
|
1388
|
+
if (i > nContextLines) {
|
|
1389
|
+
iStart = i - nContextLines;
|
|
1390
|
+
aStart = iStart;
|
|
1391
|
+
bStart = iStart;
|
|
1392
|
+
aEnd = aStart;
|
|
1393
|
+
bEnd = bStart;
|
|
1394
|
+
}
|
|
1395
|
+
for(let iCommon = iStart; iCommon !== i; iCommon += 1)pushCommonLine(diffs[iCommon][1]);
|
|
1396
|
+
} else if (i === iLength) {
|
|
1397
|
+
const iEnd = i - iStart > nContextLines ? iStart + nContextLines : i;
|
|
1398
|
+
for(let iCommon = iStart; iCommon !== iEnd; iCommon += 1)pushCommonLine(diffs[iCommon][1]);
|
|
1399
|
+
} else {
|
|
1400
|
+
const nCommon = i - iStart;
|
|
1401
|
+
if (nCommon > nContextLines2) {
|
|
1402
|
+
const iEnd = iStart + nContextLines;
|
|
1403
|
+
for(let iCommon = iStart; iCommon !== iEnd; iCommon += 1)pushCommonLine(diffs[iCommon][1]);
|
|
1404
|
+
lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
|
|
1405
|
+
jPatchMark = lines.length;
|
|
1406
|
+
lines.push("");
|
|
1407
|
+
const nOmit = nCommon - nContextLines2;
|
|
1408
|
+
aStart = aEnd + nOmit;
|
|
1409
|
+
bStart = bEnd + nOmit;
|
|
1410
|
+
aEnd = aStart;
|
|
1411
|
+
bEnd = bStart;
|
|
1412
|
+
for(let iCommon = i - nContextLines; iCommon !== i; iCommon += 1)pushCommonLine(diffs[iCommon][1]);
|
|
1413
|
+
} else for(let iCommon = iStart; iCommon !== i; iCommon += 1)pushCommonLine(diffs[iCommon][1]);
|
|
1414
|
+
}
|
|
1415
|
+
while(i !== iLength && diffs[i][0] === DIFF_DELETE){
|
|
1416
|
+
pushDeleteLine(diffs[i][1]);
|
|
1417
|
+
i += 1;
|
|
1418
|
+
}
|
|
1419
|
+
while(i !== iLength && diffs[i][0] === DIFF_INSERT){
|
|
1420
|
+
pushInsertLine(diffs[i][1]);
|
|
1421
|
+
i += 1;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
if (hasPatch) lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
|
|
1425
|
+
return lines.join("\n");
|
|
1426
|
+
}
|
|
1427
|
+
function joinAlignedDiffsExpand(diffs, options) {
|
|
1428
|
+
return diffs.map((diff, i, diffs)=>{
|
|
1429
|
+
const line = diff[1];
|
|
1430
|
+
const isFirstOrLast = 0 === i || i === diffs.length - 1;
|
|
1431
|
+
switch(diff[0]){
|
|
1432
|
+
case DIFF_DELETE:
|
|
1433
|
+
return printDeleteLine(line, isFirstOrLast, options);
|
|
1434
|
+
case DIFF_INSERT:
|
|
1435
|
+
return printInsertLine(line, isFirstOrLast, options);
|
|
1436
|
+
default:
|
|
1437
|
+
return printCommonLine(line, isFirstOrLast, options);
|
|
1438
|
+
}
|
|
1439
|
+
}).join("\n");
|
|
1440
|
+
}
|
|
1441
|
+
const noColor = (string)=>string;
|
|
1442
|
+
const DIFF_CONTEXT_DEFAULT = 5;
|
|
1443
|
+
const DIFF_TRUNCATE_THRESHOLD_DEFAULT = 0;
|
|
1444
|
+
function getDefaultOptions() {
|
|
1445
|
+
return {
|
|
1446
|
+
aAnnotation: "Expected",
|
|
1447
|
+
aColor: node_u.green,
|
|
1448
|
+
aIndicator: "-",
|
|
1449
|
+
bAnnotation: "Received",
|
|
1450
|
+
bColor: node_u.red,
|
|
1451
|
+
bIndicator: "+",
|
|
1452
|
+
changeColor: node_u.inverse,
|
|
1453
|
+
changeLineTrailingSpaceColor: noColor,
|
|
1454
|
+
commonColor: node_u.dim,
|
|
1455
|
+
commonIndicator: " ",
|
|
1456
|
+
commonLineTrailingSpaceColor: noColor,
|
|
1457
|
+
compareKeys: void 0,
|
|
1458
|
+
contextLines: DIFF_CONTEXT_DEFAULT,
|
|
1459
|
+
emptyFirstOrLastLinePlaceholder: "",
|
|
1460
|
+
expand: false,
|
|
1461
|
+
includeChangeCounts: false,
|
|
1462
|
+
omitAnnotationLines: false,
|
|
1463
|
+
patchColor: node_u.yellow,
|
|
1464
|
+
printBasicPrototype: false,
|
|
1465
|
+
truncateThreshold: DIFF_TRUNCATE_THRESHOLD_DEFAULT,
|
|
1466
|
+
truncateAnnotation: "... Diff result is truncated",
|
|
1467
|
+
truncateAnnotationColor: noColor
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
function getCompareKeys(compareKeys) {
|
|
1471
|
+
return compareKeys && "function" == typeof compareKeys ? compareKeys : void 0;
|
|
1472
|
+
}
|
|
1473
|
+
function getContextLines(contextLines) {
|
|
1474
|
+
return "number" == typeof contextLines && Number.isSafeInteger(contextLines) && contextLines >= 0 ? contextLines : DIFF_CONTEXT_DEFAULT;
|
|
1475
|
+
}
|
|
1476
|
+
function normalizeDiffOptions(options = {}) {
|
|
1477
|
+
return {
|
|
1478
|
+
...getDefaultOptions(),
|
|
1479
|
+
...options,
|
|
1480
|
+
compareKeys: getCompareKeys(options.compareKeys),
|
|
1481
|
+
contextLines: getContextLines(options.contextLines)
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
function isEmptyString(lines) {
|
|
1485
|
+
return 1 === lines.length && 0 === lines[0].length;
|
|
1486
|
+
}
|
|
1487
|
+
function countChanges(diffs) {
|
|
1488
|
+
let a = 0;
|
|
1489
|
+
let b = 0;
|
|
1490
|
+
diffs.forEach((diff)=>{
|
|
1491
|
+
switch(diff[0]){
|
|
1492
|
+
case DIFF_DELETE:
|
|
1493
|
+
a += 1;
|
|
1494
|
+
break;
|
|
1495
|
+
case DIFF_INSERT:
|
|
1496
|
+
b += 1;
|
|
1497
|
+
break;
|
|
1498
|
+
}
|
|
1499
|
+
});
|
|
1500
|
+
return {
|
|
1501
|
+
a,
|
|
1502
|
+
b
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
function printAnnotation({ aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator, includeChangeCounts, omitAnnotationLines }, changeCounts) {
|
|
1506
|
+
if (omitAnnotationLines) return "";
|
|
1507
|
+
let aRest = "";
|
|
1508
|
+
let bRest = "";
|
|
1509
|
+
if (includeChangeCounts) {
|
|
1510
|
+
const aCount = String(changeCounts.a);
|
|
1511
|
+
const bCount = String(changeCounts.b);
|
|
1512
|
+
const baAnnotationLengthDiff = bAnnotation.length - aAnnotation.length;
|
|
1513
|
+
const aAnnotationPadding = " ".repeat(Math.max(0, baAnnotationLengthDiff));
|
|
1514
|
+
const bAnnotationPadding = " ".repeat(Math.max(0, -baAnnotationLengthDiff));
|
|
1515
|
+
const baCountLengthDiff = bCount.length - aCount.length;
|
|
1516
|
+
const aCountPadding = " ".repeat(Math.max(0, baCountLengthDiff));
|
|
1517
|
+
const bCountPadding = " ".repeat(Math.max(0, -baCountLengthDiff));
|
|
1518
|
+
aRest = `${aAnnotationPadding} ${aIndicator} ${aCountPadding}${aCount}`;
|
|
1519
|
+
bRest = `${bAnnotationPadding} ${bIndicator} ${bCountPadding}${bCount}`;
|
|
1520
|
+
}
|
|
1521
|
+
const a = `${aIndicator} ${aAnnotation}${aRest}`;
|
|
1522
|
+
const b = `${bIndicator} ${bAnnotation}${bRest}`;
|
|
1523
|
+
return `${aColor(a)}\n${bColor(b)}\n\n`;
|
|
1524
|
+
}
|
|
1525
|
+
function printDiffLines(diffs, truncated, options) {
|
|
1526
|
+
return printAnnotation(options, countChanges(diffs)) + (options.expand ? joinAlignedDiffsExpand(diffs, options) : joinAlignedDiffsNoExpand(diffs, options)) + (truncated ? options.truncateAnnotationColor(`\n${options.truncateAnnotation}`) : "");
|
|
1527
|
+
}
|
|
1528
|
+
function diffLinesUnified(aLines, bLines, options) {
|
|
1529
|
+
const normalizedOptions = normalizeDiffOptions(options);
|
|
1530
|
+
const [diffs, truncated] = diffLinesRaw(isEmptyString(aLines) ? [] : aLines, isEmptyString(bLines) ? [] : bLines, normalizedOptions);
|
|
1531
|
+
return printDiffLines(diffs, truncated, normalizedOptions);
|
|
1532
|
+
}
|
|
1533
|
+
function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCompare, options) {
|
|
1534
|
+
if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
|
|
1535
|
+
aLinesDisplay = [];
|
|
1536
|
+
aLinesCompare = [];
|
|
1537
|
+
}
|
|
1538
|
+
if (isEmptyString(bLinesDisplay) && isEmptyString(bLinesCompare)) {
|
|
1539
|
+
bLinesDisplay = [];
|
|
1540
|
+
bLinesCompare = [];
|
|
1541
|
+
}
|
|
1542
|
+
if (aLinesDisplay.length !== aLinesCompare.length || bLinesDisplay.length !== bLinesCompare.length) return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
|
|
1543
|
+
const [diffs, truncated] = diffLinesRaw(aLinesCompare, bLinesCompare, options);
|
|
1544
|
+
let aIndex = 0;
|
|
1545
|
+
let bIndex = 0;
|
|
1546
|
+
diffs.forEach((diff)=>{
|
|
1547
|
+
switch(diff[0]){
|
|
1548
|
+
case DIFF_DELETE:
|
|
1549
|
+
diff[1] = aLinesDisplay[aIndex];
|
|
1550
|
+
aIndex += 1;
|
|
1551
|
+
break;
|
|
1552
|
+
case DIFF_INSERT:
|
|
1553
|
+
diff[1] = bLinesDisplay[bIndex];
|
|
1554
|
+
bIndex += 1;
|
|
1555
|
+
break;
|
|
1556
|
+
default:
|
|
1557
|
+
diff[1] = bLinesDisplay[bIndex];
|
|
1558
|
+
aIndex += 1;
|
|
1559
|
+
bIndex += 1;
|
|
1560
|
+
}
|
|
1561
|
+
});
|
|
1562
|
+
return printDiffLines(diffs, truncated, normalizeDiffOptions(options));
|
|
1563
|
+
}
|
|
1564
|
+
function diffLinesRaw(aLines, bLines, options) {
|
|
1565
|
+
const truncate = (null == options ? void 0 : options.truncateThreshold) ?? false;
|
|
1566
|
+
const truncateThreshold = Math.max(Math.floor((null == options ? void 0 : options.truncateThreshold) ?? 0), 0);
|
|
1567
|
+
const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
|
|
1568
|
+
const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
|
|
1569
|
+
const truncated = aLength !== aLines.length || bLength !== bLines.length;
|
|
1570
|
+
const isCommon = (aIndex, bIndex)=>aLines[aIndex] === bLines[bIndex];
|
|
1571
|
+
const diffs = [];
|
|
1572
|
+
let aIndex = 0;
|
|
1573
|
+
let bIndex = 0;
|
|
1574
|
+
const foundSubsequence = (nCommon, aCommon, bCommon)=>{
|
|
1575
|
+
for(; aIndex !== aCommon; aIndex += 1)diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
|
|
1576
|
+
for(; bIndex !== bCommon; bIndex += 1)diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
|
|
1577
|
+
for(; 0 !== nCommon; nCommon -= 1, aIndex += 1, bIndex += 1)diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
|
|
1578
|
+
};
|
|
1579
|
+
diffSequences(aLength, bLength, isCommon, foundSubsequence);
|
|
1580
|
+
for(; aIndex !== aLength; aIndex += 1)diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
|
|
1581
|
+
for(; bIndex !== bLength; bIndex += 1)diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
|
|
1582
|
+
return [
|
|
1583
|
+
diffs,
|
|
1584
|
+
truncated
|
|
1585
|
+
];
|
|
1586
|
+
}
|
|
1587
|
+
function diff_getType(value) {
|
|
1588
|
+
if (void 0 === value) return "undefined";
|
|
1589
|
+
if (null === value) return "null";
|
|
1590
|
+
if (Array.isArray(value)) return "array";
|
|
1591
|
+
if ("boolean" == typeof value) return "boolean";
|
|
1592
|
+
if ("function" == typeof value) return "function";
|
|
1593
|
+
else if ("number" == typeof value) return "number";
|
|
1594
|
+
else if ("string" == typeof value) return "string";
|
|
1595
|
+
else if ("bigint" == typeof value) return "bigint";
|
|
1596
|
+
else if ("object" == typeof value) {
|
|
1597
|
+
if (null != value) {
|
|
1598
|
+
if (value.constructor === RegExp) return "regexp";
|
|
1599
|
+
else if (value.constructor === Map) return "map";
|
|
1600
|
+
else if (value.constructor === Set) return "set";
|
|
1601
|
+
else if (value.constructor === Date) return "date";
|
|
1602
|
+
}
|
|
1603
|
+
return "object";
|
|
1604
|
+
} else if ("symbol" == typeof value) return "symbol";
|
|
1605
|
+
throw new Error(`value of unknown type: ${value}`);
|
|
1606
|
+
}
|
|
1607
|
+
function getNewLineSymbol(string) {
|
|
1608
|
+
return string.includes("\r\n") ? "\r\n" : "\n";
|
|
1609
|
+
}
|
|
1610
|
+
function diffStrings(a, b, options) {
|
|
1611
|
+
const truncate = (null == options ? void 0 : options.truncateThreshold) ?? false;
|
|
1612
|
+
const truncateThreshold = Math.max(Math.floor((null == options ? void 0 : options.truncateThreshold) ?? 0), 0);
|
|
1613
|
+
let aLength = a.length;
|
|
1614
|
+
let bLength = b.length;
|
|
1615
|
+
if (truncate) {
|
|
1616
|
+
const aMultipleLines = a.includes("\n");
|
|
1617
|
+
const bMultipleLines = b.includes("\n");
|
|
1618
|
+
const aNewLineSymbol = getNewLineSymbol(a);
|
|
1619
|
+
const bNewLineSymbol = getNewLineSymbol(b);
|
|
1620
|
+
const _a = aMultipleLines ? `${a.split(aNewLineSymbol, truncateThreshold).join(aNewLineSymbol)}\n` : a;
|
|
1621
|
+
const _b = bMultipleLines ? `${b.split(bNewLineSymbol, truncateThreshold).join(bNewLineSymbol)}\n` : b;
|
|
1622
|
+
aLength = _a.length;
|
|
1623
|
+
bLength = _b.length;
|
|
1624
|
+
}
|
|
1625
|
+
const truncated = aLength !== a.length || bLength !== b.length;
|
|
1626
|
+
const isCommon = (aIndex, bIndex)=>a[aIndex] === b[bIndex];
|
|
1627
|
+
let aIndex = 0;
|
|
1628
|
+
let bIndex = 0;
|
|
1629
|
+
const diffs = [];
|
|
1630
|
+
const foundSubsequence = (nCommon, aCommon, bCommon)=>{
|
|
1631
|
+
if (aIndex !== aCommon) diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
|
|
1632
|
+
if (bIndex !== bCommon) diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
|
|
1633
|
+
aIndex = aCommon + nCommon;
|
|
1634
|
+
bIndex = bCommon + nCommon;
|
|
1635
|
+
diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
|
|
1636
|
+
};
|
|
1637
|
+
diffSequences(aLength, bLength, isCommon, foundSubsequence);
|
|
1638
|
+
if (aIndex !== aLength) diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
|
|
1639
|
+
if (bIndex !== bLength) diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
|
|
1640
|
+
return [
|
|
1641
|
+
diffs,
|
|
1642
|
+
truncated
|
|
1643
|
+
];
|
|
1644
|
+
}
|
|
1645
|
+
function concatenateRelevantDiffs(op, diffs, changeColor) {
|
|
1646
|
+
return diffs.reduce((reduced, diff)=>reduced + (diff[0] === DIFF_EQUAL ? diff[1] : diff[0] === op && 0 !== diff[1].length ? changeColor(diff[1]) : ""), "");
|
|
1647
|
+
}
|
|
1648
|
+
class ChangeBuffer {
|
|
1649
|
+
op;
|
|
1650
|
+
line;
|
|
1651
|
+
lines;
|
|
1652
|
+
changeColor;
|
|
1653
|
+
constructor(op, changeColor){
|
|
1654
|
+
this.op = op;
|
|
1655
|
+
this.line = [];
|
|
1656
|
+
this.lines = [];
|
|
1657
|
+
this.changeColor = changeColor;
|
|
1658
|
+
}
|
|
1659
|
+
pushSubstring(substring) {
|
|
1660
|
+
this.pushDiff(new Diff(this.op, substring));
|
|
1661
|
+
}
|
|
1662
|
+
pushLine() {
|
|
1663
|
+
this.lines.push(1 !== this.line.length ? new Diff(this.op, concatenateRelevantDiffs(this.op, this.line, this.changeColor)) : this.line[0][0] === this.op ? this.line[0] : new Diff(this.op, this.line[0][1]));
|
|
1664
|
+
this.line.length = 0;
|
|
1665
|
+
}
|
|
1666
|
+
isLineEmpty() {
|
|
1667
|
+
return 0 === this.line.length;
|
|
1668
|
+
}
|
|
1669
|
+
pushDiff(diff) {
|
|
1670
|
+
this.line.push(diff);
|
|
1671
|
+
}
|
|
1672
|
+
align(diff) {
|
|
1673
|
+
const string = diff[1];
|
|
1674
|
+
if (string.includes("\n")) {
|
|
1675
|
+
const substrings = string.split("\n");
|
|
1676
|
+
const iLast = substrings.length - 1;
|
|
1677
|
+
substrings.forEach((substring, i)=>{
|
|
1678
|
+
if (i < iLast) {
|
|
1679
|
+
this.pushSubstring(substring);
|
|
1680
|
+
this.pushLine();
|
|
1681
|
+
} else if (0 !== substring.length) this.pushSubstring(substring);
|
|
1682
|
+
});
|
|
1683
|
+
} else this.pushDiff(diff);
|
|
1684
|
+
}
|
|
1685
|
+
moveLinesTo(lines) {
|
|
1686
|
+
if (!this.isLineEmpty()) this.pushLine();
|
|
1687
|
+
lines.push(...this.lines);
|
|
1688
|
+
this.lines.length = 0;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
class CommonBuffer {
|
|
1692
|
+
deleteBuffer;
|
|
1693
|
+
insertBuffer;
|
|
1694
|
+
lines;
|
|
1695
|
+
constructor(deleteBuffer, insertBuffer){
|
|
1696
|
+
this.deleteBuffer = deleteBuffer;
|
|
1697
|
+
this.insertBuffer = insertBuffer;
|
|
1698
|
+
this.lines = [];
|
|
1699
|
+
}
|
|
1700
|
+
pushDiffCommonLine(diff) {
|
|
1701
|
+
this.lines.push(diff);
|
|
1702
|
+
}
|
|
1703
|
+
pushDiffChangeLines(diff) {
|
|
1704
|
+
const isDiffEmpty = 0 === diff[1].length;
|
|
1705
|
+
if (!isDiffEmpty || this.deleteBuffer.isLineEmpty()) this.deleteBuffer.pushDiff(diff);
|
|
1706
|
+
if (!isDiffEmpty || this.insertBuffer.isLineEmpty()) this.insertBuffer.pushDiff(diff);
|
|
1707
|
+
}
|
|
1708
|
+
flushChangeLines() {
|
|
1709
|
+
this.deleteBuffer.moveLinesTo(this.lines);
|
|
1710
|
+
this.insertBuffer.moveLinesTo(this.lines);
|
|
1711
|
+
}
|
|
1712
|
+
align(diff) {
|
|
1713
|
+
const op = diff[0];
|
|
1714
|
+
const string = diff[1];
|
|
1715
|
+
if (string.includes("\n")) {
|
|
1716
|
+
const substrings = string.split("\n");
|
|
1717
|
+
const iLast = substrings.length - 1;
|
|
1718
|
+
substrings.forEach((substring, i)=>{
|
|
1719
|
+
if (0 === i) {
|
|
1720
|
+
const subdiff = new Diff(op, substring);
|
|
1721
|
+
if (this.deleteBuffer.isLineEmpty() && this.insertBuffer.isLineEmpty()) {
|
|
1722
|
+
this.flushChangeLines();
|
|
1723
|
+
this.pushDiffCommonLine(subdiff);
|
|
1724
|
+
} else {
|
|
1725
|
+
this.pushDiffChangeLines(subdiff);
|
|
1726
|
+
this.flushChangeLines();
|
|
1727
|
+
}
|
|
1728
|
+
} else if (i < iLast) this.pushDiffCommonLine(new Diff(op, substring));
|
|
1729
|
+
else if (0 !== substring.length) this.pushDiffChangeLines(new Diff(op, substring));
|
|
1730
|
+
});
|
|
1731
|
+
} else this.pushDiffChangeLines(diff);
|
|
1732
|
+
}
|
|
1733
|
+
getLines() {
|
|
1734
|
+
this.flushChangeLines();
|
|
1735
|
+
return this.lines;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
function getAlignedDiffs(diffs, changeColor) {
|
|
1739
|
+
const deleteBuffer = new ChangeBuffer(DIFF_DELETE, changeColor);
|
|
1740
|
+
const insertBuffer = new ChangeBuffer(DIFF_INSERT, changeColor);
|
|
1741
|
+
const commonBuffer = new CommonBuffer(deleteBuffer, insertBuffer);
|
|
1742
|
+
diffs.forEach((diff)=>{
|
|
1743
|
+
switch(diff[0]){
|
|
1744
|
+
case DIFF_DELETE:
|
|
1745
|
+
deleteBuffer.align(diff);
|
|
1746
|
+
break;
|
|
1747
|
+
case DIFF_INSERT:
|
|
1748
|
+
insertBuffer.align(diff);
|
|
1749
|
+
break;
|
|
1750
|
+
default:
|
|
1751
|
+
commonBuffer.align(diff);
|
|
1752
|
+
}
|
|
1753
|
+
});
|
|
1754
|
+
return commonBuffer.getLines();
|
|
1755
|
+
}
|
|
1756
|
+
function diff_hasCommonDiff(diffs, isMultiline) {
|
|
1757
|
+
if (isMultiline) {
|
|
1758
|
+
const iLast = diffs.length - 1;
|
|
1759
|
+
return diffs.some((diff, i)=>diff[0] === DIFF_EQUAL && (i !== iLast || "\n" !== diff[1]));
|
|
1760
|
+
}
|
|
1761
|
+
return diffs.some((diff)=>diff[0] === DIFF_EQUAL);
|
|
1762
|
+
}
|
|
1763
|
+
function diffStringsUnified(a, b, options) {
|
|
1764
|
+
if (a !== b && 0 !== a.length && 0 !== b.length) {
|
|
1765
|
+
const isMultiline = a.includes("\n") || b.includes("\n");
|
|
1766
|
+
const [diffs, truncated] = diffStringsRaw(isMultiline ? `${a}\n` : a, isMultiline ? `${b}\n` : b, true, options);
|
|
1767
|
+
if (diff_hasCommonDiff(diffs, isMultiline)) {
|
|
1768
|
+
const optionsNormalized = normalizeDiffOptions(options);
|
|
1769
|
+
const lines = getAlignedDiffs(diffs, optionsNormalized.changeColor);
|
|
1770
|
+
return printDiffLines(lines, truncated, optionsNormalized);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
return diffLinesUnified(a.split("\n"), b.split("\n"), options);
|
|
1774
|
+
}
|
|
1775
|
+
function diffStringsRaw(a, b, cleanup, options) {
|
|
1776
|
+
const [diffs, truncated] = diffStrings(a, b, options);
|
|
1777
|
+
if (cleanup) diff_cleanupSemantic(diffs);
|
|
1778
|
+
return [
|
|
1779
|
+
diffs,
|
|
1780
|
+
truncated
|
|
1781
|
+
];
|
|
1782
|
+
}
|
|
1783
|
+
function getCommonMessage(message, options) {
|
|
1784
|
+
const { commonColor } = normalizeDiffOptions(options);
|
|
1785
|
+
return commonColor(message);
|
|
1786
|
+
}
|
|
1787
|
+
const { AsymmetricMatcher: diff_AsymmetricMatcher, DOMCollection: diff_DOMCollection, DOMElement: diff_DOMElement, Immutable: diff_Immutable, ReactElement: diff_ReactElement, ReactTestComponent: diff_ReactTestComponent } = dist_plugins;
|
|
1788
|
+
const diff_PLUGINS = [
|
|
1789
|
+
diff_ReactTestComponent,
|
|
1790
|
+
diff_ReactElement,
|
|
1791
|
+
diff_DOMElement,
|
|
1792
|
+
diff_DOMCollection,
|
|
1793
|
+
diff_Immutable,
|
|
1794
|
+
diff_AsymmetricMatcher,
|
|
1795
|
+
dist_plugins.Error
|
|
1796
|
+
];
|
|
1797
|
+
const FORMAT_OPTIONS = {
|
|
1798
|
+
maxDepth: 20,
|
|
1799
|
+
plugins: diff_PLUGINS
|
|
1800
|
+
};
|
|
1801
|
+
const FALLBACK_FORMAT_OPTIONS = {
|
|
1802
|
+
callToJSON: false,
|
|
1803
|
+
maxDepth: 8,
|
|
1804
|
+
plugins: diff_PLUGINS
|
|
1805
|
+
};
|
|
1806
|
+
function diff_diff(a, b, options) {
|
|
1807
|
+
if (Object.is(a, b)) return "";
|
|
1808
|
+
const aType = diff_getType(a);
|
|
1809
|
+
let expectedType = aType;
|
|
1810
|
+
let omitDifference = false;
|
|
1811
|
+
if ("object" === aType && "function" == typeof a.asymmetricMatch) {
|
|
1812
|
+
if (a.$$typeof !== Symbol.for("jest.asymmetricMatcher")) return;
|
|
1813
|
+
if ("function" != typeof a.getExpectedType) return;
|
|
1814
|
+
expectedType = a.getExpectedType();
|
|
1815
|
+
omitDifference = "string" === expectedType;
|
|
1816
|
+
}
|
|
1817
|
+
if (expectedType !== diff_getType(b)) {
|
|
1818
|
+
const { aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator } = normalizeDiffOptions(options);
|
|
1819
|
+
const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
|
|
1820
|
+
let aDisplay = dist_format(a, formatOptions);
|
|
1821
|
+
let bDisplay = dist_format(b, formatOptions);
|
|
1822
|
+
const MAX_LENGTH = 1e5;
|
|
1823
|
+
function truncate(s) {
|
|
1824
|
+
return s.length <= MAX_LENGTH ? s : `${s.slice(0, MAX_LENGTH)}...`;
|
|
1825
|
+
}
|
|
1826
|
+
aDisplay = truncate(aDisplay);
|
|
1827
|
+
bDisplay = truncate(bDisplay);
|
|
1828
|
+
const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)} \n${aDisplay}`;
|
|
1829
|
+
const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)} \n${bDisplay}`;
|
|
1830
|
+
return `${aDiff}\n\n${bDiff}`;
|
|
1831
|
+
}
|
|
1832
|
+
if (omitDifference) return;
|
|
1833
|
+
switch(aType){
|
|
1834
|
+
case "string":
|
|
1835
|
+
return diffLinesUnified(a.split("\n"), b.split("\n"), options);
|
|
1836
|
+
case "boolean":
|
|
1837
|
+
case "number":
|
|
1838
|
+
return comparePrimitive(a, b, options);
|
|
1839
|
+
case "map":
|
|
1840
|
+
return compareObjects(sortMap(a), sortMap(b), options);
|
|
1841
|
+
case "set":
|
|
1842
|
+
return compareObjects(sortSet(a), sortSet(b), options);
|
|
1843
|
+
default:
|
|
1844
|
+
return compareObjects(a, b, options);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
function comparePrimitive(a, b, options) {
|
|
1848
|
+
const aFormat = dist_format(a, FORMAT_OPTIONS);
|
|
1849
|
+
const bFormat = dist_format(b, FORMAT_OPTIONS);
|
|
1850
|
+
return aFormat === bFormat ? "" : diffLinesUnified(aFormat.split("\n"), bFormat.split("\n"), options);
|
|
1851
|
+
}
|
|
1852
|
+
function sortMap(map) {
|
|
1853
|
+
return new Map(Array.from(map.entries()).sort());
|
|
1854
|
+
}
|
|
1855
|
+
function sortSet(set) {
|
|
1856
|
+
return new Set(Array.from(set.values()).sort());
|
|
1857
|
+
}
|
|
1858
|
+
function compareObjects(a, b, options) {
|
|
1859
|
+
let difference;
|
|
1860
|
+
let hasThrown = false;
|
|
1861
|
+
try {
|
|
1862
|
+
const formatOptions = getFormatOptions(FORMAT_OPTIONS, options);
|
|
1863
|
+
difference = getObjectsDifference(a, b, formatOptions, options);
|
|
1864
|
+
} catch {
|
|
1865
|
+
hasThrown = true;
|
|
1866
|
+
}
|
|
1867
|
+
const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options);
|
|
1868
|
+
if (void 0 === difference || difference === noDiffMessage) {
|
|
1869
|
+
const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
|
|
1870
|
+
difference = getObjectsDifference(a, b, formatOptions, options);
|
|
1871
|
+
if (difference !== noDiffMessage && !hasThrown) difference = `${getCommonMessage(SIMILAR_MESSAGE, options)}\n\n${difference}`;
|
|
1872
|
+
}
|
|
1873
|
+
return difference;
|
|
1874
|
+
}
|
|
1875
|
+
function getFormatOptions(formatOptions, options) {
|
|
1876
|
+
const { compareKeys, printBasicPrototype, maxDepth } = normalizeDiffOptions(options);
|
|
1877
|
+
return {
|
|
1878
|
+
...formatOptions,
|
|
1879
|
+
compareKeys,
|
|
1880
|
+
printBasicPrototype,
|
|
1881
|
+
maxDepth: maxDepth ?? formatOptions.maxDepth
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
function getObjectsDifference(a, b, formatOptions, options) {
|
|
1885
|
+
const formatOptionsZeroIndent = {
|
|
1886
|
+
...formatOptions,
|
|
1887
|
+
indent: 0
|
|
1888
|
+
};
|
|
1889
|
+
const aCompare = dist_format(a, formatOptionsZeroIndent);
|
|
1890
|
+
const bCompare = dist_format(b, formatOptionsZeroIndent);
|
|
1891
|
+
if (aCompare === bCompare) return getCommonMessage(NO_DIFF_MESSAGE, options);
|
|
1892
|
+
{
|
|
1893
|
+
const aDisplay = dist_format(a, formatOptions);
|
|
1894
|
+
const bDisplay = dist_format(b, formatOptions);
|
|
1895
|
+
return diffLinesUnified2(aDisplay.split("\n"), bDisplay.split("\n"), aCompare.split("\n"), bCompare.split("\n"), options);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
const MAX_DIFF_STRING_LENGTH = 2e4;
|
|
1899
|
+
function isAsymmetricMatcher(data) {
|
|
1900
|
+
const type = getType(data);
|
|
1901
|
+
return "Object" === type && "function" == typeof data.asymmetricMatch;
|
|
1902
|
+
}
|
|
1903
|
+
function isReplaceable(obj1, obj2) {
|
|
1904
|
+
const obj1Type = getType(obj1);
|
|
1905
|
+
const obj2Type = getType(obj2);
|
|
1906
|
+
return obj1Type === obj2Type && ("Object" === obj1Type || "Array" === obj1Type);
|
|
1907
|
+
}
|
|
1908
|
+
function printDiffOrStringify(received, expected, options) {
|
|
1909
|
+
const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
|
|
1910
|
+
if ("string" == typeof expected && "string" == typeof received && expected.length > 0 && received.length > 0 && expected.length <= MAX_DIFF_STRING_LENGTH && received.length <= MAX_DIFF_STRING_LENGTH && expected !== received) {
|
|
1911
|
+
if (expected.includes("\n") || received.includes("\n")) return diffStringsUnified(expected, received, options);
|
|
1912
|
+
const [diffs] = diffStringsRaw(expected, received, true);
|
|
1913
|
+
const hasCommonDiff = diffs.some((diff)=>diff[0] === DIFF_EQUAL);
|
|
1914
|
+
const printLabel = getLabelPrinter(aAnnotation, bAnnotation);
|
|
1915
|
+
const expectedLine = printLabel(aAnnotation) + printExpected(getCommonAndChangedSubstrings(diffs, DIFF_DELETE, hasCommonDiff));
|
|
1916
|
+
const receivedLine = printLabel(bAnnotation) + printReceived(getCommonAndChangedSubstrings(diffs, DIFF_INSERT, hasCommonDiff));
|
|
1917
|
+
return `${expectedLine}\n${receivedLine}`;
|
|
1918
|
+
}
|
|
1919
|
+
const clonedExpected = deepClone(expected, {
|
|
1920
|
+
forceWritable: true
|
|
1921
|
+
});
|
|
1922
|
+
const clonedReceived = deepClone(received, {
|
|
1923
|
+
forceWritable: true
|
|
1924
|
+
});
|
|
1925
|
+
const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(clonedReceived, clonedExpected);
|
|
1926
|
+
const difference = diff_diff(replacedExpected, replacedActual, options);
|
|
1927
|
+
return difference;
|
|
1928
|
+
}
|
|
1929
|
+
function replaceAsymmetricMatcher(actual, expected, actualReplaced = new WeakSet(), expectedReplaced = new WeakSet()) {
|
|
1930
|
+
if (actual instanceof Error && expected instanceof Error && void 0 !== actual.cause && void 0 === expected.cause) {
|
|
1931
|
+
delete actual.cause;
|
|
1932
|
+
return {
|
|
1933
|
+
replacedActual: actual,
|
|
1934
|
+
replacedExpected: expected
|
|
1935
|
+
};
|
|
1936
|
+
}
|
|
1937
|
+
if (!isReplaceable(actual, expected)) return {
|
|
1938
|
+
replacedActual: actual,
|
|
1939
|
+
replacedExpected: expected
|
|
1940
|
+
};
|
|
1941
|
+
if (actualReplaced.has(actual) || expectedReplaced.has(expected)) return {
|
|
1942
|
+
replacedActual: actual,
|
|
1943
|
+
replacedExpected: expected
|
|
1944
|
+
};
|
|
1945
|
+
actualReplaced.add(actual);
|
|
1946
|
+
expectedReplaced.add(expected);
|
|
1947
|
+
getOwnProperties(expected).forEach((key)=>{
|
|
1948
|
+
const expectedValue = expected[key];
|
|
1949
|
+
const actualValue = actual[key];
|
|
1950
|
+
if (isAsymmetricMatcher(expectedValue)) {
|
|
1951
|
+
if (expectedValue.asymmetricMatch(actualValue)) actual[key] = expectedValue;
|
|
1952
|
+
} else if (isAsymmetricMatcher(actualValue)) {
|
|
1953
|
+
if (actualValue.asymmetricMatch(expectedValue)) expected[key] = actualValue;
|
|
1954
|
+
} else if (isReplaceable(actualValue, expectedValue)) {
|
|
1955
|
+
const replaced = replaceAsymmetricMatcher(actualValue, expectedValue, actualReplaced, expectedReplaced);
|
|
1956
|
+
actual[key] = replaced.replacedActual;
|
|
1957
|
+
expected[key] = replaced.replacedExpected;
|
|
1958
|
+
}
|
|
1959
|
+
});
|
|
1960
|
+
return {
|
|
1961
|
+
replacedActual: actual,
|
|
1962
|
+
replacedExpected: expected
|
|
1963
|
+
};
|
|
1964
|
+
}
|
|
1965
|
+
function getLabelPrinter(...strings) {
|
|
1966
|
+
const maxLength = strings.reduce((max, string)=>string.length > max ? string.length : max, 0);
|
|
1967
|
+
return (string)=>`${string}: ${" ".repeat(maxLength - string.length)}`;
|
|
1968
|
+
}
|
|
1969
|
+
const SPACE_SYMBOL = "·";
|
|
1970
|
+
function replaceTrailingSpaces(text) {
|
|
1971
|
+
return text.replace(/\s+$/gm, (spaces)=>SPACE_SYMBOL.repeat(spaces.length));
|
|
1972
|
+
}
|
|
1973
|
+
function printReceived(object) {
|
|
1974
|
+
return node_u.red(replaceTrailingSpaces(stringify(object)));
|
|
1975
|
+
}
|
|
1976
|
+
function printExpected(value) {
|
|
1977
|
+
return node_u.green(replaceTrailingSpaces(stringify(value)));
|
|
1978
|
+
}
|
|
1979
|
+
function getCommonAndChangedSubstrings(diffs, op, hasCommonDiff) {
|
|
1980
|
+
return diffs.reduce((reduced, diff)=>reduced + (diff[0] === DIFF_EQUAL ? diff[1] : diff[0] === op ? hasCommonDiff ? node_u.inverse(diff[1]) : diff[1] : ""), "");
|
|
1981
|
+
}
|
|
1982
|
+
export { assertTypes, diff_diff, diff_namespaceObject, format, getType, isObject, noop, printDiffOrStringify, stringify };
|