mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge branch 'master' into ns-telepathic-atom-global
Conflicts: package.json
This commit is contained in:
@@ -2624,6 +2624,7 @@ describe "Editor", ->
|
||||
|
||||
describe ".shouldPromptToSave()", ->
|
||||
it "returns false when an edit session's buffer is in use by more than one session", ->
|
||||
jasmine.unspy(editor, 'shouldPromptToSave')
|
||||
expect(editor.shouldPromptToSave()).toBeFalsy()
|
||||
buffer.setText('changed')
|
||||
expect(editor.shouldPromptToSave()).toBeTruthy()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
PaneContainer = require '../src/pane-container'
|
||||
Pane = require '../src/pane'
|
||||
{$, View} = require 'atom'
|
||||
{fs, $, View} = require 'atom'
|
||||
path = require 'path'
|
||||
temp = require 'temp'
|
||||
|
||||
@@ -147,6 +147,7 @@ describe "Pane", ->
|
||||
|
||||
describe "if the item is modified", ->
|
||||
beforeEach ->
|
||||
jasmine.unspy(editor2, 'shouldPromptToSave')
|
||||
spyOn(editor2, 'save')
|
||||
spyOn(editor2, 'saveAs')
|
||||
|
||||
@@ -347,14 +348,14 @@ describe "Pane", ->
|
||||
|
||||
describe "when the current item has a saveAs method", ->
|
||||
it "opens a save dialog and saves the current item as the selected path", ->
|
||||
spyOn(editor2, 'saveAs')
|
||||
editor2.buffer.setPath(undefined)
|
||||
pane.showItem(editor2)
|
||||
newEditor = atom.project.openSync()
|
||||
spyOn(newEditor, 'saveAs')
|
||||
pane.showItem(newEditor)
|
||||
|
||||
pane.trigger 'core:save'
|
||||
|
||||
expect(atom.showSaveDialogSync).toHaveBeenCalled()
|
||||
expect(editor2.saveAs).toHaveBeenCalledWith('/selected/path')
|
||||
expect(newEditor.saveAs).toHaveBeenCalledWith('/selected/path')
|
||||
|
||||
describe "when the current item has no saveAs method", ->
|
||||
it "does nothing", ->
|
||||
@@ -421,6 +422,17 @@ describe "Pane", ->
|
||||
view2.trigger 'title-changed'
|
||||
expect(activeItemTitleChangedHandler).toHaveBeenCalled()
|
||||
|
||||
describe "when an unmodifed buffer's path is deleted", ->
|
||||
it "removes the pane item", ->
|
||||
filePath = temp.openSync('atom').path
|
||||
editor = atom.project.openSync(filePath)
|
||||
pane.showItem(editor)
|
||||
expect(pane.items).toHaveLength(5)
|
||||
|
||||
fs.removeSync(filePath)
|
||||
waitsFor ->
|
||||
pane.items.length == 4
|
||||
|
||||
describe ".remove()", ->
|
||||
it "destroys all the pane's items", ->
|
||||
pane.remove()
|
||||
|
||||
@@ -9,6 +9,7 @@ Keymap = require '../src/keymap'
|
||||
Config = require '../src/config'
|
||||
{Point} = require 'telepath'
|
||||
Project = require '../src/project'
|
||||
Editor = require '../src/editor'
|
||||
EditorView = require '../src/editor-view'
|
||||
TokenizedBuffer = require '../src/tokenized-buffer'
|
||||
pathwatcher = require 'pathwatcher'
|
||||
@@ -91,6 +92,7 @@ beforeEach ->
|
||||
spyOn(window, "setTimeout").andCallFake window.fakeSetTimeout
|
||||
spyOn(window, "clearTimeout").andCallFake window.fakeClearTimeout
|
||||
spyOn(File.prototype, "detectResurrectionAfterDelay").andCallFake -> @detectResurrection()
|
||||
spyOn(Editor.prototype, "shouldPromptToSave").andReturn false
|
||||
|
||||
# make tokenization synchronous
|
||||
TokenizedBuffer.prototype.chunkSize = Infinity
|
||||
|
||||
@@ -34,11 +34,11 @@ describe 'TextBuffer', ->
|
||||
expect(buffer.getText()).toBe fs.readFileSync(filePath, 'utf8')
|
||||
|
||||
describe "when no file exists for the path", ->
|
||||
it "is modified and is initially empty", ->
|
||||
it "is not modified and is initially empty", ->
|
||||
filePath = "does-not-exist.txt"
|
||||
expect(fs.existsSync(filePath)).toBeFalsy()
|
||||
buffer = atom.project.bufferForPathSync(filePath)
|
||||
expect(buffer.isModified()).toBeTruthy()
|
||||
expect(buffer.isModified()).not.toBeTruthy()
|
||||
expect(buffer.getText()).toBe ''
|
||||
|
||||
describe "when no path is given", ->
|
||||
@@ -113,10 +113,17 @@ describe 'TextBuffer', ->
|
||||
|
||||
runs ->
|
||||
[event] = changeHandler.argsForCall[0]
|
||||
expect(event.oldRange).toEqual [[0, 0], [0, 5]]
|
||||
expect(event.oldRange).toEqual [[0, 0], [0, 0]]
|
||||
expect(event.newRange).toEqual [[0, 0], [0, 6]]
|
||||
expect(event.oldText).toBe "first"
|
||||
expect(event.oldText).toBe ""
|
||||
expect(event.newText).toBe "second"
|
||||
|
||||
[event] = changeHandler.argsForCall[1]
|
||||
expect(event.oldRange).toEqual [[0, 6], [0, 11]]
|
||||
expect(event.newRange).toEqual [[0, 6], [0, 6]]
|
||||
expect(event.oldText).toBe "first"
|
||||
expect(event.newText).toBe ""
|
||||
|
||||
expect(buffer.isModified()).toBeFalsy()
|
||||
|
||||
describe "when the buffer's memory contents differ from the *previous* disk contents", ->
|
||||
@@ -160,20 +167,38 @@ describe 'TextBuffer', ->
|
||||
filePath = bufferToDelete.getPath() # symlinks may have been converted
|
||||
|
||||
expect(bufferToDelete.getPath()).toBe filePath
|
||||
expect(bufferToDelete.isModified()).toBeFalsy()
|
||||
|
||||
removeHandler = jasmine.createSpy('removeHandler')
|
||||
bufferToDelete.file.on 'removed', removeHandler
|
||||
fs.removeSync(filePath)
|
||||
waitsFor "file to be removed", ->
|
||||
removeHandler.callCount > 0
|
||||
|
||||
afterEach ->
|
||||
bufferToDelete.destroy()
|
||||
|
||||
it "retains its path and reports the buffer as modified", ->
|
||||
expect(bufferToDelete.getPath()).toBe filePath
|
||||
expect(bufferToDelete.isModified()).toBeTruthy()
|
||||
describe "when the file is modified", ->
|
||||
beforeEach ->
|
||||
bufferToDelete.setText("I WAS MODIFIED")
|
||||
expect(bufferToDelete.isModified()).toBeTruthy()
|
||||
|
||||
removeHandler = jasmine.createSpy('removeHandler')
|
||||
bufferToDelete.file.on 'removed', removeHandler
|
||||
fs.removeSync(filePath)
|
||||
waitsFor "file to be removed", ->
|
||||
removeHandler.callCount > 0
|
||||
|
||||
it "retains its path and reports the buffer as modified", ->
|
||||
expect(bufferToDelete.getPath()).toBe filePath
|
||||
expect(bufferToDelete.isModified()).toBeTruthy()
|
||||
|
||||
describe "when the file is not modified", ->
|
||||
beforeEach ->
|
||||
expect(bufferToDelete.isModified()).toBeFalsy()
|
||||
|
||||
removeHandler = jasmine.createSpy('removeHandler')
|
||||
bufferToDelete.file.on 'removed', removeHandler
|
||||
fs.removeSync(filePath)
|
||||
waitsFor "file to be removed", ->
|
||||
removeHandler.callCount > 0
|
||||
|
||||
it "retains its path and reports the buffer as not modified", ->
|
||||
expect(bufferToDelete.getPath()).toBe filePath
|
||||
expect(bufferToDelete.isModified()).toBeFalsy()
|
||||
|
||||
it "resumes watching of the file when it is re-saved", ->
|
||||
bufferToDelete.save()
|
||||
@@ -210,19 +235,6 @@ describe 'TextBuffer', ->
|
||||
advanceClock(buffer.stoppedChangingDelay)
|
||||
expect(modifiedHandler).toHaveBeenCalledWith(false)
|
||||
|
||||
it "reports the modified status changing to true after the underlying file is deleted", ->
|
||||
buffer.release()
|
||||
filePath = path.join(temp.dir, 'atom-tmp-file')
|
||||
fs.writeFileSync(filePath, 'delete me')
|
||||
buffer = atom.project.bufferForPathSync(filePath)
|
||||
modifiedHandler = jasmine.createSpy("modifiedHandler")
|
||||
buffer.on 'modified-status-changed', modifiedHandler
|
||||
|
||||
fs.removeSync(filePath)
|
||||
|
||||
waitsFor "modified status to change", -> modifiedHandler.callCount
|
||||
runs -> expect(buffer.isModified()).toBe true
|
||||
|
||||
it "reports the modified status changing to false after a modified buffer is saved", ->
|
||||
filePath = path.join(temp.dir, 'atom-tmp-file')
|
||||
fs.writeFileSync(filePath, '')
|
||||
@@ -454,6 +466,68 @@ describe 'TextBuffer', ->
|
||||
expect(event.oldRange).toEqual expectedPreRange
|
||||
expect(event.newRange).toEqual [[0, 0], [1, 14]]
|
||||
|
||||
describe ".setTextViaDiff(text)", ->
|
||||
it "can change the entire contents of the buffer when there are no newlines", ->
|
||||
buffer.setText('BUFFER CHANGE')
|
||||
newText = 'DISK CHANGE'
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
describe "with standard newlines", ->
|
||||
it "can change the entire contents of the buffer with no newline at the end", ->
|
||||
newText = "I know you are.\nBut what am I?"
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
it "can change the entire contents of the buffer with a newline at the end", ->
|
||||
newText = "I know you are.\nBut what am I?\n"
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
it "can change a few lines at the beginning in the buffer", ->
|
||||
newText = buffer.getText().replace(/function/g, 'omgwow')
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
it "can change a few lines in the middle of the buffer", ->
|
||||
newText = buffer.getText().replace(/shift/g, 'omgwow')
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
it "can adds a newline at the end", ->
|
||||
newText = buffer.getText() + '\n'
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
describe "with windows newlines", ->
|
||||
beforeEach ->
|
||||
buffer.setText(buffer.getText().replace(/\n/g, '\r\n'))
|
||||
|
||||
it "adds a newline at the end", ->
|
||||
newText = buffer.getText() + '\r\n'
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
it "changes the entire contents of the buffer with smaller content with no newline at the end", ->
|
||||
newText = "I know you are.\r\nBut what am I?"
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
it "changes the entire contents of the buffer with smaller content with newline at the end", ->
|
||||
newText = "I know you are.\r\nBut what am I?\r\n"
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
it "changes a few lines at the beginning in the buffer", ->
|
||||
newText = buffer.getText().replace(/function/g, 'omgwow')
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
it "changes a few lines in the middle of the buffer", ->
|
||||
newText = buffer.getText().replace(/shift/g, 'omgwow')
|
||||
buffer.setTextViaDiff(newText)
|
||||
expect(buffer.getText()).toBe newText
|
||||
|
||||
describe ".save()", ->
|
||||
saveBuffer = null
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{$, $$, fs} = require 'atom'
|
||||
path = require 'path'
|
||||
Editor = require '../src/editor'
|
||||
WindowEventHandler = require '../src/window-event-handler'
|
||||
|
||||
describe "Window", ->
|
||||
@@ -54,6 +55,7 @@ describe "Window", ->
|
||||
[beforeUnloadEvent] = []
|
||||
|
||||
beforeEach ->
|
||||
jasmine.unspy(Editor.prototype, "shouldPromptToSave")
|
||||
beforeUnloadEvent = $.Event(new Event('beforeunload'))
|
||||
|
||||
describe "when pane items are are modified", ->
|
||||
|
||||
Reference in New Issue
Block a user