-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathDiffer.coffee
65 lines (60 loc) · 1.69 KB
/
Differ.coffee
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
{Differ} = require '..'
suite 'Differ'
test '#_qformat', ->
d = new Differ
results = d._qformat('\tabcDefghiJkl\n', '\tabcdefGhijkl\n',
' ^ ^ ^ ', ' ^ ^ ^ ')
results.should.eql [
'- \tabcDefghiJkl\n',
'? \t ^ ^ ^\n',
'+ \tabcdefGhijkl\n',
'? \t ^ ^ ^\n'
]
test '#_fancyReplace', ->
d = new Differ
d._fancyReplace(['abcDefghiJkl\n'], 0, 1,
['abcdefGhijkl\n'], 0, 1).should.eql [
'- abcDefghiJkl\n',
'? ^ ^ ^\n',
'+ abcdefGhijkl\n',
'? ^ ^ ^\n'
]
test '#compare', ->
d = new Differ
d.compare(['one\n', 'two\n', 'three\n'],
['ore\n', 'tree\n', 'emu\n']).should.eql [
'- one\n',
'? ^\n',
'+ ore\n',
'? ^\n',
'- two\n',
'- three\n',
'? -\n',
'+ tree\n',
'+ emu\n'
]
text1 = [
'1. Beautiful is better than ugly.\n',
'2. Explicit is better than implicit.\n',
'3. Simple is better than complex.\n',
'4. Complex is better than complicated.\n'
]
text2 = [
'1. Beautiful is better than ugly.\n',
'3. Simple is better than complex.\n',
'4. Complicated is better than complex.\n',
'5. Flat is better than nested.\n'
]
d = new Differ()
d.compare(text1, text2).should.eql [
' 1. Beautiful is better than ugly.\n',
'- 2. Explicit is better than implicit.\n',
'- 3. Simple is better than complex.\n',
'+ 3. Simple is better than complex.\n',
'? ++\n',
'- 4. Complex is better than complicated.\n',
'? ^ ---- ^\n',
'+ 4. Complicated is better than complex.\n',
'? ++++ ^ ^\n',
'+ 5. Flat is better than nested.\n'
]