@noma.to/qwik-testing-library 1.3.1 → 1.4.0

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