mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Move structural folding specs to edit-session-spec
Structural folding should really be handled at the edit session level so that the DisplayBuffer doesn't need access to the LanguageMode. It should only be concerned with the raw ability to create folds.
This commit is contained in:
@@ -142,89 +142,6 @@ describe "DisplayBuffer", ->
|
||||
|
||||
expect(changeHandler).toHaveBeenCalledWith(start: 0, end: 15, screenDelta: 3, bufferDelta: 0)
|
||||
|
||||
describe "structural folding", ->
|
||||
describe ".unfoldAll()", ->
|
||||
it "unfolds every folded line", ->
|
||||
displayBuffer.foldBufferRow(0)
|
||||
displayBuffer.foldBufferRow(1)
|
||||
|
||||
displayBuffer.unfoldAll()
|
||||
expect(Object.keys(displayBuffer.activeFolds).length).toBe 0
|
||||
|
||||
describe ".foldAll()", ->
|
||||
it "folds every foldable line", ->
|
||||
displayBuffer.foldAll()
|
||||
fold = displayBuffer.lineForRow(0).fold
|
||||
expect(fold).toBeDefined()
|
||||
expect([fold.startRow, fold.endRow]).toEqual [0,12]
|
||||
|
||||
expect(Object.keys(displayBuffer.activeFolds).length).toBe(3)
|
||||
expect(displayBuffer.activeFolds[1].length).toBe(1)
|
||||
expect(displayBuffer.activeFolds[4].length).toBe(1)
|
||||
|
||||
it "doesn't fold lines that are already folded", ->
|
||||
displayBuffer.foldBufferRow(4)
|
||||
displayBuffer.foldAll()
|
||||
expect(Object.keys(displayBuffer.activeFolds).length).toBe(3)
|
||||
expect(displayBuffer.activeFolds[0].length).toBe(1)
|
||||
expect(displayBuffer.activeFolds[1].length).toBe(1)
|
||||
expect(displayBuffer.activeFolds[4].length).toBe(1)
|
||||
|
||||
describe ".foldBufferRow(bufferRow)", ->
|
||||
describe "when bufferRow can be folded", ->
|
||||
it "creates a fold based on the syntactic region starting at the given row", ->
|
||||
displayBuffer.foldBufferRow(1)
|
||||
fold = displayBuffer.lineForRow(1).fold
|
||||
expect(fold.startRow).toBe 1
|
||||
expect(fold.endRow).toBe 9
|
||||
|
||||
describe "when bufferRow can't be folded", ->
|
||||
it "searches upward for the first row that begins a syntatic region containing the given buffer row (and folds it)", ->
|
||||
displayBuffer.foldBufferRow(8)
|
||||
fold = displayBuffer.lineForRow(1).fold
|
||||
expect(fold.startRow).toBe 1
|
||||
expect(fold.endRow).toBe 9
|
||||
|
||||
describe "when the bufferRow is already folded", ->
|
||||
it "searches upward for the first row that begins a syntatic region containing the folded row (and folds it)", ->
|
||||
displayBuffer.foldBufferRow(2)
|
||||
expect(displayBuffer.lineForRow(1).fold).toBeDefined()
|
||||
expect(displayBuffer.lineForRow(0).fold).not.toBeDefined()
|
||||
|
||||
displayBuffer.foldBufferRow(1)
|
||||
expect(displayBuffer.lineForRow(0).fold).toBeDefined()
|
||||
|
||||
describe "when the bufferRow is in a multi-line comment", ->
|
||||
it "searches upward and downward for surrounding comment lines and folds them as a single fold", ->
|
||||
buffer.insert([1,0], " //this is a comment\n // and\n //more docs\n\n//second comment")
|
||||
displayBuffer.foldBufferRow(1)
|
||||
fold = displayBuffer.lineForRow(1).fold
|
||||
expect(fold.startRow).toBe 1
|
||||
expect(fold.endRow).toBe 3
|
||||
|
||||
describe "when the bufferRow is a single-line comment", ->
|
||||
it "searches upward for the first row that begins a syntatic region containing the folded row (and folds it)", ->
|
||||
buffer.insert([1,0], " //this is a single line comment\n")
|
||||
displayBuffer.foldBufferRow(1)
|
||||
fold = displayBuffer.lineForRow(0).fold
|
||||
expect(fold.startRow).toBe 0
|
||||
expect(fold.endRow).toBe 13
|
||||
|
||||
describe ".unfoldBufferRow(bufferRow)", ->
|
||||
describe "when bufferRow can be unfolded", ->
|
||||
it "destroys a fold based on the syntactic region starting at the given row", ->
|
||||
displayBuffer.foldBufferRow(1)
|
||||
expect(displayBuffer.lineForRow(1).fold).toBeDefined()
|
||||
|
||||
displayBuffer.unfoldBufferRow(1)
|
||||
expect(displayBuffer.lineForRow(1).fold).toBeUndefined()
|
||||
|
||||
describe "when bufferRow can't be unfolded", ->
|
||||
it "does not throw an error", ->
|
||||
expect(displayBuffer.lineForRow(1).fold).toBeUndefined()
|
||||
displayBuffer.unfoldBufferRow(1)
|
||||
expect(displayBuffer.lineForRow(1).fold).toBeUndefined()
|
||||
|
||||
describe "primitive folding", ->
|
||||
editSession2 = null
|
||||
|
||||
|
||||
@@ -2111,11 +2111,89 @@ describe "EditSession", ->
|
||||
expect(cursor3.getBufferPosition()).toEqual [1,2]
|
||||
|
||||
describe "folding", ->
|
||||
describe "structural folding", ->
|
||||
it "maintains cursor buffer position when a fold is created/destroyed", ->
|
||||
editSession.setCursorBufferPosition([5,5])
|
||||
describe ".unfoldAll()", ->
|
||||
it "unfolds every folded line", ->
|
||||
initialScreenLineCount = editSession.getScreenLineCount()
|
||||
editSession.foldBufferRow(0)
|
||||
editSession.foldBufferRow(1)
|
||||
expect(editSession.getScreenLineCount()).toBeLessThan initialScreenLineCount
|
||||
editSession.unfoldAll()
|
||||
expect(editSession.getScreenLineCount()).toBe initialScreenLineCount
|
||||
|
||||
describe ".foldAll()", ->
|
||||
it "folds every foldable line", ->
|
||||
editSession.foldAll()
|
||||
expect(editSession.getCursorBufferPosition()).toEqual([5,5])
|
||||
|
||||
fold1 = editSession.lineForScreenRow(0).fold
|
||||
expect([fold1.startRow, fold1.endRow]).toEqual [0, 12]
|
||||
fold1.destroy()
|
||||
|
||||
fold2 = editSession.lineForScreenRow(1).fold
|
||||
expect([fold2.startRow, fold2.endRow]).toEqual [1, 9]
|
||||
fold2.destroy()
|
||||
|
||||
fold3 = editSession.lineForScreenRow(4).fold
|
||||
expect([fold3.startRow, fold3.endRow]).toEqual [4, 7]
|
||||
|
||||
describe ".foldBufferRow(bufferRow)", ->
|
||||
describe "when bufferRow can be folded", ->
|
||||
it "creates a fold based on the syntactic region starting at the given row", ->
|
||||
editSession.foldBufferRow(1)
|
||||
fold = editSession.lineForScreenRow(1).fold
|
||||
expect(fold.startRow).toBe 1
|
||||
expect(fold.endRow).toBe 9
|
||||
|
||||
describe "when bufferRow can't be folded", ->
|
||||
it "searches upward for the first row that begins a syntatic region containing the given buffer row (and folds it)", ->
|
||||
editSession.foldBufferRow(8)
|
||||
fold = editSession.lineForScreenRow(1).fold
|
||||
expect(fold.startRow).toBe 1
|
||||
expect(fold.endRow).toBe 9
|
||||
|
||||
describe "when the bufferRow is already folded", ->
|
||||
it "searches upward for the first row that begins a syntatic region containing the folded row (and folds it)", ->
|
||||
editSession.foldBufferRow(2)
|
||||
expect(editSession.lineForScreenRow(1).fold).toBeDefined()
|
||||
expect(editSession.lineForScreenRow(0).fold).not.toBeDefined()
|
||||
|
||||
editSession.foldBufferRow(1)
|
||||
expect(editSession.lineForScreenRow(0).fold).toBeDefined()
|
||||
|
||||
describe "when the bufferRow is in a multi-line comment", ->
|
||||
it "searches upward and downward for surrounding comment lines and folds them as a single fold", ->
|
||||
buffer.insert([1,0], " //this is a comment\n // and\n //more docs\n\n//second comment")
|
||||
editSession.foldBufferRow(1)
|
||||
fold = editSession.lineForScreenRow(1).fold
|
||||
expect(fold.startRow).toBe 1
|
||||
expect(fold.endRow).toBe 3
|
||||
|
||||
describe "when the bufferRow is a single-line comment", ->
|
||||
it "searches upward for the first row that begins a syntatic region containing the folded row (and folds it)", ->
|
||||
buffer.insert([1,0], " //this is a single line comment\n")
|
||||
editSession.foldBufferRow(1)
|
||||
fold = editSession.lineForScreenRow(0).fold
|
||||
expect(fold.startRow).toBe 0
|
||||
expect(fold.endRow).toBe 13
|
||||
|
||||
describe ".unfoldBufferRow(bufferRow)", ->
|
||||
describe "when bufferRow can be unfolded", ->
|
||||
it "destroys a fold based on the syntactic region starting at the given row", ->
|
||||
editSession.foldBufferRow(1)
|
||||
expect(editSession.lineForScreenRow(1).fold).toBeDefined()
|
||||
|
||||
editSession.unfoldBufferRow(1)
|
||||
expect(editSession.lineForScreenRow(1).fold).toBeUndefined()
|
||||
|
||||
describe "when bufferRow can't be unfolded", ->
|
||||
it "does not throw an error", ->
|
||||
expect(editSession.lineForScreenRow(1).fold).toBeUndefined()
|
||||
editSession.unfoldBufferRow(1)
|
||||
expect(editSession.lineForScreenRow(1).fold).toBeUndefined()
|
||||
|
||||
it "maintains cursor buffer position when a folding/unfolding", ->
|
||||
editSession.setCursorBufferPosition([5,5])
|
||||
editSession.foldAll()
|
||||
expect(editSession.getCursorBufferPosition()).toEqual([5,5])
|
||||
|
||||
describe ".deleteLine()", ->
|
||||
it "deletes the first line when the cursor is there", ->
|
||||
|
||||
Reference in New Issue
Block a user