htmldiff
Version:
HTML Diffing in JavaScript (CoffeeScript)
66 lines (50 loc) • 2.13 kB
text/coffeescript
describe 'render_operations', ->
beforeEach ->
diff = (require '../src/htmldiff.coffee')
= (before, after)->
ops = diff.calculate_operations before, after
diff.render_operations before, after, ops
it 'should be a function', ->
(expect ).is.a 'function'
describe 'equal', ->
beforeEach ->
before = ['this', ' ', 'is', ' ', 'a', ' ', 'test']
= before, before
it 'should output the text', ->
(expect ).equal 'this is a test'
describe 'insert', ->
beforeEach ->
before = ['this', ' ', 'is']
after = ['this', ' ', 'is', ' ', 'a', ' ', 'test']
= before, after
it 'should wrap in an <ins>', ->
(expect ).equal 'this is<ins> a test</ins>'
describe 'delete', ->
beforeEach ->
before = ['this', ' ', 'is', ' ', 'a', ' ', 'test', \
' ', 'of', ' ', 'stuff']
after = ['this', ' ', 'is', ' ', 'a', ' ', 'test']
= before, after
it 'should wrap in a <del>', ->
(expect ).to.equal 'this is a test<del> of stuff</del>'
describe 'replace', ->
beforeEach ->
before = ['this', ' ', 'is', ' ', 'a', ' ', 'break']
after = ['this', ' ', 'is', ' ', 'a', ' ', 'test']
= before, after
it 'should wrap in both <ins> and <del>', ->
(expect ).to.equal 'this is a <del>break</del><ins>test</ins>'
describe 'Dealing with tags', ->
beforeEach ->
before = ['<p>', 'a', '</p>']
after = ['<p>', 'a', ' ', 'b', '</p>', '<p>', 'c', '</p>']
= before, after
it 'should make sure the <ins/del> tags are within the <p> tags', ->
(expect ).to.equal '<p>a<ins> b</ins></p><p><ins>c</ins></p>'
describe 'When there is a change at the beginning, in a <p>', ->
beforeEach ->
before = ['<p>', 'this', ' ', 'is', ' ', 'awesome', '</p>']
after = ['<p>', 'I', ' ', 'is', ' ', 'awesome', '</p>']
= before, after
it 'should keep the change inside the <p>', ->
(expect ).to.equal '<p><del>this</del><ins>I</ins> is awesome</p>'