@noma.to/qwik-mock 1.1.0 → 1.1.2

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.
Files changed (51) hide show
  1. package/lib/lib/qwik-mock.cjs +3 -3
  2. package/lib/lib/qwik-mock.mjs +1 -1
  3. package/package.json +7 -6
  4. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.cjs +0 -83
  5. package/lib/node_modules/.pnpm/@jridgewell_sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs +0 -83
  6. package/lib/node_modules/.pnpm/@vitest_expect@4.0.18/node_modules/@vitest/expect/dist/index.cjs +0 -1785
  7. package/lib/node_modules/.pnpm/@vitest_expect@4.0.18/node_modules/@vitest/expect/dist/index.mjs +0 -1785
  8. package/lib/node_modules/.pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.cjs +0 -964
  9. package/lib/node_modules/.pnpm/@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.mjs +0 -964
  10. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/chunk-tasks.cjs +0 -60
  11. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/chunk-tasks.mjs +0 -60
  12. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/index.cjs +0 -1102
  13. package/lib/node_modules/.pnpm/@vitest_runner@4.0.18/node_modules/@vitest/runner/dist/index.mjs +0 -1102
  14. package/lib/node_modules/.pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest/snapshot/dist/index.cjs +0 -1289
  15. package/lib/node_modules/.pnpm/@vitest_snapshot@4.0.18/node_modules/@vitest/snapshot/dist/index.mjs +0 -1289
  16. package/lib/node_modules/.pnpm/@vitest_spy@4.0.18/node_modules/@vitest/spy/dist/index.cjs +0 -422
  17. package/lib/node_modules/.pnpm/@vitest_spy@4.0.18/node_modules/@vitest/spy/dist/index.mjs +0 -422
  18. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.cjs +0 -6
  19. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-_commonjsHelpers.mjs +0 -6
  20. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.cjs +0 -98
  21. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/chunk-pathe.M-eThtNZ.mjs +0 -98
  22. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/diff.cjs +0 -1626
  23. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/diff.mjs +0 -1626
  24. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/display.cjs +0 -690
  25. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/display.mjs +0 -690
  26. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/error.cjs +0 -39
  27. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/error.mjs +0 -39
  28. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/helpers.cjs +0 -151
  29. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/helpers.mjs +0 -151
  30. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/serialize.cjs +0 -114
  31. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/serialize.mjs +0 -114
  32. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/source-map.cjs +0 -125
  33. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/source-map.mjs +0 -125
  34. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/timers.cjs +0 -22
  35. package/lib/node_modules/.pnpm/@vitest_utils@4.0.18/node_modules/@vitest/utils/dist/timers.mjs +0 -22
  36. package/lib/node_modules/.pnpm/chai@6.2.2/node_modules/chai/index.cjs +0 -4056
  37. package/lib/node_modules/.pnpm/chai@6.2.2/node_modules/chai/index.mjs +0 -4056
  38. package/lib/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.cjs +0 -994
  39. package/lib/node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs +0 -994
  40. package/lib/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.cjs +0 -101
  41. package/lib/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -101
  42. package/lib/node_modules/.pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.cjs +0 -84
  43. package/lib/node_modules/.pnpm/tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.mjs +0 -84
  44. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.cjs +0 -4
  45. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/_commonjsHelpers.D26ty3Ew.mjs +0 -4
  46. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.cjs +0 -51
  47. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/date.Bq6ZW5rf.mjs +0 -51
  48. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/utils.DvEY5TfP.cjs +0 -45
  49. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/utils.DvEY5TfP.mjs +0 -45
  50. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.cjs +0 -2609
  51. package/lib/node_modules/.pnpm/vitest@4.0.18_@types_node@25.1.0_@vitest_ui@4.0.18_happy-dom@20.0.11_jiti@2.4.2_jsdom@26.1.0__pd2l5poczrcnqygjcqiguyknnm/node_modules/vitest/dist/chunks/vi.2VT5v0um.mjs +0 -2609
@@ -1,1626 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
6
- const index = require("../../../../../@vitest_pretty-format@4.0.18/node_modules/@vitest/pretty-format/dist/index.cjs");
7
- const index$1 = require("../../../../../tinyrainbow@3.0.3/node_modules/tinyrainbow/dist/index.cjs");
8
- const display = require("./display.cjs");
9
- const helpers = require("./helpers.cjs");
10
- const chunk_commonjsHelpers = require("./chunk-_commonjsHelpers.cjs");
11
- const DIFF_DELETE = -1;
12
- const DIFF_INSERT = 1;
13
- const DIFF_EQUAL = 0;
14
- class Diff {
15
- constructor(op, text) {
16
- __publicField(this, 0);
17
- __publicField(this, 1);
18
- this[0] = op;
19
- this[1] = text;
20
- }
21
- }
22
- function diff_commonPrefix(text1, text2) {
23
- if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) {
24
- return 0;
25
- }
26
- let pointermin = 0;
27
- let pointermax = Math.min(text1.length, text2.length);
28
- let pointermid = pointermax;
29
- let pointerstart = 0;
30
- while (pointermin < pointermid) {
31
- if (text1.substring(pointerstart, pointermid) === text2.substring(pointerstart, pointermid)) {
32
- pointermin = pointermid;
33
- pointerstart = pointermin;
34
- } else {
35
- pointermax = pointermid;
36
- }
37
- pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
38
- }
39
- return pointermid;
40
- }
41
- function diff_commonSuffix(text1, text2) {
42
- if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) {
43
- return 0;
44
- }
45
- let pointermin = 0;
46
- let pointermax = Math.min(text1.length, text2.length);
47
- let pointermid = pointermax;
48
- let pointerend = 0;
49
- while (pointermin < pointermid) {
50
- if (text1.substring(text1.length - pointermid, text1.length - pointerend) === text2.substring(text2.length - pointermid, text2.length - pointerend)) {
51
- pointermin = pointermid;
52
- pointerend = pointermin;
53
- } else {
54
- pointermax = pointermid;
55
- }
56
- pointermid = Math.floor((pointermax - pointermin) / 2 + pointermin);
57
- }
58
- return pointermid;
59
- }
60
- function diff_commonOverlap_(text1, text2) {
61
- const text1_length = text1.length;
62
- const text2_length = text2.length;
63
- if (text1_length === 0 || text2_length === 0) {
64
- return 0;
65
- }
66
- if (text1_length > text2_length) {
67
- text1 = text1.substring(text1_length - text2_length);
68
- } else if (text1_length < text2_length) {
69
- text2 = text2.substring(0, text1_length);
70
- }
71
- const text_length = Math.min(text1_length, text2_length);
72
- if (text1 === text2) {
73
- return text_length;
74
- }
75
- let best = 0;
76
- let length = 1;
77
- while (true) {
78
- const pattern = text1.substring(text_length - length);
79
- const found = text2.indexOf(pattern);
80
- if (found === -1) {
81
- return best;
82
- }
83
- length += found;
84
- if (found === 0 || text1.substring(text_length - length) === text2.substring(0, length)) {
85
- best = length;
86
- length++;
87
- }
88
- }
89
- }
90
- function diff_cleanupSemantic(diffs) {
91
- let changes = false;
92
- const equalities = [];
93
- let equalitiesLength = 0;
94
- let lastEquality = null;
95
- let pointer = 0;
96
- let length_insertions1 = 0;
97
- let length_deletions1 = 0;
98
- let length_insertions2 = 0;
99
- let length_deletions2 = 0;
100
- while (pointer < diffs.length) {
101
- if (diffs[pointer][0] === DIFF_EQUAL) {
102
- equalities[equalitiesLength++] = pointer;
103
- length_insertions1 = length_insertions2;
104
- length_deletions1 = length_deletions2;
105
- length_insertions2 = 0;
106
- length_deletions2 = 0;
107
- lastEquality = diffs[pointer][1];
108
- } else {
109
- if (diffs[pointer][0] === DIFF_INSERT) {
110
- length_insertions2 += diffs[pointer][1].length;
111
- } else {
112
- length_deletions2 += diffs[pointer][1].length;
113
- }
114
- if (lastEquality && lastEquality.length <= Math.max(length_insertions1, length_deletions1) && lastEquality.length <= Math.max(length_insertions2, length_deletions2)) {
115
- diffs.splice(equalities[equalitiesLength - 1], 0, new Diff(DIFF_DELETE, lastEquality));
116
- diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
117
- equalitiesLength--;
118
- equalitiesLength--;
119
- pointer = equalitiesLength > 0 ? equalities[equalitiesLength - 1] : -1;
120
- length_insertions1 = 0;
121
- length_deletions1 = 0;
122
- length_insertions2 = 0;
123
- length_deletions2 = 0;
124
- lastEquality = null;
125
- changes = true;
126
- }
127
- }
128
- pointer++;
129
- }
130
- if (changes) {
131
- diff_cleanupMerge(diffs);
132
- }
133
- diff_cleanupSemanticLossless(diffs);
134
- pointer = 1;
135
- while (pointer < diffs.length) {
136
- if (diffs[pointer - 1][0] === DIFF_DELETE && diffs[pointer][0] === DIFF_INSERT) {
137
- const deletion = diffs[pointer - 1][1];
138
- const insertion = diffs[pointer][1];
139
- const overlap_length1 = diff_commonOverlap_(deletion, insertion);
140
- const overlap_length2 = diff_commonOverlap_(insertion, deletion);
141
- if (overlap_length1 >= overlap_length2) {
142
- if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) {
143
- diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1)));
144
- diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlap_length1);
145
- diffs[pointer + 1][1] = insertion.substring(overlap_length1);
146
- pointer++;
147
- }
148
- } else {
149
- if (overlap_length2 >= deletion.length / 2 || overlap_length2 >= insertion.length / 2) {
150
- diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2)));
151
- diffs[pointer - 1][0] = DIFF_INSERT;
152
- diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlap_length2);
153
- diffs[pointer + 1][0] = DIFF_DELETE;
154
- diffs[pointer + 1][1] = deletion.substring(overlap_length2);
155
- pointer++;
156
- }
157
- }
158
- pointer++;
159
- }
160
- pointer++;
161
- }
162
- }
163
- const nonAlphaNumericRegex_ = /[^a-z0-9]/i;
164
- const whitespaceRegex_ = /\s/;
165
- const linebreakRegex_ = /[\r\n]/;
166
- const blanklineEndRegex_ = /\n\r?\n$/;
167
- const blanklineStartRegex_ = /^\r?\n\r?\n/;
168
- function diff_cleanupSemanticLossless(diffs) {
169
- let pointer = 1;
170
- while (pointer < diffs.length - 1) {
171
- if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
172
- let equality1 = diffs[pointer - 1][1];
173
- let edit = diffs[pointer][1];
174
- let equality2 = diffs[pointer + 1][1];
175
- const commonOffset = diff_commonSuffix(equality1, edit);
176
- if (commonOffset) {
177
- const commonString = edit.substring(edit.length - commonOffset);
178
- equality1 = equality1.substring(0, equality1.length - commonOffset);
179
- edit = commonString + edit.substring(0, edit.length - commonOffset);
180
- equality2 = commonString + equality2;
181
- }
182
- let bestEquality1 = equality1;
183
- let bestEdit = edit;
184
- let bestEquality2 = equality2;
185
- let bestScore = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
186
- while (edit.charAt(0) === equality2.charAt(0)) {
187
- equality1 += edit.charAt(0);
188
- edit = edit.substring(1) + equality2.charAt(0);
189
- equality2 = equality2.substring(1);
190
- const score = diff_cleanupSemanticScore_(equality1, edit) + diff_cleanupSemanticScore_(edit, equality2);
191
- if (score >= bestScore) {
192
- bestScore = score;
193
- bestEquality1 = equality1;
194
- bestEdit = edit;
195
- bestEquality2 = equality2;
196
- }
197
- }
198
- if (diffs[pointer - 1][1] !== bestEquality1) {
199
- if (bestEquality1) {
200
- diffs[pointer - 1][1] = bestEquality1;
201
- } else {
202
- diffs.splice(pointer - 1, 1);
203
- pointer--;
204
- }
205
- diffs[pointer][1] = bestEdit;
206
- if (bestEquality2) {
207
- diffs[pointer + 1][1] = bestEquality2;
208
- } else {
209
- diffs.splice(pointer + 1, 1);
210
- pointer--;
211
- }
212
- }
213
- }
214
- pointer++;
215
- }
216
- }
217
- function diff_cleanupMerge(diffs) {
218
- var _diffs$at;
219
- diffs.push(new Diff(DIFF_EQUAL, ""));
220
- let pointer = 0;
221
- let count_delete = 0;
222
- let count_insert = 0;
223
- let text_delete = "";
224
- let text_insert = "";
225
- let commonlength;
226
- while (pointer < diffs.length) {
227
- switch (diffs[pointer][0]) {
228
- case DIFF_INSERT:
229
- count_insert++;
230
- text_insert += diffs[pointer][1];
231
- pointer++;
232
- break;
233
- case DIFF_DELETE:
234
- count_delete++;
235
- text_delete += diffs[pointer][1];
236
- pointer++;
237
- break;
238
- case DIFF_EQUAL:
239
- if (count_delete + count_insert > 1) {
240
- if (count_delete !== 0 && count_insert !== 0) {
241
- commonlength = diff_commonPrefix(text_insert, text_delete);
242
- if (commonlength !== 0) {
243
- if (pointer - count_delete - count_insert > 0 && diffs[pointer - count_delete - count_insert - 1][0] === DIFF_EQUAL) {
244
- diffs[pointer - count_delete - count_insert - 1][1] += text_insert.substring(0, commonlength);
245
- } else {
246
- diffs.splice(0, 0, new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength)));
247
- pointer++;
248
- }
249
- text_insert = text_insert.substring(commonlength);
250
- text_delete = text_delete.substring(commonlength);
251
- }
252
- commonlength = diff_commonSuffix(text_insert, text_delete);
253
- if (commonlength !== 0) {
254
- diffs[pointer][1] = text_insert.substring(text_insert.length - commonlength) + diffs[pointer][1];
255
- text_insert = text_insert.substring(0, text_insert.length - commonlength);
256
- text_delete = text_delete.substring(0, text_delete.length - commonlength);
257
- }
258
- }
259
- pointer -= count_delete + count_insert;
260
- diffs.splice(pointer, count_delete + count_insert);
261
- if (text_delete.length) {
262
- diffs.splice(pointer, 0, new Diff(DIFF_DELETE, text_delete));
263
- pointer++;
264
- }
265
- if (text_insert.length) {
266
- diffs.splice(pointer, 0, new Diff(DIFF_INSERT, text_insert));
267
- pointer++;
268
- }
269
- pointer++;
270
- } else if (pointer !== 0 && diffs[pointer - 1][0] === DIFF_EQUAL) {
271
- diffs[pointer - 1][1] += diffs[pointer][1];
272
- diffs.splice(pointer, 1);
273
- } else {
274
- pointer++;
275
- }
276
- count_insert = 0;
277
- count_delete = 0;
278
- text_delete = "";
279
- text_insert = "";
280
- break;
281
- }
282
- }
283
- if (((_diffs$at = diffs.at(-1)) === null || _diffs$at === void 0 ? void 0 : _diffs$at[1]) === "") {
284
- diffs.pop();
285
- }
286
- let changes = false;
287
- pointer = 1;
288
- while (pointer < diffs.length - 1) {
289
- if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
290
- if (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1]) {
291
- diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length);
292
- diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
293
- diffs.splice(pointer - 1, 1);
294
- changes = true;
295
- } else if (diffs[pointer][1].substring(0, diffs[pointer + 1][1].length) === diffs[pointer + 1][1]) {
296
- diffs[pointer - 1][1] += diffs[pointer + 1][1];
297
- diffs[pointer][1] = diffs[pointer][1].substring(diffs[pointer + 1][1].length) + diffs[pointer + 1][1];
298
- diffs.splice(pointer + 1, 1);
299
- changes = true;
300
- }
301
- }
302
- pointer++;
303
- }
304
- if (changes) {
305
- diff_cleanupMerge(diffs);
306
- }
307
- }
308
- function diff_cleanupSemanticScore_(one, two) {
309
- if (!one || !two) {
310
- return 6;
311
- }
312
- const char1 = one.charAt(one.length - 1);
313
- const char2 = two.charAt(0);
314
- const nonAlphaNumeric1 = char1.match(nonAlphaNumericRegex_);
315
- const nonAlphaNumeric2 = char2.match(nonAlphaNumericRegex_);
316
- const whitespace1 = nonAlphaNumeric1 && char1.match(whitespaceRegex_);
317
- const whitespace2 = nonAlphaNumeric2 && char2.match(whitespaceRegex_);
318
- const lineBreak1 = whitespace1 && char1.match(linebreakRegex_);
319
- const lineBreak2 = whitespace2 && char2.match(linebreakRegex_);
320
- const blankLine1 = lineBreak1 && one.match(blanklineEndRegex_);
321
- const blankLine2 = lineBreak2 && two.match(blanklineStartRegex_);
322
- if (blankLine1 || blankLine2) {
323
- return 5;
324
- } else if (lineBreak1 || lineBreak2) {
325
- return 4;
326
- } else if (nonAlphaNumeric1 && !whitespace1 && whitespace2) {
327
- return 3;
328
- } else if (whitespace1 || whitespace2) {
329
- return 2;
330
- } else if (nonAlphaNumeric1 || nonAlphaNumeric2) {
331
- return 1;
332
- }
333
- return 0;
334
- }
335
- const NO_DIFF_MESSAGE = "Compared values have no visual difference.";
336
- const SIMILAR_MESSAGE = "Compared values serialize to the same structure.\nPrinting internal object structure without calling `toJSON` instead.";
337
- var build = {};
338
- var hasRequiredBuild;
339
- function requireBuild() {
340
- if (hasRequiredBuild) return build;
341
- hasRequiredBuild = 1;
342
- Object.defineProperty(build, "__esModule", {
343
- value: true
344
- });
345
- build.default = diffSequence;
346
- const pkg = "diff-sequences";
347
- const NOT_YET_SET = 0;
348
- const countCommonItemsF = (aIndex, aEnd, bIndex, bEnd, isCommon) => {
349
- let nCommon = 0;
350
- while (aIndex < aEnd && bIndex < bEnd && isCommon(aIndex, bIndex)) {
351
- aIndex += 1;
352
- bIndex += 1;
353
- nCommon += 1;
354
- }
355
- return nCommon;
356
- };
357
- const countCommonItemsR = (aStart, aIndex, bStart, bIndex, isCommon) => {
358
- let nCommon = 0;
359
- while (aStart <= aIndex && bStart <= bIndex && isCommon(aIndex, bIndex)) {
360
- aIndex -= 1;
361
- bIndex -= 1;
362
- nCommon += 1;
363
- }
364
- return nCommon;
365
- };
366
- const extendPathsF = (d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF) => {
367
- let iF = 0;
368
- let kF = -d;
369
- let aFirst = aIndexesF[iF];
370
- let aIndexPrev1 = aFirst;
371
- aIndexesF[iF] += countCommonItemsF(
372
- aFirst + 1,
373
- aEnd,
374
- bF + aFirst - kF + 1,
375
- bEnd,
376
- isCommon
377
- );
378
- const nF = d < iMaxF ? d : iMaxF;
379
- for (iF += 1, kF += 2; iF <= nF; iF += 1, kF += 2) {
380
- if (iF !== d && aIndexPrev1 < aIndexesF[iF]) {
381
- aFirst = aIndexesF[iF];
382
- } else {
383
- aFirst = aIndexPrev1 + 1;
384
- if (aEnd <= aFirst) {
385
- return iF - 1;
386
- }
387
- }
388
- aIndexPrev1 = aIndexesF[iF];
389
- aIndexesF[iF] = aFirst + countCommonItemsF(aFirst + 1, aEnd, bF + aFirst - kF + 1, bEnd, isCommon);
390
- }
391
- return iMaxF;
392
- };
393
- const extendPathsR = (d, aStart, bStart, bR, isCommon, aIndexesR, iMaxR) => {
394
- let iR = 0;
395
- let kR = d;
396
- let aFirst = aIndexesR[iR];
397
- let aIndexPrev1 = aFirst;
398
- aIndexesR[iR] -= countCommonItemsR(
399
- aStart,
400
- aFirst - 1,
401
- bStart,
402
- bR + aFirst - kR - 1,
403
- isCommon
404
- );
405
- const nR = d < iMaxR ? d : iMaxR;
406
- for (iR += 1, kR -= 2; iR <= nR; iR += 1, kR -= 2) {
407
- if (iR !== d && aIndexesR[iR] < aIndexPrev1) {
408
- aFirst = aIndexesR[iR];
409
- } else {
410
- aFirst = aIndexPrev1 - 1;
411
- if (aFirst < aStart) {
412
- return iR - 1;
413
- }
414
- }
415
- aIndexPrev1 = aIndexesR[iR];
416
- aIndexesR[iR] = aFirst - countCommonItemsR(
417
- aStart,
418
- aFirst - 1,
419
- bStart,
420
- bR + aFirst - kR - 1,
421
- isCommon
422
- );
423
- }
424
- return iMaxR;
425
- };
426
- const extendOverlappablePathsF = (d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division) => {
427
- const bF = bStart - aStart;
428
- const aLength = aEnd - aStart;
429
- const bLength = bEnd - bStart;
430
- const baDeltaLength = bLength - aLength;
431
- const kMinOverlapF = -baDeltaLength - (d - 1);
432
- const kMaxOverlapF = -baDeltaLength + (d - 1);
433
- let aIndexPrev1 = NOT_YET_SET;
434
- const nF = d < iMaxF ? d : iMaxF;
435
- for (let iF = 0, kF = -d; iF <= nF; iF += 1, kF += 2) {
436
- const insert = iF === 0 || iF !== d && aIndexPrev1 < aIndexesF[iF];
437
- const aLastPrev = insert ? aIndexesF[iF] : aIndexPrev1;
438
- const aFirst = insert ? aLastPrev : aLastPrev + 1;
439
- const bFirst = bF + aFirst - kF;
440
- const nCommonF = countCommonItemsF(
441
- aFirst + 1,
442
- aEnd,
443
- bFirst + 1,
444
- bEnd,
445
- isCommon
446
- );
447
- const aLast = aFirst + nCommonF;
448
- aIndexPrev1 = aIndexesF[iF];
449
- aIndexesF[iF] = aLast;
450
- if (kMinOverlapF <= kF && kF <= kMaxOverlapF) {
451
- const iR = (d - 1 - (kF + baDeltaLength)) / 2;
452
- if (iR <= iMaxR && aIndexesR[iR] - 1 <= aLast) {
453
- const bLastPrev = bF + aLastPrev - (insert ? kF + 1 : kF - 1);
454
- const nCommonR = countCommonItemsR(
455
- aStart,
456
- aLastPrev,
457
- bStart,
458
- bLastPrev,
459
- isCommon
460
- );
461
- const aIndexPrevFirst = aLastPrev - nCommonR;
462
- const bIndexPrevFirst = bLastPrev - nCommonR;
463
- const aEndPreceding = aIndexPrevFirst + 1;
464
- const bEndPreceding = bIndexPrevFirst + 1;
465
- division.nChangePreceding = d - 1;
466
- if (d - 1 === aEndPreceding + bEndPreceding - aStart - bStart) {
467
- division.aEndPreceding = aStart;
468
- division.bEndPreceding = bStart;
469
- } else {
470
- division.aEndPreceding = aEndPreceding;
471
- division.bEndPreceding = bEndPreceding;
472
- }
473
- division.nCommonPreceding = nCommonR;
474
- if (nCommonR !== 0) {
475
- division.aCommonPreceding = aEndPreceding;
476
- division.bCommonPreceding = bEndPreceding;
477
- }
478
- division.nCommonFollowing = nCommonF;
479
- if (nCommonF !== 0) {
480
- division.aCommonFollowing = aFirst + 1;
481
- division.bCommonFollowing = bFirst + 1;
482
- }
483
- const aStartFollowing = aLast + 1;
484
- const bStartFollowing = bFirst + nCommonF + 1;
485
- division.nChangeFollowing = d - 1;
486
- if (d - 1 === aEnd + bEnd - aStartFollowing - bStartFollowing) {
487
- division.aStartFollowing = aEnd;
488
- division.bStartFollowing = bEnd;
489
- } else {
490
- division.aStartFollowing = aStartFollowing;
491
- division.bStartFollowing = bStartFollowing;
492
- }
493
- return true;
494
- }
495
- }
496
- }
497
- return false;
498
- };
499
- const extendOverlappablePathsR = (d, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, iMaxF, aIndexesR, iMaxR, division) => {
500
- const bR = bEnd - aEnd;
501
- const aLength = aEnd - aStart;
502
- const bLength = bEnd - bStart;
503
- const baDeltaLength = bLength - aLength;
504
- const kMinOverlapR = baDeltaLength - d;
505
- const kMaxOverlapR = baDeltaLength + d;
506
- let aIndexPrev1 = NOT_YET_SET;
507
- const nR = d < iMaxR ? d : iMaxR;
508
- for (let iR = 0, kR = d; iR <= nR; iR += 1, kR -= 2) {
509
- const insert = iR === 0 || iR !== d && aIndexesR[iR] < aIndexPrev1;
510
- const aLastPrev = insert ? aIndexesR[iR] : aIndexPrev1;
511
- const aFirst = insert ? aLastPrev : aLastPrev - 1;
512
- const bFirst = bR + aFirst - kR;
513
- const nCommonR = countCommonItemsR(
514
- aStart,
515
- aFirst - 1,
516
- bStart,
517
- bFirst - 1,
518
- isCommon
519
- );
520
- const aLast = aFirst - nCommonR;
521
- aIndexPrev1 = aIndexesR[iR];
522
- aIndexesR[iR] = aLast;
523
- if (kMinOverlapR <= kR && kR <= kMaxOverlapR) {
524
- const iF = (d + (kR - baDeltaLength)) / 2;
525
- if (iF <= iMaxF && aLast - 1 <= aIndexesF[iF]) {
526
- const bLast = bFirst - nCommonR;
527
- division.nChangePreceding = d;
528
- if (d === aLast + bLast - aStart - bStart) {
529
- division.aEndPreceding = aStart;
530
- division.bEndPreceding = bStart;
531
- } else {
532
- division.aEndPreceding = aLast;
533
- division.bEndPreceding = bLast;
534
- }
535
- division.nCommonPreceding = nCommonR;
536
- if (nCommonR !== 0) {
537
- division.aCommonPreceding = aLast;
538
- division.bCommonPreceding = bLast;
539
- }
540
- division.nChangeFollowing = d - 1;
541
- if (d === 1) {
542
- division.nCommonFollowing = 0;
543
- division.aStartFollowing = aEnd;
544
- division.bStartFollowing = bEnd;
545
- } else {
546
- const bLastPrev = bR + aLastPrev - (insert ? kR - 1 : kR + 1);
547
- const nCommonF = countCommonItemsF(
548
- aLastPrev,
549
- aEnd,
550
- bLastPrev,
551
- bEnd,
552
- isCommon
553
- );
554
- division.nCommonFollowing = nCommonF;
555
- if (nCommonF !== 0) {
556
- division.aCommonFollowing = aLastPrev;
557
- division.bCommonFollowing = bLastPrev;
558
- }
559
- const aStartFollowing = aLastPrev + nCommonF;
560
- const bStartFollowing = bLastPrev + nCommonF;
561
- if (d - 1 === aEnd + bEnd - aStartFollowing - bStartFollowing) {
562
- division.aStartFollowing = aEnd;
563
- division.bStartFollowing = bEnd;
564
- } else {
565
- division.aStartFollowing = aStartFollowing;
566
- division.bStartFollowing = bStartFollowing;
567
- }
568
- }
569
- return true;
570
- }
571
- }
572
- }
573
- return false;
574
- };
575
- const divide = (nChange, aStart, aEnd, bStart, bEnd, isCommon, aIndexesF, aIndexesR, division) => {
576
- const bF = bStart - aStart;
577
- const bR = bEnd - aEnd;
578
- const aLength = aEnd - aStart;
579
- const bLength = bEnd - bStart;
580
- const baDeltaLength = bLength - aLength;
581
- let iMaxF = aLength;
582
- let iMaxR = aLength;
583
- aIndexesF[0] = aStart - 1;
584
- aIndexesR[0] = aEnd;
585
- if (baDeltaLength % 2 === 0) {
586
- const dMin = (nChange || baDeltaLength) / 2;
587
- const dMax = (aLength + bLength) / 2;
588
- for (let d = 1; d <= dMax; d += 1) {
589
- iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
590
- if (d < dMin) {
591
- iMaxR = extendPathsR(d, aStart, bStart, bR, isCommon, aIndexesR, iMaxR);
592
- } else if (
593
- // If a reverse path overlaps a forward path in the same diagonal,
594
- // return a division of the index intervals at the middle change.
595
- extendOverlappablePathsR(
596
- d,
597
- aStart,
598
- aEnd,
599
- bStart,
600
- bEnd,
601
- isCommon,
602
- aIndexesF,
603
- iMaxF,
604
- aIndexesR,
605
- iMaxR,
606
- division
607
- )
608
- ) {
609
- return;
610
- }
611
- }
612
- } else {
613
- const dMin = ((nChange || baDeltaLength) + 1) / 2;
614
- const dMax = (aLength + bLength + 1) / 2;
615
- let d = 1;
616
- iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
617
- for (d += 1; d <= dMax; d += 1) {
618
- iMaxR = extendPathsR(
619
- d - 1,
620
- aStart,
621
- bStart,
622
- bR,
623
- isCommon,
624
- aIndexesR,
625
- iMaxR
626
- );
627
- if (d < dMin) {
628
- iMaxF = extendPathsF(d, aEnd, bEnd, bF, isCommon, aIndexesF, iMaxF);
629
- } else if (
630
- // If a forward path overlaps a reverse path in the same diagonal,
631
- // return a division of the index intervals at the middle change.
632
- extendOverlappablePathsF(
633
- d,
634
- aStart,
635
- aEnd,
636
- bStart,
637
- bEnd,
638
- isCommon,
639
- aIndexesF,
640
- iMaxF,
641
- aIndexesR,
642
- iMaxR,
643
- division
644
- )
645
- ) {
646
- return;
647
- }
648
- }
649
- }
650
- throw new Error(
651
- `${pkg}: no overlap aStart=${aStart} aEnd=${aEnd} bStart=${bStart} bEnd=${bEnd}`
652
- );
653
- };
654
- const findSubsequences = (nChange, aStart, aEnd, bStart, bEnd, transposed, callbacks, aIndexesF, aIndexesR, division) => {
655
- if (bEnd - bStart < aEnd - aStart) {
656
- transposed = !transposed;
657
- if (transposed && callbacks.length === 1) {
658
- const { foundSubsequence: foundSubsequence2, isCommon: isCommon2 } = callbacks[0];
659
- callbacks[1] = {
660
- foundSubsequence: (nCommon, bCommon, aCommon) => {
661
- foundSubsequence2(nCommon, aCommon, bCommon);
662
- },
663
- isCommon: (bIndex, aIndex) => isCommon2(aIndex, bIndex)
664
- };
665
- }
666
- const tStart = aStart;
667
- const tEnd = aEnd;
668
- aStart = bStart;
669
- aEnd = bEnd;
670
- bStart = tStart;
671
- bEnd = tEnd;
672
- }
673
- const { foundSubsequence, isCommon } = callbacks[transposed ? 1 : 0];
674
- divide(
675
- nChange,
676
- aStart,
677
- aEnd,
678
- bStart,
679
- bEnd,
680
- isCommon,
681
- aIndexesF,
682
- aIndexesR,
683
- division
684
- );
685
- const {
686
- nChangePreceding,
687
- aEndPreceding,
688
- bEndPreceding,
689
- nCommonPreceding,
690
- aCommonPreceding,
691
- bCommonPreceding,
692
- nCommonFollowing,
693
- aCommonFollowing,
694
- bCommonFollowing,
695
- nChangeFollowing,
696
- aStartFollowing,
697
- bStartFollowing
698
- } = division;
699
- if (aStart < aEndPreceding && bStart < bEndPreceding) {
700
- findSubsequences(
701
- nChangePreceding,
702
- aStart,
703
- aEndPreceding,
704
- bStart,
705
- bEndPreceding,
706
- transposed,
707
- callbacks,
708
- aIndexesF,
709
- aIndexesR,
710
- division
711
- );
712
- }
713
- if (nCommonPreceding !== 0) {
714
- foundSubsequence(nCommonPreceding, aCommonPreceding, bCommonPreceding);
715
- }
716
- if (nCommonFollowing !== 0) {
717
- foundSubsequence(nCommonFollowing, aCommonFollowing, bCommonFollowing);
718
- }
719
- if (aStartFollowing < aEnd && bStartFollowing < bEnd) {
720
- findSubsequences(
721
- nChangeFollowing,
722
- aStartFollowing,
723
- aEnd,
724
- bStartFollowing,
725
- bEnd,
726
- transposed,
727
- callbacks,
728
- aIndexesF,
729
- aIndexesR,
730
- division
731
- );
732
- }
733
- };
734
- const validateLength = (name, arg) => {
735
- if (typeof arg !== "number") {
736
- throw new TypeError(`${pkg}: ${name} typeof ${typeof arg} is not a number`);
737
- }
738
- if (!Number.isSafeInteger(arg)) {
739
- throw new RangeError(`${pkg}: ${name} value ${arg} is not a safe integer`);
740
- }
741
- if (arg < 0) {
742
- throw new RangeError(`${pkg}: ${name} value ${arg} is a negative integer`);
743
- }
744
- };
745
- const validateCallback = (name, arg) => {
746
- const type = typeof arg;
747
- if (type !== "function") {
748
- throw new TypeError(`${pkg}: ${name} typeof ${type} is not a function`);
749
- }
750
- };
751
- function diffSequence(aLength, bLength, isCommon, foundSubsequence) {
752
- validateLength("aLength", aLength);
753
- validateLength("bLength", bLength);
754
- validateCallback("isCommon", isCommon);
755
- validateCallback("foundSubsequence", foundSubsequence);
756
- const nCommonF = countCommonItemsF(0, aLength, 0, bLength, isCommon);
757
- if (nCommonF !== 0) {
758
- foundSubsequence(nCommonF, 0, 0);
759
- }
760
- if (aLength !== nCommonF || bLength !== nCommonF) {
761
- const aStart = nCommonF;
762
- const bStart = nCommonF;
763
- const nCommonR = countCommonItemsR(
764
- aStart,
765
- aLength - 1,
766
- bStart,
767
- bLength - 1,
768
- isCommon
769
- );
770
- const aEnd = aLength - nCommonR;
771
- const bEnd = bLength - nCommonR;
772
- const nCommonFR = nCommonF + nCommonR;
773
- if (aLength !== nCommonFR && bLength !== nCommonFR) {
774
- const nChange = 0;
775
- const transposed = false;
776
- const callbacks = [
777
- {
778
- foundSubsequence,
779
- isCommon
780
- }
781
- ];
782
- const aIndexesF = [NOT_YET_SET];
783
- const aIndexesR = [NOT_YET_SET];
784
- const division = {
785
- aCommonFollowing: NOT_YET_SET,
786
- aCommonPreceding: NOT_YET_SET,
787
- aEndPreceding: NOT_YET_SET,
788
- aStartFollowing: NOT_YET_SET,
789
- bCommonFollowing: NOT_YET_SET,
790
- bCommonPreceding: NOT_YET_SET,
791
- bEndPreceding: NOT_YET_SET,
792
- bStartFollowing: NOT_YET_SET,
793
- nChangeFollowing: NOT_YET_SET,
794
- nChangePreceding: NOT_YET_SET,
795
- nCommonFollowing: NOT_YET_SET,
796
- nCommonPreceding: NOT_YET_SET
797
- };
798
- findSubsequences(
799
- nChange,
800
- aStart,
801
- aEnd,
802
- bStart,
803
- bEnd,
804
- transposed,
805
- callbacks,
806
- aIndexesF,
807
- aIndexesR,
808
- division
809
- );
810
- }
811
- if (nCommonR !== 0) {
812
- foundSubsequence(nCommonR, aEnd, bEnd);
813
- }
814
- }
815
- }
816
- return build;
817
- }
818
- var buildExports = /* @__PURE__ */ requireBuild();
819
- var diffSequences = /* @__PURE__ */ chunk_commonjsHelpers.g(buildExports);
820
- function formatTrailingSpaces(line, trailingSpaceFormatter) {
821
- return line.replace(/\s+$/, (match) => trailingSpaceFormatter(match));
822
- }
823
- function printDiffLine(line, isFirstOrLast, color, indicator, trailingSpaceFormatter, emptyFirstOrLastLinePlaceholder) {
824
- return line.length !== 0 ? color(`${indicator} ${formatTrailingSpaces(line, trailingSpaceFormatter)}`) : indicator !== " " ? color(indicator) : isFirstOrLast && emptyFirstOrLastLinePlaceholder.length !== 0 ? color(`${indicator} ${emptyFirstOrLastLinePlaceholder}`) : "";
825
- }
826
- function printDeleteLine(line, isFirstOrLast, { aColor, aIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
827
- return printDiffLine(line, isFirstOrLast, aColor, aIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
828
- }
829
- function printInsertLine(line, isFirstOrLast, { bColor, bIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
830
- return printDiffLine(line, isFirstOrLast, bColor, bIndicator, changeLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
831
- }
832
- function printCommonLine(line, isFirstOrLast, { commonColor, commonIndicator, commonLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder }) {
833
- return printDiffLine(line, isFirstOrLast, commonColor, commonIndicator, commonLineTrailingSpaceColor, emptyFirstOrLastLinePlaceholder);
834
- }
835
- function createPatchMark(aStart, aEnd, bStart, bEnd, { patchColor }) {
836
- return patchColor(`@@ -${aStart + 1},${aEnd - aStart} +${bStart + 1},${bEnd - bStart} @@`);
837
- }
838
- function joinAlignedDiffsNoExpand(diffs, options) {
839
- const iLength = diffs.length;
840
- const nContextLines = options.contextLines;
841
- const nContextLines2 = nContextLines + nContextLines;
842
- let jLength = iLength;
843
- let hasExcessAtStartOrEnd = false;
844
- let nExcessesBetweenChanges = 0;
845
- let i = 0;
846
- while (i !== iLength) {
847
- const iStart = i;
848
- while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
849
- i += 1;
850
- }
851
- if (iStart !== i) {
852
- if (iStart === 0) {
853
- if (i > nContextLines) {
854
- jLength -= i - nContextLines;
855
- hasExcessAtStartOrEnd = true;
856
- }
857
- } else if (i === iLength) {
858
- const n = i - iStart;
859
- if (n > nContextLines) {
860
- jLength -= n - nContextLines;
861
- hasExcessAtStartOrEnd = true;
862
- }
863
- } else {
864
- const n = i - iStart;
865
- if (n > nContextLines2) {
866
- jLength -= n - nContextLines2;
867
- nExcessesBetweenChanges += 1;
868
- }
869
- }
870
- }
871
- while (i !== iLength && diffs[i][0] !== DIFF_EQUAL) {
872
- i += 1;
873
- }
874
- }
875
- const hasPatch = nExcessesBetweenChanges !== 0 || hasExcessAtStartOrEnd;
876
- if (nExcessesBetweenChanges !== 0) {
877
- jLength += nExcessesBetweenChanges + 1;
878
- } else if (hasExcessAtStartOrEnd) {
879
- jLength += 1;
880
- }
881
- const jLast = jLength - 1;
882
- const lines = [];
883
- let jPatchMark = 0;
884
- if (hasPatch) {
885
- lines.push("");
886
- }
887
- let aStart = 0;
888
- let bStart = 0;
889
- let aEnd = 0;
890
- let bEnd = 0;
891
- const pushCommonLine = (line) => {
892
- const j = lines.length;
893
- lines.push(printCommonLine(line, j === 0 || j === jLast, options));
894
- aEnd += 1;
895
- bEnd += 1;
896
- };
897
- const pushDeleteLine = (line) => {
898
- const j = lines.length;
899
- lines.push(printDeleteLine(line, j === 0 || j === jLast, options));
900
- aEnd += 1;
901
- };
902
- const pushInsertLine = (line) => {
903
- const j = lines.length;
904
- lines.push(printInsertLine(line, j === 0 || j === jLast, options));
905
- bEnd += 1;
906
- };
907
- i = 0;
908
- while (i !== iLength) {
909
- let iStart = i;
910
- while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
911
- i += 1;
912
- }
913
- if (iStart !== i) {
914
- if (iStart === 0) {
915
- if (i > nContextLines) {
916
- iStart = i - nContextLines;
917
- aStart = iStart;
918
- bStart = iStart;
919
- aEnd = aStart;
920
- bEnd = bStart;
921
- }
922
- for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
923
- pushCommonLine(diffs[iCommon][1]);
924
- }
925
- } else if (i === iLength) {
926
- const iEnd = i - iStart > nContextLines ? iStart + nContextLines : i;
927
- for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
928
- pushCommonLine(diffs[iCommon][1]);
929
- }
930
- } else {
931
- const nCommon = i - iStart;
932
- if (nCommon > nContextLines2) {
933
- const iEnd = iStart + nContextLines;
934
- for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
935
- pushCommonLine(diffs[iCommon][1]);
936
- }
937
- lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
938
- jPatchMark = lines.length;
939
- lines.push("");
940
- const nOmit = nCommon - nContextLines2;
941
- aStart = aEnd + nOmit;
942
- bStart = bEnd + nOmit;
943
- aEnd = aStart;
944
- bEnd = bStart;
945
- for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1) {
946
- pushCommonLine(diffs[iCommon][1]);
947
- }
948
- } else {
949
- for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
950
- pushCommonLine(diffs[iCommon][1]);
951
- }
952
- }
953
- }
954
- }
955
- while (i !== iLength && diffs[i][0] === DIFF_DELETE) {
956
- pushDeleteLine(diffs[i][1]);
957
- i += 1;
958
- }
959
- while (i !== iLength && diffs[i][0] === DIFF_INSERT) {
960
- pushInsertLine(diffs[i][1]);
961
- i += 1;
962
- }
963
- }
964
- if (hasPatch) {
965
- lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
966
- }
967
- return lines.join("\n");
968
- }
969
- function joinAlignedDiffsExpand(diffs, options) {
970
- return diffs.map((diff2, i, diffs2) => {
971
- const line = diff2[1];
972
- const isFirstOrLast = i === 0 || i === diffs2.length - 1;
973
- switch (diff2[0]) {
974
- case DIFF_DELETE:
975
- return printDeleteLine(line, isFirstOrLast, options);
976
- case DIFF_INSERT:
977
- return printInsertLine(line, isFirstOrLast, options);
978
- default:
979
- return printCommonLine(line, isFirstOrLast, options);
980
- }
981
- }).join("\n");
982
- }
983
- const noColor = (string) => string;
984
- const DIFF_CONTEXT_DEFAULT = 5;
985
- const DIFF_TRUNCATE_THRESHOLD_DEFAULT = 0;
986
- function getDefaultOptions() {
987
- return {
988
- aAnnotation: "Expected",
989
- aColor: index$1.default.green,
990
- aIndicator: "-",
991
- bAnnotation: "Received",
992
- bColor: index$1.default.red,
993
- bIndicator: "+",
994
- changeColor: index$1.default.inverse,
995
- changeLineTrailingSpaceColor: noColor,
996
- commonColor: index$1.default.dim,
997
- commonIndicator: " ",
998
- commonLineTrailingSpaceColor: noColor,
999
- compareKeys: void 0,
1000
- contextLines: DIFF_CONTEXT_DEFAULT,
1001
- emptyFirstOrLastLinePlaceholder: "",
1002
- expand: false,
1003
- includeChangeCounts: false,
1004
- omitAnnotationLines: false,
1005
- patchColor: index$1.default.yellow,
1006
- printBasicPrototype: false,
1007
- truncateThreshold: DIFF_TRUNCATE_THRESHOLD_DEFAULT,
1008
- truncateAnnotation: "... Diff result is truncated",
1009
- truncateAnnotationColor: noColor
1010
- };
1011
- }
1012
- function getCompareKeys(compareKeys) {
1013
- return compareKeys && typeof compareKeys === "function" ? compareKeys : void 0;
1014
- }
1015
- function getContextLines(contextLines) {
1016
- return typeof contextLines === "number" && Number.isSafeInteger(contextLines) && contextLines >= 0 ? contextLines : DIFF_CONTEXT_DEFAULT;
1017
- }
1018
- function normalizeDiffOptions(options = {}) {
1019
- return {
1020
- ...getDefaultOptions(),
1021
- ...options,
1022
- compareKeys: getCompareKeys(options.compareKeys),
1023
- contextLines: getContextLines(options.contextLines)
1024
- };
1025
- }
1026
- function isEmptyString(lines) {
1027
- return lines.length === 1 && lines[0].length === 0;
1028
- }
1029
- function countChanges(diffs) {
1030
- let a = 0;
1031
- let b = 0;
1032
- diffs.forEach((diff2) => {
1033
- switch (diff2[0]) {
1034
- case DIFF_DELETE:
1035
- a += 1;
1036
- break;
1037
- case DIFF_INSERT:
1038
- b += 1;
1039
- break;
1040
- }
1041
- });
1042
- return {
1043
- a,
1044
- b
1045
- };
1046
- }
1047
- function printAnnotation({ aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator, includeChangeCounts, omitAnnotationLines }, changeCounts) {
1048
- if (omitAnnotationLines) {
1049
- return "";
1050
- }
1051
- let aRest = "";
1052
- let bRest = "";
1053
- if (includeChangeCounts) {
1054
- const aCount = String(changeCounts.a);
1055
- const bCount = String(changeCounts.b);
1056
- const baAnnotationLengthDiff = bAnnotation.length - aAnnotation.length;
1057
- const aAnnotationPadding = " ".repeat(Math.max(0, baAnnotationLengthDiff));
1058
- const bAnnotationPadding = " ".repeat(Math.max(0, -baAnnotationLengthDiff));
1059
- const baCountLengthDiff = bCount.length - aCount.length;
1060
- const aCountPadding = " ".repeat(Math.max(0, baCountLengthDiff));
1061
- const bCountPadding = " ".repeat(Math.max(0, -baCountLengthDiff));
1062
- aRest = `${aAnnotationPadding} ${aIndicator} ${aCountPadding}${aCount}`;
1063
- bRest = `${bAnnotationPadding} ${bIndicator} ${bCountPadding}${bCount}`;
1064
- }
1065
- const a = `${aIndicator} ${aAnnotation}${aRest}`;
1066
- const b = `${bIndicator} ${bAnnotation}${bRest}`;
1067
- return `${aColor(a)}
1068
- ${bColor(b)}
1069
-
1070
- `;
1071
- }
1072
- function printDiffLines(diffs, truncated, options) {
1073
- return printAnnotation(options, countChanges(diffs)) + (options.expand ? joinAlignedDiffsExpand(diffs, options) : joinAlignedDiffsNoExpand(diffs, options)) + (truncated ? options.truncateAnnotationColor(`
1074
- ${options.truncateAnnotation}`) : "");
1075
- }
1076
- function diffLinesUnified(aLines, bLines, options) {
1077
- const normalizedOptions = normalizeDiffOptions(options);
1078
- const [diffs, truncated] = diffLinesRaw(isEmptyString(aLines) ? [] : aLines, isEmptyString(bLines) ? [] : bLines, normalizedOptions);
1079
- return printDiffLines(diffs, truncated, normalizedOptions);
1080
- }
1081
- function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCompare, options) {
1082
- if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
1083
- aLinesDisplay = [];
1084
- aLinesCompare = [];
1085
- }
1086
- if (isEmptyString(bLinesDisplay) && isEmptyString(bLinesCompare)) {
1087
- bLinesDisplay = [];
1088
- bLinesCompare = [];
1089
- }
1090
- if (aLinesDisplay.length !== aLinesCompare.length || bLinesDisplay.length !== bLinesCompare.length) {
1091
- return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
1092
- }
1093
- const [diffs, truncated] = diffLinesRaw(aLinesCompare, bLinesCompare, options);
1094
- let aIndex = 0;
1095
- let bIndex = 0;
1096
- diffs.forEach((diff2) => {
1097
- switch (diff2[0]) {
1098
- case DIFF_DELETE:
1099
- diff2[1] = aLinesDisplay[aIndex];
1100
- aIndex += 1;
1101
- break;
1102
- case DIFF_INSERT:
1103
- diff2[1] = bLinesDisplay[bIndex];
1104
- bIndex += 1;
1105
- break;
1106
- default:
1107
- diff2[1] = bLinesDisplay[bIndex];
1108
- aIndex += 1;
1109
- bIndex += 1;
1110
- }
1111
- });
1112
- return printDiffLines(diffs, truncated, normalizeDiffOptions(options));
1113
- }
1114
- function diffLinesRaw(aLines, bLines, options) {
1115
- const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
1116
- const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
1117
- const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
1118
- const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
1119
- const truncated = aLength !== aLines.length || bLength !== bLines.length;
1120
- const isCommon = (aIndex2, bIndex2) => aLines[aIndex2] === bLines[bIndex2];
1121
- const diffs = [];
1122
- let aIndex = 0;
1123
- let bIndex = 0;
1124
- const foundSubsequence = (nCommon, aCommon, bCommon) => {
1125
- for (; aIndex !== aCommon; aIndex += 1) {
1126
- diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
1127
- }
1128
- for (; bIndex !== bCommon; bIndex += 1) {
1129
- diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
1130
- }
1131
- for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) {
1132
- diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
1133
- }
1134
- };
1135
- diffSequences(aLength, bLength, isCommon, foundSubsequence);
1136
- for (; aIndex !== aLength; aIndex += 1) {
1137
- diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
1138
- }
1139
- for (; bIndex !== bLength; bIndex += 1) {
1140
- diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
1141
- }
1142
- return [diffs, truncated];
1143
- }
1144
- function getType(value) {
1145
- if (value === void 0) {
1146
- return "undefined";
1147
- } else if (value === null) {
1148
- return "null";
1149
- } else if (Array.isArray(value)) {
1150
- return "array";
1151
- } else if (typeof value === "boolean") {
1152
- return "boolean";
1153
- } else if (typeof value === "function") {
1154
- return "function";
1155
- } else if (typeof value === "number") {
1156
- return "number";
1157
- } else if (typeof value === "string") {
1158
- return "string";
1159
- } else if (typeof value === "bigint") {
1160
- return "bigint";
1161
- } else if (typeof value === "object") {
1162
- if (value != null) {
1163
- if (value.constructor === RegExp) {
1164
- return "regexp";
1165
- } else if (value.constructor === Map) {
1166
- return "map";
1167
- } else if (value.constructor === Set) {
1168
- return "set";
1169
- } else if (value.constructor === Date) {
1170
- return "date";
1171
- }
1172
- }
1173
- return "object";
1174
- } else if (typeof value === "symbol") {
1175
- return "symbol";
1176
- }
1177
- throw new Error(`value of unknown type: ${value}`);
1178
- }
1179
- function getNewLineSymbol(string) {
1180
- return string.includes("\r\n") ? "\r\n" : "\n";
1181
- }
1182
- function diffStrings(a, b, options) {
1183
- const truncate = (options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? false;
1184
- const truncateThreshold = Math.max(Math.floor((options === null || options === void 0 ? void 0 : options.truncateThreshold) ?? 0), 0);
1185
- let aLength = a.length;
1186
- let bLength = b.length;
1187
- if (truncate) {
1188
- const aMultipleLines = a.includes("\n");
1189
- const bMultipleLines = b.includes("\n");
1190
- const aNewLineSymbol = getNewLineSymbol(a);
1191
- const bNewLineSymbol = getNewLineSymbol(b);
1192
- const _a = aMultipleLines ? `${a.split(aNewLineSymbol, truncateThreshold).join(aNewLineSymbol)}
1193
- ` : a;
1194
- const _b = bMultipleLines ? `${b.split(bNewLineSymbol, truncateThreshold).join(bNewLineSymbol)}
1195
- ` : b;
1196
- aLength = _a.length;
1197
- bLength = _b.length;
1198
- }
1199
- const truncated = aLength !== a.length || bLength !== b.length;
1200
- const isCommon = (aIndex2, bIndex2) => a[aIndex2] === b[bIndex2];
1201
- let aIndex = 0;
1202
- let bIndex = 0;
1203
- const diffs = [];
1204
- const foundSubsequence = (nCommon, aCommon, bCommon) => {
1205
- if (aIndex !== aCommon) {
1206
- diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
1207
- }
1208
- if (bIndex !== bCommon) {
1209
- diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
1210
- }
1211
- aIndex = aCommon + nCommon;
1212
- bIndex = bCommon + nCommon;
1213
- diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
1214
- };
1215
- diffSequences(aLength, bLength, isCommon, foundSubsequence);
1216
- if (aIndex !== aLength) {
1217
- diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
1218
- }
1219
- if (bIndex !== bLength) {
1220
- diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
1221
- }
1222
- return [diffs, truncated];
1223
- }
1224
- function concatenateRelevantDiffs(op, diffs, changeColor) {
1225
- return diffs.reduce((reduced, diff2) => reduced + (diff2[0] === DIFF_EQUAL ? diff2[1] : diff2[0] === op && diff2[1].length !== 0 ? changeColor(diff2[1]) : ""), "");
1226
- }
1227
- class ChangeBuffer {
1228
- constructor(op, changeColor) {
1229
- __publicField(this, "op");
1230
- __publicField(this, "line");
1231
- __publicField(this, "lines");
1232
- __publicField(this, "changeColor");
1233
- this.op = op;
1234
- this.line = [];
1235
- this.lines = [];
1236
- this.changeColor = changeColor;
1237
- }
1238
- pushSubstring(substring) {
1239
- this.pushDiff(new Diff(this.op, substring));
1240
- }
1241
- pushLine() {
1242
- this.lines.push(this.line.length !== 1 ? 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]));
1243
- this.line.length = 0;
1244
- }
1245
- isLineEmpty() {
1246
- return this.line.length === 0;
1247
- }
1248
- // Minor input to buffer.
1249
- pushDiff(diff2) {
1250
- this.line.push(diff2);
1251
- }
1252
- // Main input to buffer.
1253
- align(diff2) {
1254
- const string = diff2[1];
1255
- if (string.includes("\n")) {
1256
- const substrings = string.split("\n");
1257
- const iLast = substrings.length - 1;
1258
- substrings.forEach((substring, i) => {
1259
- if (i < iLast) {
1260
- this.pushSubstring(substring);
1261
- this.pushLine();
1262
- } else if (substring.length !== 0) {
1263
- this.pushSubstring(substring);
1264
- }
1265
- });
1266
- } else {
1267
- this.pushDiff(diff2);
1268
- }
1269
- }
1270
- // Output from buffer.
1271
- moveLinesTo(lines) {
1272
- if (!this.isLineEmpty()) {
1273
- this.pushLine();
1274
- }
1275
- lines.push(...this.lines);
1276
- this.lines.length = 0;
1277
- }
1278
- }
1279
- class CommonBuffer {
1280
- constructor(deleteBuffer, insertBuffer) {
1281
- __publicField(this, "deleteBuffer");
1282
- __publicField(this, "insertBuffer");
1283
- __publicField(this, "lines");
1284
- this.deleteBuffer = deleteBuffer;
1285
- this.insertBuffer = insertBuffer;
1286
- this.lines = [];
1287
- }
1288
- pushDiffCommonLine(diff2) {
1289
- this.lines.push(diff2);
1290
- }
1291
- pushDiffChangeLines(diff2) {
1292
- const isDiffEmpty = diff2[1].length === 0;
1293
- if (!isDiffEmpty || this.deleteBuffer.isLineEmpty()) {
1294
- this.deleteBuffer.pushDiff(diff2);
1295
- }
1296
- if (!isDiffEmpty || this.insertBuffer.isLineEmpty()) {
1297
- this.insertBuffer.pushDiff(diff2);
1298
- }
1299
- }
1300
- flushChangeLines() {
1301
- this.deleteBuffer.moveLinesTo(this.lines);
1302
- this.insertBuffer.moveLinesTo(this.lines);
1303
- }
1304
- // Input to buffer.
1305
- align(diff2) {
1306
- const op = diff2[0];
1307
- const string = diff2[1];
1308
- if (string.includes("\n")) {
1309
- const substrings = string.split("\n");
1310
- const iLast = substrings.length - 1;
1311
- substrings.forEach((substring, i) => {
1312
- if (i === 0) {
1313
- const subdiff = new Diff(op, substring);
1314
- if (this.deleteBuffer.isLineEmpty() && this.insertBuffer.isLineEmpty()) {
1315
- this.flushChangeLines();
1316
- this.pushDiffCommonLine(subdiff);
1317
- } else {
1318
- this.pushDiffChangeLines(subdiff);
1319
- this.flushChangeLines();
1320
- }
1321
- } else if (i < iLast) {
1322
- this.pushDiffCommonLine(new Diff(op, substring));
1323
- } else if (substring.length !== 0) {
1324
- this.pushDiffChangeLines(new Diff(op, substring));
1325
- }
1326
- });
1327
- } else {
1328
- this.pushDiffChangeLines(diff2);
1329
- }
1330
- }
1331
- // Output from buffer.
1332
- getLines() {
1333
- this.flushChangeLines();
1334
- return this.lines;
1335
- }
1336
- }
1337
- function getAlignedDiffs(diffs, changeColor) {
1338
- const deleteBuffer = new ChangeBuffer(DIFF_DELETE, changeColor);
1339
- const insertBuffer = new ChangeBuffer(DIFF_INSERT, changeColor);
1340
- const commonBuffer = new CommonBuffer(deleteBuffer, insertBuffer);
1341
- diffs.forEach((diff2) => {
1342
- switch (diff2[0]) {
1343
- case DIFF_DELETE:
1344
- deleteBuffer.align(diff2);
1345
- break;
1346
- case DIFF_INSERT:
1347
- insertBuffer.align(diff2);
1348
- break;
1349
- default:
1350
- commonBuffer.align(diff2);
1351
- }
1352
- });
1353
- return commonBuffer.getLines();
1354
- }
1355
- function hasCommonDiff(diffs, isMultiline) {
1356
- if (isMultiline) {
1357
- const iLast = diffs.length - 1;
1358
- return diffs.some((diff2, i) => diff2[0] === DIFF_EQUAL && (i !== iLast || diff2[1] !== "\n"));
1359
- }
1360
- return diffs.some((diff2) => diff2[0] === DIFF_EQUAL);
1361
- }
1362
- function diffStringsUnified(a, b, options) {
1363
- if (a !== b && a.length !== 0 && b.length !== 0) {
1364
- const isMultiline = a.includes("\n") || b.includes("\n");
1365
- const [diffs, truncated] = diffStringsRaw(isMultiline ? `${a}
1366
- ` : a, isMultiline ? `${b}
1367
- ` : b, true, options);
1368
- if (hasCommonDiff(diffs, isMultiline)) {
1369
- const optionsNormalized = normalizeDiffOptions(options);
1370
- const lines = getAlignedDiffs(diffs, optionsNormalized.changeColor);
1371
- return printDiffLines(lines, truncated, optionsNormalized);
1372
- }
1373
- }
1374
- return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1375
- }
1376
- function diffStringsRaw(a, b, cleanup, options) {
1377
- const [diffs, truncated] = diffStrings(a, b, options);
1378
- {
1379
- diff_cleanupSemantic(diffs);
1380
- }
1381
- return [diffs, truncated];
1382
- }
1383
- function getCommonMessage(message, options) {
1384
- const { commonColor } = normalizeDiffOptions(options);
1385
- return commonColor(message);
1386
- }
1387
- const { AsymmetricMatcher, DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent } = index.plugins;
1388
- const PLUGINS = [
1389
- ReactTestComponent,
1390
- ReactElement,
1391
- DOMElement,
1392
- DOMCollection,
1393
- Immutable,
1394
- AsymmetricMatcher,
1395
- index.plugins.Error
1396
- ];
1397
- const FORMAT_OPTIONS = {
1398
- maxDepth: 20,
1399
- plugins: PLUGINS
1400
- };
1401
- const FALLBACK_FORMAT_OPTIONS = {
1402
- callToJSON: false,
1403
- maxDepth: 8,
1404
- plugins: PLUGINS
1405
- };
1406
- function diff(a, b, options) {
1407
- if (Object.is(a, b)) {
1408
- return "";
1409
- }
1410
- const aType = getType(a);
1411
- let expectedType = aType;
1412
- let omitDifference = false;
1413
- if (aType === "object" && typeof a.asymmetricMatch === "function") {
1414
- if (a.$$typeof !== /* @__PURE__ */ Symbol.for("jest.asymmetricMatcher")) {
1415
- return void 0;
1416
- }
1417
- if (typeof a.getExpectedType !== "function") {
1418
- return void 0;
1419
- }
1420
- expectedType = a.getExpectedType();
1421
- omitDifference = expectedType === "string";
1422
- }
1423
- if (expectedType !== getType(b)) {
1424
- let truncate = function(s) {
1425
- return s.length <= MAX_LENGTH ? s : `${s.slice(0, MAX_LENGTH)}...`;
1426
- };
1427
- const { aAnnotation, aColor, aIndicator, bAnnotation, bColor, bIndicator } = normalizeDiffOptions(options);
1428
- const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
1429
- let aDisplay = index.format(a, formatOptions);
1430
- let bDisplay = index.format(b, formatOptions);
1431
- const MAX_LENGTH = 1e5;
1432
- aDisplay = truncate(aDisplay);
1433
- bDisplay = truncate(bDisplay);
1434
- const aDiff = `${aColor(`${aIndicator} ${aAnnotation}:`)}
1435
- ${aDisplay}`;
1436
- const bDiff = `${bColor(`${bIndicator} ${bAnnotation}:`)}
1437
- ${bDisplay}`;
1438
- return `${aDiff}
1439
-
1440
- ${bDiff}`;
1441
- }
1442
- if (omitDifference) {
1443
- return void 0;
1444
- }
1445
- switch (aType) {
1446
- case "string":
1447
- return diffLinesUnified(a.split("\n"), b.split("\n"), options);
1448
- case "boolean":
1449
- case "number":
1450
- return comparePrimitive(a, b, options);
1451
- case "map":
1452
- return compareObjects(sortMap(a), sortMap(b), options);
1453
- case "set":
1454
- return compareObjects(sortSet(a), sortSet(b), options);
1455
- default:
1456
- return compareObjects(a, b, options);
1457
- }
1458
- }
1459
- function comparePrimitive(a, b, options) {
1460
- const aFormat = index.format(a, FORMAT_OPTIONS);
1461
- const bFormat = index.format(b, FORMAT_OPTIONS);
1462
- return aFormat === bFormat ? "" : diffLinesUnified(aFormat.split("\n"), bFormat.split("\n"), options);
1463
- }
1464
- function sortMap(map) {
1465
- return new Map(Array.from(map.entries()).sort());
1466
- }
1467
- function sortSet(set) {
1468
- return new Set(Array.from(set.values()).sort());
1469
- }
1470
- function compareObjects(a, b, options) {
1471
- let difference;
1472
- let hasThrown = false;
1473
- try {
1474
- const formatOptions = getFormatOptions(FORMAT_OPTIONS, options);
1475
- difference = getObjectsDifference(a, b, formatOptions, options);
1476
- } catch {
1477
- hasThrown = true;
1478
- }
1479
- const noDiffMessage = getCommonMessage(NO_DIFF_MESSAGE, options);
1480
- if (difference === void 0 || difference === noDiffMessage) {
1481
- const formatOptions = getFormatOptions(FALLBACK_FORMAT_OPTIONS, options);
1482
- difference = getObjectsDifference(a, b, formatOptions, options);
1483
- if (difference !== noDiffMessage && !hasThrown) {
1484
- difference = `${getCommonMessage(SIMILAR_MESSAGE, options)}
1485
-
1486
- ${difference}`;
1487
- }
1488
- }
1489
- return difference;
1490
- }
1491
- function getFormatOptions(formatOptions, options) {
1492
- const { compareKeys, printBasicPrototype, maxDepth } = normalizeDiffOptions(options);
1493
- return {
1494
- ...formatOptions,
1495
- compareKeys,
1496
- printBasicPrototype,
1497
- maxDepth: maxDepth ?? formatOptions.maxDepth
1498
- };
1499
- }
1500
- function getObjectsDifference(a, b, formatOptions, options) {
1501
- const formatOptionsZeroIndent = {
1502
- ...formatOptions,
1503
- indent: 0
1504
- };
1505
- const aCompare = index.format(a, formatOptionsZeroIndent);
1506
- const bCompare = index.format(b, formatOptionsZeroIndent);
1507
- if (aCompare === bCompare) {
1508
- return getCommonMessage(NO_DIFF_MESSAGE, options);
1509
- } else {
1510
- const aDisplay = index.format(a, formatOptions);
1511
- const bDisplay = index.format(b, formatOptions);
1512
- return diffLinesUnified2(aDisplay.split("\n"), bDisplay.split("\n"), aCompare.split("\n"), bCompare.split("\n"), options);
1513
- }
1514
- }
1515
- const MAX_DIFF_STRING_LENGTH = 2e4;
1516
- function isAsymmetricMatcher(data) {
1517
- const type = helpers.getType(data);
1518
- return type === "Object" && typeof data.asymmetricMatch === "function";
1519
- }
1520
- function isReplaceable(obj1, obj2) {
1521
- const obj1Type = helpers.getType(obj1);
1522
- const obj2Type = helpers.getType(obj2);
1523
- return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
1524
- }
1525
- function printDiffOrStringify(received, expected, options) {
1526
- const { aAnnotation, bAnnotation } = normalizeDiffOptions(options);
1527
- if (typeof expected === "string" && typeof received === "string" && expected.length > 0 && received.length > 0 && expected.length <= MAX_DIFF_STRING_LENGTH && received.length <= MAX_DIFF_STRING_LENGTH && expected !== received) {
1528
- if (expected.includes("\n") || received.includes("\n")) {
1529
- return diffStringsUnified(expected, received, options);
1530
- }
1531
- const [diffs] = diffStringsRaw(expected, received);
1532
- const hasCommonDiff2 = diffs.some((diff2) => diff2[0] === DIFF_EQUAL);
1533
- const printLabel = getLabelPrinter(aAnnotation, bAnnotation);
1534
- const expectedLine = printLabel(aAnnotation) + printExpected(getCommonAndChangedSubstrings(diffs, DIFF_DELETE, hasCommonDiff2));
1535
- const receivedLine = printLabel(bAnnotation) + printReceived(getCommonAndChangedSubstrings(diffs, DIFF_INSERT, hasCommonDiff2));
1536
- return `${expectedLine}
1537
- ${receivedLine}`;
1538
- }
1539
- const clonedExpected = helpers.deepClone(expected, { forceWritable: true });
1540
- const clonedReceived = helpers.deepClone(received, { forceWritable: true });
1541
- const { replacedExpected, replacedActual } = replaceAsymmetricMatcher(clonedReceived, clonedExpected);
1542
- const difference = diff(replacedExpected, replacedActual, options);
1543
- return difference;
1544
- }
1545
- function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
1546
- if (actual instanceof Error && expected instanceof Error && typeof actual.cause !== "undefined" && typeof expected.cause === "undefined") {
1547
- delete actual.cause;
1548
- return {
1549
- replacedActual: actual,
1550
- replacedExpected: expected
1551
- };
1552
- }
1553
- if (!isReplaceable(actual, expected)) {
1554
- return {
1555
- replacedActual: actual,
1556
- replacedExpected: expected
1557
- };
1558
- }
1559
- if (actualReplaced.has(actual) || expectedReplaced.has(expected)) {
1560
- return {
1561
- replacedActual: actual,
1562
- replacedExpected: expected
1563
- };
1564
- }
1565
- actualReplaced.add(actual);
1566
- expectedReplaced.add(expected);
1567
- helpers.getOwnProperties(expected).forEach((key) => {
1568
- const expectedValue = expected[key];
1569
- const actualValue = actual[key];
1570
- if (isAsymmetricMatcher(expectedValue)) {
1571
- if (expectedValue.asymmetricMatch(actualValue)) {
1572
- expected[key] = actualValue;
1573
- } else if ("sample" in expectedValue && expectedValue.sample !== void 0 && isReplaceable(actualValue, expectedValue.sample)) {
1574
- const replaced = replaceAsymmetricMatcher(actualValue, expectedValue.sample, actualReplaced, expectedReplaced);
1575
- actual[key] = replaced.replacedActual;
1576
- expected[key] = replaced.replacedExpected;
1577
- }
1578
- } else if (isAsymmetricMatcher(actualValue)) {
1579
- if (actualValue.asymmetricMatch(expectedValue)) {
1580
- actual[key] = expectedValue;
1581
- } else if ("sample" in actualValue && actualValue.sample !== void 0 && isReplaceable(actualValue.sample, expectedValue)) {
1582
- const replaced = replaceAsymmetricMatcher(actualValue.sample, expectedValue, actualReplaced, expectedReplaced);
1583
- actual[key] = replaced.replacedActual;
1584
- expected[key] = replaced.replacedExpected;
1585
- }
1586
- } else if (isReplaceable(actualValue, expectedValue)) {
1587
- const replaced = replaceAsymmetricMatcher(actualValue, expectedValue, actualReplaced, expectedReplaced);
1588
- actual[key] = replaced.replacedActual;
1589
- expected[key] = replaced.replacedExpected;
1590
- }
1591
- });
1592
- return {
1593
- replacedActual: actual,
1594
- replacedExpected: expected
1595
- };
1596
- }
1597
- function getLabelPrinter(...strings) {
1598
- const maxLength = strings.reduce((max, string) => string.length > max ? string.length : max, 0);
1599
- return (string) => `${string}: ${" ".repeat(maxLength - string.length)}`;
1600
- }
1601
- const SPACE_SYMBOL = "·";
1602
- function replaceTrailingSpaces(text) {
1603
- return text.replace(/\s+$/gm, (spaces) => SPACE_SYMBOL.repeat(spaces.length));
1604
- }
1605
- function printReceived(object) {
1606
- return index$1.default.red(replaceTrailingSpaces(display.stringify(object)));
1607
- }
1608
- function printExpected(value) {
1609
- return index$1.default.green(replaceTrailingSpaces(display.stringify(value)));
1610
- }
1611
- function getCommonAndChangedSubstrings(diffs, op, hasCommonDiff2) {
1612
- return diffs.reduce((reduced, diff2) => reduced + (diff2[0] === DIFF_EQUAL ? diff2[1] : diff2[0] === op ? hasCommonDiff2 ? index$1.default.inverse(diff2[1]) : diff2[1] : ""), "");
1613
- }
1614
- exports.DIFF_DELETE = DIFF_DELETE;
1615
- exports.DIFF_EQUAL = DIFF_EQUAL;
1616
- exports.DIFF_INSERT = DIFF_INSERT;
1617
- exports.Diff = Diff;
1618
- exports.diff = diff;
1619
- exports.diffLinesRaw = diffLinesRaw;
1620
- exports.diffLinesUnified = diffLinesUnified;
1621
- exports.diffLinesUnified2 = diffLinesUnified2;
1622
- exports.diffStringsRaw = diffStringsRaw;
1623
- exports.diffStringsUnified = diffStringsUnified;
1624
- exports.getLabelPrinter = getLabelPrinter;
1625
- exports.printDiffOrStringify = printDiffOrStringify;
1626
- exports.replaceAsymmetricMatcher = replaceAsymmetricMatcher;