-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathsentence.js
52 lines (45 loc) · 1.68 KB
/
sentence.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
import {diffSentences, sentenceDiff} from '../../lib/diff/sentence';
import {convertChangesToXML} from '../../lib/convert/xml';
import {expect} from 'chai';
describe('diff/sentence', function() {
describe('tokenize', function() {
it('should split on whitespace after a punctuation mark, and keep the whitespace as a token', function() {
expect(sentenceDiff.removeEmpty(sentenceDiff.tokenize(''))).to.eql([]);
expect(sentenceDiff.removeEmpty(sentenceDiff.tokenize(
'Foo bar baz! Qux wibbly wobbly bla? \n\tYayayaya!Yayayaya!Ya! Yes!!!!! Blub'
))).to.eql([
'Foo bar baz!',
' ',
'Qux wibbly wobbly bla?',
' \n\t',
'Yayayaya!Yayayaya!Ya!',
' ',
'Yes!!!!!',
' ',
'Blub'
]);
expect(sentenceDiff.removeEmpty(sentenceDiff.tokenize(
'! Hello there.'
))).to.eql([
'!',
' ',
'Hello there.'
]);
expect(sentenceDiff.removeEmpty(sentenceDiff.tokenize(
' foo bar baz.'
))).to.eql([
' foo bar baz.'
]);
});
});
describe('#diffSentences', function() {
it('Should diff Sentences', function() {
const diffResult = diffSentences('New Value.', 'New ValueMoreData.');
expect(convertChangesToXML(diffResult)).to.equal('<del>New Value.</del><ins>New ValueMoreData.</ins>');
});
it('should diff only the last sentence', function() {
const diffResult = diffSentences('Here im. Rock you like old man.', 'Here im. Rock you like hurricane.');
expect(convertChangesToXML(diffResult)).to.equal('Here im. <del>Rock you like old man.</del><ins>Rock you like hurricane.</ins>');
});
});
});