dubdiff/test/dubdiffPlaintext.js

69 lines
1.7 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 {plaintextDiff, diffToString} from '../src/common/util/dubdiff'
let diff = (a, b) => diffToString(plaintextDiff(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('diffs single words', () => {
2016-12-10 00:01:59 +01:00
expect(diff(
'This is a smlb sentence.',
'This is a simple sentence.'
2016-12-10 00:41:21 +01:00
)).to.equal('This is a [-smlb -]{+simple +}sentence.')
2016-12-10 00:01:59 +01:00
})
it('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('diffs with word deletion', () => {
2016-12-10 00:01:59 +01:00
expect(diff(
'Gonna delete a word.',
'Gonna delete word.'
2016-12-10 00:41:21 +01:00
)).to.equal('Gonna delete [-a -]word.')
2016-12-10 00:01:59 +01:00
})
it('diffs with word insertion', () => {
2016-12-10 00:01:59 +01:00
expect(diff(
2016-12-10 00:41:21 +01:00
'Gonna add word.',
'Gonna add a word.'
)).to.equal('Gonna add {+a +}word.')
2016-12-10 00:01:59 +01:00
})
it('diffs accross newline without weird spaces', () => {
expect(diff(
'This is a flawed\ncomment',
'This is a corrected\nitem'
2016-12-10 00:41:21 +01:00
)).to.equal('This is a [-flawed-]{+corrected+}\n[-comment-]{+item+}')
2016-12-10 00:01:59 +01:00
})
it('doesn\'t add spaces after newline', () => {
expect(diff(
'\nhere',
'\nhere'
)).to.equal('\nhere')
})
it('doesn\'t add spaces before newline', () => {
expect(diff(
'there\n',
'there\n'
)).to.equal('there\n')
})
it('treats punctuation separately', () => {
expect(diff(
'Hello world.',
'Hello, world.'
)).to.equal('Hello{+, +}world.')
})
})