DiffCodecTests.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* eslint-disable
  2. handle-callback-err,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const sinon = require('sinon');
  14. const chai = require('chai');
  15. const should = chai.should();
  16. const {
  17. expect
  18. } = chai;
  19. const modulePath = "../../../../app/js/DiffCodec.js";
  20. const SandboxedModule = require('sandboxed-module');
  21. describe("DiffCodec", function() {
  22. beforeEach(function() {
  23. this.callback = sinon.stub();
  24. return this.DiffCodec = SandboxedModule.require(modulePath);
  25. });
  26. return describe("diffAsShareJsOps", function() {
  27. it("should insert new text correctly", function(done) {
  28. this.before = ["hello world"];
  29. this.after = ["hello beautiful world"];
  30. return this.DiffCodec.diffAsShareJsOp(this.before, this.after, (error, ops) => {
  31. expect(ops).to.deep.equal([{
  32. i: "beautiful ",
  33. p: 6
  34. }
  35. ]);
  36. return done();
  37. });
  38. });
  39. it("should shift later inserts by previous inserts", function(done) {
  40. this.before = ["the boy played with the ball"];
  41. this.after = ["the tall boy played with the red ball"];
  42. return this.DiffCodec.diffAsShareJsOp(this.before, this.after, (error, ops) => {
  43. expect(ops).to.deep.equal([
  44. { i: "tall ", p: 4 },
  45. { i: "red ", p: 29 }
  46. ]);
  47. return done();
  48. });
  49. });
  50. it("should delete text correctly", function(done) {
  51. this.before = ["hello beautiful world"];
  52. this.after = ["hello world"];
  53. return this.DiffCodec.diffAsShareJsOp(this.before, this.after, (error, ops) => {
  54. expect(ops).to.deep.equal([{
  55. d: "beautiful ",
  56. p: 6
  57. }
  58. ]);
  59. return done();
  60. });
  61. });
  62. return it("should shift later deletes by the first deletes", function(done) {
  63. this.before = ["the tall boy played with the red ball"];
  64. this.after = ["the boy played with the ball"];
  65. return this.DiffCodec.diffAsShareJsOp(this.before, this.after, (error, ops) => {
  66. expect(ops).to.deep.equal([
  67. { d: "tall ", p: 4 },
  68. { d: "red ", p: 24 }
  69. ]);
  70. return done();
  71. });
  72. });
  73. });
  74. });