-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
68 lines (59 loc) · 1.91 KB
/
test.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var assert = require('assert');
var worddiff = require('./index.js');
describe('word-diff', function() {
describe('#diffString(old, new)', function() {
it('identical', function() {
var diff = worddiff.diffString('apple', 'apple');
assert.deepEqual(diff, [{text: 'apple'}])
});
it('trivial diff', function() {
var diff = worddiff.diffString('apple', 'cider');
assert.deepEqual(diff, [
{remove: 'apple', add: 'cider'}
])
});
it('simple add', function() {
var diff = worddiff.diffString('apple', 'apple cider');
assert.deepEqual(diff, [
{text: 'apple'},
{remove: '', add: 'cider'},
])
});
it('simple remove', function() {
var diff = worddiff.diffString('apple computer', 'apple');
assert.deepEqual(diff, [
{text: 'apple '},
{remove: 'computer', add: ''}
])
});
it('ignore whitespace changes', function() {
var diff = worddiff.diffString('apple ', 'apple \n ');
assert.deepEqual(diff, [
{text: 'apple '}
])
});
it('preserve whitespaces', function() {
var diff = worddiff.diffString('good guy', 'bad \n guy');
assert.deepEqual(diff, [
{add: 'bad \n ', remove: 'good '},
{text: 'guy'}
])
});
it('multiword overwrite in the middle', function() {
var diff = worddiff.diffString('foo bar baz tiri biri bimm boo!', 'foo bar baz Yoo Higiri Hipp Hopp boo!');
assert.deepEqual(diff, [
{text: 'foo bar baz '},
{add: 'Yoo Higiri Hipp Hopp ', remove: 'tiri biri bimm '},
{text: 'boo!'},
])
});
it('multiword remove in the middle', function() {
var diff = worddiff.diffString('Apple, you are a Legend!', 'Apple, Legend!');
assert.deepEqual(diff, [
{text: 'Apple, '},
{add: '', remove: 'you are a '},
{text: 'Legend!'},
]);
});
});
});