Commit f23737a4 authored by Winnie Hellmann's avatar Winnie Hellmann

Refactor diff_spec.js to use table-based tests

parent 61d08f57
...@@ -9,60 +9,57 @@ describe('Multi-file editor library diff calculator', () => { ...@@ -9,60 +9,57 @@ describe('Multi-file editor library diff calculator', () => {
}); });
describe('modified', () => { describe('modified', () => {
it('', () => { it.each`
const diff = computeDiff('123', '1234')[0]; originalContent | newContent | lineNumber
${'123'} | ${'1234'} | ${1}
expect(diff.added).toBeTruthy(); ${'123\n123\n123'} | ${'123\n1234\n123'} | ${2}
expect(diff.modified).toBeTruthy(); `(
expect(diff.removed).toBeUndefined(); 'marks line $lineNumber as added and modified but not removed',
}); ({ originalContent, newContent, lineNumber }) => {
const diff = computeDiff(originalContent, newContent)[0];
it('', () => {
const diff = computeDiff('123\n123\n123', '123\n1234\n123')[0]; expect(diff.added).toBeTruthy();
expect(diff.modified).toBeTruthy();
expect(diff.added).toBeTruthy(); expect(diff.removed).toBeUndefined();
expect(diff.modified).toBeTruthy(); expect(diff.lineNumber).toBe(lineNumber);
expect(diff.removed).toBeUndefined(); },
expect(diff.lineNumber).toBe(2); );
});
}); });
describe('added', () => { describe('added', () => {
it('', () => { it.each`
const diff = computeDiff('123', '123\n123')[0]; originalContent | newContent | lineNumber
${'123'} | ${'123\n123'} | ${1}
expect(diff.added).toBeTruthy(); ${'123\n123\n123'} | ${'123\n123\n1234\n123'} | ${3}
expect(diff.modified).toBeUndefined(); `(
expect(diff.removed).toBeUndefined(); 'marks line $lineNumber as added but not modified and not removed',
}); ({ originalContent, newContent, lineNumber }) => {
const diff = computeDiff(originalContent, newContent)[0];
it('', () => {
const diff = computeDiff('123\n123\n123', '123\n123\n1234\n123')[0]; expect(diff.added).toBeTruthy();
expect(diff.modified).toBeUndefined();
expect(diff.added).toBeTruthy(); expect(diff.removed).toBeUndefined();
expect(diff.modified).toBeUndefined(); expect(diff.lineNumber).toBe(lineNumber);
expect(diff.removed).toBeUndefined(); },
expect(diff.lineNumber).toBe(3); );
});
}); });
describe('removed', () => { describe('removed', () => {
it('', () => { it.each`
const diff = computeDiff('123', '')[0]; originalContent | newContent | lineNumber | modified
${'123'} | ${''} | ${1} | ${undefined}
expect(diff.added).toBeUndefined(); ${'123\n123\n123'} | ${'123\n123'} | ${2} | ${true}
expect(diff.modified).toBeUndefined(); `(
expect(diff.removed).toBeTruthy(); 'marks line $lineNumber as removed',
}); ({ originalContent, newContent, lineNumber, modified }) => {
const diff = computeDiff(originalContent, newContent)[0];
it('', () => {
const diff = computeDiff('123\n123\n123', '123\n123')[0]; expect(diff.added).toBeUndefined();
expect(diff.modified).toBe(modified);
expect(diff.added).toBeUndefined(); expect(diff.removed).toBeTruthy();
expect(diff.modified).toBeTruthy(); expect(diff.lineNumber).toBe(lineNumber);
expect(diff.removed).toBeTruthy(); },
expect(diff.lineNumber).toBe(2); );
});
}); });
it('includes line number of change', () => { it('includes line number of change', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment