From 120e2a3bdb2fdc40c58bb508f42e79d412fd3069 Mon Sep 17 00:00:00 2001 From: Ben Ogle & Nathan Sobo Date: Thu, 12 Jun 2014 16:51:18 -0600 Subject: [PATCH] Move decoration Editor specs to DisplayBuffer --- spec/display-buffer-spec.coffee | 25 +++++++ spec/editor-spec.coffee | 111 -------------------------------- 2 files changed, 25 insertions(+), 111 deletions(-) diff --git a/spec/display-buffer-spec.coffee b/spec/display-buffer-spec.coffee index 1c15f83e4..965d9af76 100644 --- a/spec/display-buffer-spec.coffee +++ b/spec/display-buffer-spec.coffee @@ -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 diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 4a5b77ce7..04bec25ac 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -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