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

Function diffLinesRaw

packages/jest-diff/src/diffLines.ts:166–207  ·  view source on GitHub ↗
(
  aLines: Array<string>,
  bLines: Array<string>,
)

Source from the content-addressed store, hash-verified

164
165// Compare two arrays of strings line-by-line.
166export const diffLinesRaw = (
167 aLines: Array<string>,
168 bLines: Array<string>,
169): Array<Diff> => {
170 const aLength = aLines.length;
171 const bLength = bLines.length;
172
173 const isCommon = (aIndex: number, bIndex: number) =>
174 aLines[aIndex] === bLines[bIndex];
175
176 const diffs: Array<Diff> = [];
177 let aIndex = 0;
178 let bIndex = 0;
179
180 const foundSubsequence = (
181 nCommon: number,
182 aCommon: number,
183 bCommon: number,
184 ) => {
185 for (; aIndex !== aCommon; aIndex += 1) {
186 diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
187 }
188 for (; bIndex !== bCommon; bIndex += 1) {
189 diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
190 }
191 for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) {
192 diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
193 }
194 };
195
196 diff(aLength, bLength, isCommon, foundSubsequence);
197
198 // After the last common subsequence, push remaining change items.
199 for (; aIndex !== aLength; aIndex += 1) {
200 diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
201 }
202 for (; bIndex !== bLength; bIndex += 1) {
203 diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
204 }
205
206 return diffs;
207};

Callers 2

diffLinesUnifiedFunction · 0.85
diffLinesUnified2Function · 0.85

Calls 1

diffFunction · 0.70

Tested by

no test coverage detected