mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Create buildDiff function
This commit is contained in:
@@ -28,6 +28,10 @@ module.exports = DiffGenerator =
|
||||
return content
|
||||
|
||||
buildDiff: (initialContent, updates) ->
|
||||
diff = [ u: initialContent ]
|
||||
for update in updates
|
||||
diff = DiffGenerator.applyUpdateToDiff diff, update
|
||||
return diff
|
||||
|
||||
applyUpdateToDiff: (diff, update) ->
|
||||
position = 0
|
||||
|
||||
@@ -50,6 +50,34 @@ describe "DiffGenerator", ->
|
||||
rewoundContent = @DiffGenerator.rewindUpdates content, updates
|
||||
rewoundContent.should.equal "aaa"
|
||||
|
||||
describe "buildDiff", ->
|
||||
beforeEach ->
|
||||
@diff = [ u: "mock-diff" ]
|
||||
@content = "Hello world"
|
||||
@updates = [
|
||||
{ i: "mock-update-1" }
|
||||
{ i: "mock-update-2" }
|
||||
{ i: "mock-update-3" }
|
||||
]
|
||||
@DiffGenerator.applyUpdateToDiff = sinon.stub().returns(@diff)
|
||||
@result = @DiffGenerator.buildDiff(@content, @updates)
|
||||
|
||||
it "should return the diff", ->
|
||||
@result.should.deep.equal @diff
|
||||
|
||||
it "should build the content into an initial diff", ->
|
||||
@DiffGenerator.applyUpdateToDiff
|
||||
.calledWith([{
|
||||
u: @content
|
||||
}], @updates[0])
|
||||
.should.equal true
|
||||
|
||||
it "should apply each update", ->
|
||||
for update in @updates
|
||||
@DiffGenerator.applyUpdateToDiff
|
||||
.calledWith(sinon.match.any, update)
|
||||
.should.equal true
|
||||
|
||||
describe "applyUpdateToDiff", ->
|
||||
describe "an insert", ->
|
||||
it "should insert into the middle of (u)nchanged text", ->
|
||||
|
||||
Reference in New Issue
Block a user