Project.open returns an editSession instead of a buffer.

First step in removing the coupling of Editor and Buffer. Editor should get all information about the active buffer from the activeEditSession.
This commit is contained in:
Corey Johnson & Nathan Sobo
2012-06-18 15:56:55 -07:00
parent 4bd5a017cf
commit 4659fd7dc3
10 changed files with 78 additions and 93 deletions

View File

@@ -39,19 +39,6 @@ describe 'Buffer', ->
expect(eventHandler).toHaveBeenCalledWith(buffer)
describe ".isModified()", ->
describe "when deserialized", ->
it "returns false", ->
buffer = Buffer.deserialize(buffer.serialize(), new Project)
expect(buffer.isModified()).toBe false
buffer = Buffer.deserialize((new Buffer).serialize(), new Project)
expect(buffer.isModified()).toBe false
it "returns is true if buffer no path and had changes", ->
buffer = new Buffer
buffer.insert([0,0], "oh hi")
expect(buffer.isModified()).toBe true
it "returns true when user changes buffer", ->
expect(buffer.isModified()).toBeFalsy()
buffer.insert([0,0], "hi")
@@ -68,25 +55,6 @@ describe 'Buffer', ->
buffer.save()
expect(buffer.isModified()).toBe false
describe '.deserialize(state, project)', ->
project = null
beforeEach ->
project = new Project(fs.directory(filePath))
describe 'when the state has a path', ->
it 'use the project to open the path', ->
savedBuffer = project.open(filePath)
buffer = Buffer.deserialize(savedBuffer.serialize(), project)
expect(buffer).toBe savedBuffer
describe 'when the state has text (and no path)', ->
it 'creates a new empty buffer (does not serialze unsaved text)', ->
unsavedBuffer = project.open()
unsavedBuffer.setText("OMGWTFBBQ")
buffer = Buffer.deserialize(unsavedBuffer.serialize(), project)
expect(buffer.getText()).toBe ""
describe ".getLines()", ->
it "returns an array of lines in the text contents", ->
expect(buffer.getLines().length).toBe fileContents.split("\n").length

View File

@@ -66,6 +66,7 @@ describe "Editor", ->
expect(editor.serialize).toHaveBeenCalled()
expect(Editor.deserialize).toHaveBeenCalled()
expect(newEditor.buffer).toBe editor.buffer
expect(newEditor.getCursorScreenPosition()).toEqual editor.getCursorScreenPosition()
expect(newEditor.editSessions[0]).toEqual(editor.editSessions[0])

View File

@@ -14,30 +14,30 @@ describe "Project", ->
project.on 'new-buffer', newBufferHandler
describe "when given an absolute path that hasn't been opened previously", ->
it "returns a new buffer for the given path and emits a 'new-buffer' event", ->
buffer = project.open(absolutePath)
expect(buffer.path).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith buffer
it "returns a new edit session for the given path and emits a 'new-buffer' event", ->
editSession = project.open(absolutePath)
expect(editSession.buffer.path).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer
describe "when given a relative path that hasn't been opened previously", ->
it "returns a buffer for the given path (relative to the project root) and emits a 'new-buffer' event", ->
buffer = project.open('a')
expect(buffer.path).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith buffer
it "returns a new edit session for the given path (relative to the project root) and emits a 'new-buffer' event", ->
editSession = project.open('a')
expect(editSession.buffer.path).toBe absolutePath
expect(newBufferHandler).toHaveBeenCalledWith editSession.buffer
describe "when passed the path to a buffer that has already been opened", ->
it "returns the previously opened buffer", ->
buffer = project.open(absolutePath)
it "returns a new edit session containing previously opened buffer", ->
editSession = project.open(absolutePath)
newBufferHandler.reset()
expect(project.open(absolutePath)).toBe buffer
expect(project.open('a')).toBe buffer
expect(project.open(absolutePath).buffer).toBe editSession.buffer
expect(project.open('a').buffer).toBe editSession.buffer
expect(newBufferHandler).not.toHaveBeenCalled()
describe "when not passed a path", ->
it "returns a new buffer and emits a new-buffer event", ->
buffer = project.open()
expect(buffer.path).toBeUndefined()
expect(newBufferHandler).toHaveBeenCalledWith(buffer)
it "returns a new edit session and emits a new-buffer event", ->
editSession = project.open()
expect(editSession.buffer.getPath()).toBeUndefined()
expect(newBufferHandler).toHaveBeenCalledWith(editSession.buffer)
describe ".resolve(path)", ->
it "returns an absolute path based on the project's root", ->