DiffCodecTests.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. expect = chai.expect
  5. modulePath = "../../../../app/js/DiffCodec.js"
  6. SandboxedModule = require('sandboxed-module')
  7. describe "DiffCodec", ->
  8. beforeEach ->
  9. @callback = sinon.stub()
  10. @DiffCodec = SandboxedModule.require modulePath
  11. describe "diffAsShareJsOps", ->
  12. it "should insert new text correctly", (done) ->
  13. @before = ["hello world"]
  14. @after = ["hello beautiful world"]
  15. @DiffCodec.diffAsShareJsOp @before, @after, (error, ops) ->
  16. expect(ops).to.deep.equal [
  17. i: "beautiful "
  18. p: 6
  19. ]
  20. done()
  21. it "should shift later inserts by previous inserts", (done) ->
  22. @before = ["the boy played with the ball"]
  23. @after = ["the tall boy played with the red ball"]
  24. @DiffCodec.diffAsShareJsOp @before, @after, (error, ops) ->
  25. expect(ops).to.deep.equal [
  26. { i: "tall ", p: 4 }
  27. { i: "red ", p: 29 }
  28. ]
  29. done()
  30. it "should delete text correctly", (done) ->
  31. @before = ["hello beautiful world"]
  32. @after = ["hello world"]
  33. @DiffCodec.diffAsShareJsOp @before, @after, (error, ops) ->
  34. expect(ops).to.deep.equal [
  35. d: "beautiful "
  36. p: 6
  37. ]
  38. done()
  39. it "should shift later deletes by the first deletes", (done) ->
  40. @before = ["the tall boy played with the red ball"]
  41. @after = ["the boy played with the ball"]
  42. @DiffCodec.diffAsShareJsOp @before, @after, (error, ops) ->
  43. expect(ops).to.deep.equal [
  44. { d: "tall ", p: 4 }
  45. { d: "red ", p: 24 }
  46. ]
  47. done()