mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Move indent/outdent selection specs to edit-session-spec
This commit is contained in:
@@ -984,6 +984,65 @@ describe "EditSession", ->
|
||||
expect(editSession.buffer.lineForRow(0)).toBe "var first = function () {"
|
||||
expect(buffer.lineForRow(1)).toBe " var first = function(items) {"
|
||||
|
||||
describe ".indentSelectedRows()", ->
|
||||
tabLength = null
|
||||
|
||||
beforeEach ->
|
||||
tabLength = editSession.tabText.length
|
||||
|
||||
describe "when nothing is selected", ->
|
||||
it "indents line and retains selection", ->
|
||||
editSession.setSelectedBufferRange([[0,3], [0,3]])
|
||||
editSession.indentSelectedRows()
|
||||
expect(buffer.lineForRow(0)).toBe "#{editSession.tabText}var quicksort = function () {"
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[0, 3 + tabLength], [0, 3 + tabLength]]
|
||||
|
||||
describe "when one line is selected", ->
|
||||
it "indents line and retains selection", ->
|
||||
editSession.setSelectedBufferRange([[0,4], [0,14]])
|
||||
editSession.indentSelectedRows()
|
||||
expect(buffer.lineForRow(0)).toBe "#{editSession.tabText}var quicksort = function () {"
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[0, 4 + tabLength], [0, 14 + tabLength]]
|
||||
|
||||
describe "when multiple lines are selected", ->
|
||||
it "indents selected lines (that are not empty) and retains selection", ->
|
||||
editSession.setSelectedBufferRange([[9,1], [11,15]])
|
||||
editSession.indentSelectedRows()
|
||||
expect(buffer.lineForRow(9)).toBe " };"
|
||||
expect(buffer.lineForRow(10)).toBe ""
|
||||
expect(buffer.lineForRow(11)).toBe " return sort(Array.apply(this, arguments));"
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[9, 1 + tabLength], [11, 15 + tabLength]]
|
||||
|
||||
describe ".outdentSelectedRows()", ->
|
||||
tabLength = null
|
||||
|
||||
beforeEach ->
|
||||
editSession.tabText = " "
|
||||
tabLength = editSession.tabText.length
|
||||
|
||||
describe "when nothing is selected", ->
|
||||
it "outdents line and retains selection", ->
|
||||
editSession.setSelectedBufferRange([[1,3], [1,3]])
|
||||
editSession.outdentSelectedRows()
|
||||
expect(buffer.lineForRow(1)).toBe "var sort = function(items) {"
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[1, 3 - tabLength], [1, 3 - tabLength]]
|
||||
|
||||
describe "when one line is selected", ->
|
||||
it "outdents line and retains editSession", ->
|
||||
editSession.setSelectedBufferRange([[1,4], [1,14]])
|
||||
editSession.outdentSelectedRows()
|
||||
expect(buffer.lineForRow(1)).toBe "var sort = function(items) {"
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[1, 4 - tabLength], [1, 14 - tabLength]]
|
||||
|
||||
describe "when multiple lines are selected", ->
|
||||
it "outdents selected lines and retains editSession", ->
|
||||
editSession.setSelectedBufferRange([[0,1], [3,15]])
|
||||
editSession.outdentSelectedRows()
|
||||
expect(buffer.lineForRow(0)).toBe "var quicksort = function () {"
|
||||
expect(buffer.lineForRow(1)).toBe "var sort = function(items) {"
|
||||
expect(buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[0, 1], [3, 15 - tabLength]]
|
||||
|
||||
describe ".undo() and .redo()", ->
|
||||
it "undoes/redoes the last change", ->
|
||||
editSession.insertText("foo")
|
||||
|
||||
@@ -171,65 +171,6 @@ describe "Selection", ->
|
||||
selection.selectToScreenPosition([0, 25])
|
||||
expect(selection.isReversed()).toBeFalsy()
|
||||
|
||||
describe ".indentSelectedRows()", ->
|
||||
tabLength = null
|
||||
|
||||
beforeEach ->
|
||||
tabLength = editor.tabText.length
|
||||
|
||||
describe "when nothing is selected", ->
|
||||
it "indents line and retains selection", ->
|
||||
selection.setBufferRange new Range([0,3], [0,3])
|
||||
selection.indentSelectedRows()
|
||||
expect(editor.buffer.lineForRow(0)).toBe "#{editor.tabText}var quicksort = function () {"
|
||||
expect(selection.getBufferRange()).toEqual [[0, 3 + tabLength], [0, 3 + tabLength]]
|
||||
|
||||
describe "when one line is selected", ->
|
||||
it "indents line and retains selection", ->
|
||||
selection.setBufferRange new Range([0,4], [0,14])
|
||||
selection.indentSelectedRows()
|
||||
expect(editor.buffer.lineForRow(0)).toBe "#{editor.tabText}var quicksort = function () {"
|
||||
expect(selection.getBufferRange()).toEqual [[0, 4 + tabLength], [0, 14 + tabLength]]
|
||||
|
||||
describe "when multiple lines are selected", ->
|
||||
it "indents selected lines (that are not empty) and retains selection", ->
|
||||
selection.setBufferRange new Range([9,1], [11,15])
|
||||
selection.indentSelectedRows()
|
||||
expect(editor.buffer.lineForRow(9)).toBe " };"
|
||||
expect(editor.buffer.lineForRow(10)).toBe ""
|
||||
expect(editor.buffer.lineForRow(11)).toBe " return sort(Array.apply(this, arguments));"
|
||||
expect(selection.getBufferRange()).toEqual [[9, 1 + tabLength], [11, 15 + tabLength]]
|
||||
|
||||
describe ".outdentSelectedRows()", ->
|
||||
tabLength = null
|
||||
|
||||
beforeEach ->
|
||||
editor.tabText = " "
|
||||
tabLength = editor.tabText.length
|
||||
|
||||
describe "when nothing is selected", ->
|
||||
it "outdents line and retains selection", ->
|
||||
selection.setBufferRange new Range([1,3], [1,3])
|
||||
selection.outdentSelectedRows()
|
||||
expect(editor.buffer.lineForRow(1)).toBe "var sort = function(items) {"
|
||||
expect(selection.getBufferRange()).toEqual [[1, 3 - tabLength], [1, 3 - tabLength]]
|
||||
|
||||
describe "when one line is selected", ->
|
||||
it "outdents line and retains selection", ->
|
||||
selection.setBufferRange new Range([1,4], [1,14])
|
||||
selection.outdentSelectedRows()
|
||||
expect(editor.buffer.lineForRow(1)).toBe "var sort = function(items) {"
|
||||
expect(selection.getBufferRange()).toEqual [[1, 4 - tabLength], [1, 14 - tabLength]]
|
||||
|
||||
describe "when multiple lines are selected", ->
|
||||
it "outdents selected lines and retains selection", ->
|
||||
selection.setBufferRange new Range([0,1], [3,15])
|
||||
selection.outdentSelectedRows()
|
||||
expect(editor.buffer.lineForRow(0)).toBe "var quicksort = function () {"
|
||||
expect(editor.buffer.lineForRow(1)).toBe "var sort = function(items) {"
|
||||
expect(editor.buffer.lineForRow(2)).toBe " if (items.length <= 1) return items;"
|
||||
expect(selection.getBufferRange()).toEqual [[0, 1], [3, 15 - tabLength]]
|
||||
|
||||
describe ".toggleLineComments()", ->
|
||||
it "toggles comments on the selected lines", ->
|
||||
selection.setBufferRange([[4, 5], [7, 5]])
|
||||
|
||||
Reference in New Issue
Block a user