All files / util/diff/__tests__ util.ts

100% Statements 22/22
100% Branches 1/1
100% Functions 5/5
100% Lines 21/21

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 25 26 27 28 29 30 31 32 33 34 35 36 37 383x   3x 482x 482x 482x 482x       1481x     1454x     482x 482x 482x 482x 482x       1454x     1481x     482x 482x 482x 482x 482x 482x    
import * as diff from '../str';
 
export const assertPatch = (src: string, dst: string, patch: diff.Patch = diff.diff(src, dst)) => {
  const src1 = diff.src(patch);
  const dst1 = diff.dst(patch);
  let dst2 = src;
  diff.apply(
    patch,
    dst2.length,
    (pos, str) => {
      dst2 = dst2.slice(0, pos) + str + dst2.slice(pos);
    },
    (pos, len) => {
      dst2 = dst2.slice(0, pos) + dst2.slice(pos + len);
    },
  );
  const inverted = diff.invert(patch);
  const src2 = diff.dst(inverted);
  const dst3 = diff.src(inverted);
  let src3 = dst;
  diff.apply(
    inverted,
    src3.length,
    (pos, str) => {
      src3 = src3.slice(0, pos) + str + src3.slice(pos);
    },
    (pos, len) => {
      src3 = src3.slice(0, pos) + src3.slice(pos + len);
    },
  );
  expect(src1).toBe(src);
  expect(src2).toBe(src);
  expect(src3).toBe(src);
  expect(dst1).toBe(dst);
  expect(dst2).toBe(dst);
  expect(dst3).toBe(dst);
};