MCPcopy
hub / github.com/jestjs/jest / diffLinesUnified2

Function diffLinesUnified2

packages/jest-diff/src/diffLines.ts:114–163  ·  view source on GitHub ↗
(
  aLinesDisplay: Array<string>,
  bLinesDisplay: Array<string>,
  aLinesCompare: Array<string>,
  bLinesCompare: Array<string>,
  options?: DiffOptions,
)

Source from the content-addressed store, hash-verified

112// Compare the pair of comparison arrays line-by-line.
113// Format the corresponding lines in the pair of displayable arrays.
114export const diffLinesUnified2 = (
115 aLinesDisplay: Array<string>,
116 bLinesDisplay: Array<string>,
117 aLinesCompare: Array<string>,
118 bLinesCompare: Array<string>,
119 options?: DiffOptions,
120): string => {
121 if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
122 aLinesDisplay = [];
123 aLinesCompare = [];
124 }
125 if (isEmptyString(bLinesDisplay) && isEmptyString(bLinesCompare)) {
126 bLinesDisplay = [];
127 bLinesCompare = [];
128 }
129
130 if (
131 aLinesDisplay.length !== aLinesCompare.length ||
132 bLinesDisplay.length !== bLinesCompare.length
133 ) {
134 // Fall back to diff of display lines.
135 return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
136 }
137
138 const diffs = diffLinesRaw(aLinesCompare, bLinesCompare);
139
140 // Replace comparison lines with displayable lines.
141 let aIndex = 0;
142 let bIndex = 0;
143 for (const diff of diffs) {
144 switch (diff[0]) {
145 case DIFF_DELETE:
146 diff[1] = aLinesDisplay[aIndex];
147 aIndex += 1;
148 break;
149
150 case DIFF_INSERT:
151 diff[1] = bLinesDisplay[bIndex];
152 bIndex += 1;
153 break;
154
155 default:
156 diff[1] = bLinesDisplay[bIndex];
157 aIndex += 1;
158 bIndex += 1;
159 }
160 }
161
162 return printDiffLines(diffs, normalizeDiffOptions(options));
163};
164
165// Compare two arrays of strings line-by-line.
166export const diffLinesRaw = (

Callers 3

getObjectsDifferenceFunction · 0.90
diff.test.tsFile · 0.90
printSnapshotAndReceivedFunction · 0.90

Calls 5

normalizeDiffOptionsFunction · 0.90
diffLinesUnifiedFunction · 0.85
diffLinesRawFunction · 0.85
printDiffLinesFunction · 0.85
isEmptyStringFunction · 0.70

Tested by

no test coverage detected