2020-05-06 06:11:22 -04:00
|
|
|
/* eslint-disable
|
|
|
|
handle-callback-err,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-05-06 06:10:51 -04:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const chai = require('chai');
|
|
|
|
const should = chai.should();
|
|
|
|
const {
|
|
|
|
expect
|
|
|
|
} = chai;
|
|
|
|
const modulePath = "../../../../app/js/DiffCodec.js";
|
|
|
|
const SandboxedModule = require('sandboxed-module');
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:10:51 -04:00
|
|
|
describe("DiffCodec", function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
this.callback = sinon.stub();
|
|
|
|
return this.DiffCodec = SandboxedModule.require(modulePath);
|
|
|
|
});
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:10:51 -04:00
|
|
|
return describe("diffAsShareJsOps", function() {
|
|
|
|
it("should insert new text correctly", function(done) {
|
|
|
|
this.before = ["hello world"];
|
|
|
|
this.after = ["hello beautiful world"];
|
2020-05-06 06:11:22 -04:00
|
|
|
return this.DiffCodec.diffAsShareJsOp(this.before, this.after, (error, ops) => {
|
2020-05-06 06:10:51 -04:00
|
|
|
expect(ops).to.deep.equal([{
|
|
|
|
i: "beautiful ",
|
2014-02-12 05:40:42 -05:00
|
|
|
p: 6
|
2020-05-06 06:10:51 -04:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:10:51 -04:00
|
|
|
it("should shift later inserts by previous inserts", function(done) {
|
|
|
|
this.before = ["the boy played with the ball"];
|
|
|
|
this.after = ["the tall boy played with the red ball"];
|
2020-05-06 06:11:22 -04:00
|
|
|
return this.DiffCodec.diffAsShareJsOp(this.before, this.after, (error, ops) => {
|
2020-05-06 06:10:51 -04:00
|
|
|
expect(ops).to.deep.equal([
|
|
|
|
{ i: "tall ", p: 4 },
|
2014-02-12 05:40:42 -05:00
|
|
|
{ i: "red ", p: 29 }
|
2020-05-06 06:10:51 -04:00
|
|
|
]);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:10:51 -04:00
|
|
|
it("should delete text correctly", function(done) {
|
|
|
|
this.before = ["hello beautiful world"];
|
|
|
|
this.after = ["hello world"];
|
2020-05-06 06:11:22 -04:00
|
|
|
return this.DiffCodec.diffAsShareJsOp(this.before, this.after, (error, ops) => {
|
2020-05-06 06:10:51 -04:00
|
|
|
expect(ops).to.deep.equal([{
|
|
|
|
d: "beautiful ",
|
2014-02-12 05:40:42 -05:00
|
|
|
p: 6
|
2020-05-06 06:10:51 -04:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
|
2020-05-06 06:10:51 -04:00
|
|
|
return it("should shift later deletes by the first deletes", function(done) {
|
|
|
|
this.before = ["the tall boy played with the red ball"];
|
|
|
|
this.after = ["the boy played with the ball"];
|
2020-05-06 06:11:22 -04:00
|
|
|
return this.DiffCodec.diffAsShareJsOp(this.before, this.after, (error, ops) => {
|
2020-05-06 06:10:51 -04:00
|
|
|
expect(ops).to.deep.equal([
|
|
|
|
{ d: "tall ", p: 4 },
|
2014-02-12 05:40:42 -05:00
|
|
|
{ d: "red ", p: 24 }
|
2020-05-06 06:10:51 -04:00
|
|
|
]);
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-02-12 05:40:42 -05:00
|
|
|
|
|
|
|
|
|
|
|
|