2016-12-10 00:01:59 +01:00
|
|
|
/*eslint-env node, mocha */
|
|
|
|
/*global expect */
|
|
|
|
/*eslint no-console: 0*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import chai from 'chai'
|
|
|
|
|
|
|
|
import {markdownDiff, diffToString} from '../src/common/util/dubdiff'
|
|
|
|
|
|
|
|
let diff = (a,b) => diffToString(markdownDiff(a,b))
|
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('dubdiff', () => {
|
|
|
|
let db;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
});
|
|
|
|
|
|
|
|
it('plaintext diffs consecutive words', ()=>{
|
|
|
|
expect(diff(
|
|
|
|
'This is a smlb sentnce with no errors.',
|
|
|
|
'This is a simple sentence with no errors.'
|
2016-12-14 07:30:09 +01:00
|
|
|
)).to.equal('This is a [-smlb sentnce -]{+simple sentence +}with no errors.')
|
2016-12-10 00:01:59 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('plaintext diffs with word deletion', ()=>{
|
|
|
|
expect(diff(
|
|
|
|
'Gonna delete a word.',
|
|
|
|
'Gonna delete word.'
|
2016-12-14 07:30:09 +01:00
|
|
|
)).to.equal('Gonna delete [-a -]word.')
|
2016-12-10 00:01:59 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('plaintext diffs with word insertion', ()=>{
|
|
|
|
expect(diff(
|
|
|
|
'Gonna delete word.',
|
|
|
|
'Gonna delete a word.'
|
2016-12-14 07:30:09 +01:00
|
|
|
)).to.equal('Gonna delete {+a +}word.')
|
2016-12-10 00:01:59 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('reorganizes insertions after multiline deletions', ()=>{
|
|
|
|
expect(diff(
|
|
|
|
`# Title
|
|
|
|
other`,
|
|
|
|
`# Subtitle`
|
2016-12-14 07:30:09 +01:00
|
|
|
)).to.equal('# [-Title-]{+Subtitle+}[-\nother-]')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('pulls prefixes out of ins or del blocks after newline', () => {
|
|
|
|
expect(diff(
|
|
|
|
'# Title\n > hello',
|
|
|
|
'# Title\n - goodbye'
|
|
|
|
)).to.equal('# Title\n > [-hello-]\n - {+goodbye+}')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('respects bold and italic boundaries', () => {
|
|
|
|
expect(diff(
|
|
|
|
'This *word* **isn\'t** changed.',
|
|
|
|
'This *other one* **is** changed.'
|
|
|
|
)).to.equal('This *[-word-]{+other one+}* **[-isn\'t-]{+is+}** changed.')
|
|
|
|
})
|
|
|
|
it('respects link boundaries in link text', () => {
|
|
|
|
expect(diff(
|
|
|
|
'This [link](https://somewhere.com) is the same.',
|
|
|
|
'This [target](https://somewhere.com) changed.'
|
|
|
|
)).to.equal('This [[-link-]{+target+}](https://somewhere.com) [-is the same-]{+changed+}.')
|
|
|
|
})
|
|
|
|
it('respects link boundaries in link target', () => {
|
|
|
|
expect(diff(
|
|
|
|
'This [link](https://somewhere.com) is the same.',
|
|
|
|
'This [link](https://somewhere.org) changed.'
|
|
|
|
)).to.equal('This [link](https://somewhere.[-com-]{+org+}) [-is the same-]{+changed+}.')
|
2016-12-10 00:01:59 +01:00
|
|
|
})
|
|
|
|
})
|