dubdiff/test/dubdiffMarkdown.js

86 lines
2.4 KiB
JavaScript
Raw Normal View History

/* eslint-env node, mocha */
/* global expect */
/* eslint no-console: 0 */
'use strict'
2016-12-10 00:01:59 +01:00
import chai from 'chai'
import {markdownDiff, diffToString} from '../src/common/util/dubdiff'
2016-12-10 00:01:59 +01:00
let diff = (a, b) => diffToString(markdownDiff(a, b))
2016-12-10 00:01:59 +01:00
const expect = chai.expect // eslint-disable-line no-unused-vars
2016-12-10 00:01:59 +01:00
describe('dubdiff', () => {
beforeEach(() => {
})
2016-12-10 00:01:59 +01:00
it('plaintext diffs consecutive words', () => {
2016-12-10 00:01:59 +01:00
expect(diff(
'This is a smlb sentnce with no errors.',
'This is a simple sentence with no errors.'
)).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', () => {
2016-12-10 00:01:59 +01:00
expect(diff(
'Gonna delete a word.',
'Gonna delete word.'
)).to.equal('Gonna delete [-a -]word.')
2016-12-10 00:01:59 +01:00
})
it('plaintext diffs with word insertion', () => {
2016-12-10 00:01:59 +01:00
expect(diff(
'Gonna delete word.',
'Gonna delete a word.'
)).to.equal('Gonna delete {+a +}word.')
2016-12-10 00:01:59 +01:00
})
it('reorganizes insertions after multiline deletions', () => {
2016-12-10 00:01:59 +01:00
expect(diff(
`# Title
other`,
`# Subtitle`
2017-01-05 23:18:03 +01:00
)).to.equal('# [-Title-]{+Subtitle+}\n[-other-]')
})
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+}.')
})
it('deletes a title', () => {
2017-01-05 23:18:03 +01:00
expect(diff(
'Hello\n# Title 1\n# Title 2',
'Hello\n# Title 2'
)).to.equal('Hello\n# Title [-1-]\n# [-Title -]2')
2017-01-05 23:18:03 +01:00
})
it('deletes a more different title', () => {
2017-01-05 23:18:03 +01:00
expect(diff(
'Hello\n# Filbert\n# Title 2',
'Hello\n# Title 2'
)).to.equal('Hello\n# [-Filbert-]\n# Title 2')
2016-12-10 00:01:59 +01:00
})
2017-01-05 23:18:03 +01:00
})