react-diff-view
Version:
A git diff component to consume the git unified diff output.
68 lines • 2.02 kB
JavaScript
import { describe, test, expect } from 'vitest';
import markWord from '../markWord';
describe('markWord', () => {
test('no match', () => {
const mark = markWord('x', 'mark');
const input = [
[
[[{ type: 'text', value: 'abc' }]],
],
[
[[{ type: 'text', value: 'abc' }]],
],
];
const result = mark(input);
expect(result).toEqual(input);
});
test('single occurence', () => {
const mark = markWord('A', 'first', 'a');
const input = [
[
[[{ type: 'text', value: 'AAaabb' }]],
],
[
[[{ type: 'text', value: '' }]],
],
];
const result = mark(input);
const expected = [
[
[
[{ type: 'mark', markType: 'first', value: 'a' }],
[{ type: 'mark', markType: 'first', value: 'a' }],
[{ type: 'text', value: 'aabb' }],
],
],
[
[[{ type: 'text', value: '' }]],
],
];
expect(result).toEqual(expected);
});
test('complex word', () => {
const mark = markWord('\t', 'tab', ' ');
const input = [
[
[[{ type: 'text', value: '\t\t bb' }]],
],
[
[[{ type: 'text', value: '' }]],
],
];
const result = mark(input);
const expected = [
[
[
[{ markType: 'tab', type: 'mark', value: ' ' }],
[{ markType: 'tab', type: 'mark', value: ' ' }],
[{ type: 'text', value: ' bb' }],
],
],
[
[[{ type: 'text', value: '' }]],
],
];
expect(result).toEqual(expected);
});
});
//# sourceMappingURL=markWord.test.js.map