Move decoration Editor specs to DisplayBuffer

This commit is contained in:
Ben Ogle & Nathan Sobo
2014-06-12 16:51:18 -06:00
committed by Ben Ogle
parent 7142022f05
commit 120e2a3bdb
2 changed files with 25 additions and 111 deletions

View File

@@ -992,6 +992,31 @@ describe "DisplayBuffer", ->
expect(start.top).toBe 5 * 20
expect(start.left).toBe (4 * 10) + (6 * 11)
describe "decorations", ->
it "can add decorations associated with markers and remove them", ->
decoration = {type: 'gutter', class: 'one'}
marker = displayBuffer.markBufferRange([[2, 13], [3, 15]], class: 'my-marker', invalidate: 'inside')
displayBuffer.addDecorationForMarker(marker, decoration)
decoration = displayBuffer.decorationsForScreenRowRange(2, 3)[marker.id][0]
expect(decoration.getScreenRange()).toEqual [[2, 13], [3, 15]]
expect(decoration.isValid()).toBe true
expect(decoration.class).toBe 'one'
buffer.insert([0, 0], '\n')
expect(decoration.getScreenRange()).toEqual [[3, 13], [4, 15]]
expect(decoration.isValid()).toBe true
buffer.insert([4, 2], 'n')
expect(decoration.isValid()).toBe false
buffer.undo()
expect(decoration.getScreenRange()).toEqual [[3, 13], [4, 15]]
expect(decoration.isValid()).toBe true
displayBuffer.removeDecorationForMarker(marker, decoration)
expect(displayBuffer.decorationsForScreenRowRange(2, 3)[marker.id]).not.toBeDefined()
describe "::setScrollTop", ->
beforeEach ->
displayBuffer.manageScrollPosition = true

View File

@@ -3243,114 +3243,3 @@ describe "Editor", ->
editor.pageUp()
expect(editor.getScrollTop()).toBe 0
expect(editor.getCursorBufferPosition().row).toBe 0
describe "decorations", ->
decoration = null
beforeEach ->
decoration = {type: 'gutter', class: 'one'}
it "can add decorations to buffer rows and remove them", ->
editor.addDecorationToBufferRow(2, decoration)
editor.addDecorationToBufferRow(2, decoration)
decorations = editor.decorationsForBufferRow(2)
expect(decorations).toHaveLength 1
expect(decorations).toContain decoration
editor.removeDecorationFromBufferRow(2, decoration)
decorations = editor.decorationsForBufferRow(2)
expect(decorations).toHaveLength 0
it "can add decorations to buffer row ranges and remove them", ->
editor.addDecorationToBufferRowRange(2, 4, decoration)
expect(editor.decorationsForBufferRow 2).toContain decoration
expect(editor.decorationsForBufferRow 3).toContain decoration
expect(editor.decorationsForBufferRow 4).toContain decoration
editor.removeDecorationFromBufferRowRange(3, 5, decoration)
expect(editor.decorationsForBufferRow 2).toContain decoration
expect(editor.decorationsForBufferRow 3).not.toContain decoration
expect(editor.decorationsForBufferRow 4).not.toContain decoration
it "can add decorations associated with markers and remove them", ->
marker = editor.displayBuffer.markBufferRange([[2, 13], [3, 15]], class: 'my-marker', invalidate: 'inside')
editor.addDecorationForMarker(marker, decoration)
expect(editor.decorationsForBufferRow 1).not.toContain decoration
expect(editor.decorationsForBufferRow 2).toContain decoration
expect(editor.decorationsForBufferRow 3).toContain decoration
expect(editor.decorationsForBufferRow 4).not.toContain decoration
editor.getBuffer().insert([0, 0], '\n')
expect(editor.decorationsForBufferRow 2).not.toContain decoration
expect(editor.decorationsForBufferRow 3).toContain decoration
expect(editor.decorationsForBufferRow 4).toContain decoration
expect(editor.decorationsForBufferRow 5).not.toContain decoration
editor.getBuffer().insert([4, 2], 'n')
expect(editor.decorationsForBufferRow 2).not.toContain decoration
expect(editor.decorationsForBufferRow 3).not.toContain decoration
expect(editor.decorationsForBufferRow 4).not.toContain decoration
expect(editor.decorationsForBufferRow 5).not.toContain decoration
editor.getBuffer().undo()
expect(editor.decorationsForBufferRow 2).not.toContain decoration
expect(editor.decorationsForBufferRow 3).toContain decoration
expect(editor.decorationsForBufferRow 4).toContain decoration
expect(editor.decorationsForBufferRow 5).not.toContain decoration
editor.removeDecorationForMarker(marker, decoration)
expect(editor.decorationsForBufferRow 2).not.toContain decoration
expect(editor.decorationsForBufferRow 3).not.toContain decoration
expect(editor.decorationsForBufferRow 4).not.toContain decoration
expect(editor.decorationsForBufferRow 5).not.toContain decoration
describe "decorationsForBufferRow", ->
one = {type: 'one', class: 'one'}
two = {type: 'two', class: 'two'}
typeless = {class: 'typeless'}
beforeEach ->
editor.addDecorationToBufferRow(2, one)
editor.addDecorationToBufferRow(2, two)
editor.addDecorationToBufferRow(2, typeless)
it "returns all decorations with no decorationType specified", ->
decorations = editor.decorationsForBufferRow(2)
expect(decorations).toContain one
expect(decorations).toContain two
expect(decorations).toContain typeless
it "returns typeless decorations with all decorationTypes", ->
decorations = editor.decorationsForBufferRow(2, 'one')
expect(decorations).toContain one
expect(decorations).not.toContain two
expect(decorations).toContain typeless
describe "decorationsForBufferRowRange", ->
one = {type: 'one', class: 'one'}
two = {type: 'two', class: 'two'}
typeless = {class: 'typeless'}
it "returns an object of decorations based on the decorationType", ->
editor.addDecorationToBufferRow(2, one)
editor.addDecorationToBufferRow(3, one)
editor.addDecorationToBufferRow(5, one)
editor.addDecorationToBufferRow(3, two)
editor.addDecorationToBufferRow(4, two)
editor.addDecorationToBufferRow(3, typeless)
editor.addDecorationToBufferRow(5, typeless)
decorations = editor.decorationsForBufferRowRange(2, 5, 'one')
expect(decorations[2]).toContain one
expect(decorations[3]).toContain one
expect(decorations[3]).not.toContain two
expect(decorations[3]).toContain typeless
expect(decorations[4]).toHaveLength 0
expect(decorations[5]).toContain one
expect(decorations[5]).toContain typeless