All files / util/diff/__tests__ line.ts

100% Statements 16/16
100% Branches 9/9
100% Functions 1/1
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 252x   2x     1038x   1038x 1038x 964x 2888x 2199x 730x 1469x 1008x 461x 461x       74x   1038x    
import * as line from '../line';
 
export const assertDiff = (src: string[], dst: string[]) => {
  // console.log('src', src);
  // console.log('dst', dst);
  const diff = line.diff(src, dst);
  // console.log(diff);
  const res: string[] = [];
  if (diff.length) {
    for (const [type, srcIdx, dstIdx, patch] of diff) {
      if (type === line.LINE_PATCH_OP_TYPE.DEL) {
      } else if (type === line.LINE_PATCH_OP_TYPE.INS) {
        res.push(dst[dstIdx]);
      } else if (type === line.LINE_PATCH_OP_TYPE.EQL) {
        res.push(src[srcIdx]);
      } else if (type === line.LINE_PATCH_OP_TYPE.MIX) {
        res.push(dst[dstIdx]);
      }
    }
  } else {
    res.push(...src);
  }
  expect(res).toEqual(dst);
};