From 1b2b1a324dab6d4ec0079ca056f5a729f3f53b2d Mon Sep 17 00:00:00 2001 From: Corey Johnson & Nathan Sobo Date: Fri, 13 Apr 2012 11:40:29 -0600 Subject: [PATCH] Add a mock-based test for Editor.prototype.split and ensure it doesn't raise exceptions when not in a pane --- spec/app/editor-spec.coffee | 23 +++++++++++++++++++++++ src/app/editor.coffee | 8 ++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/spec/app/editor-spec.coffee b/spec/app/editor-spec.coffee index a39edcb7f..d35cb05cb 100644 --- a/spec/app/editor-spec.coffee +++ b/spec/app/editor-spec.coffee @@ -2144,3 +2144,26 @@ describe "Editor", -> expect(editor.buffer.path).toBe "0" editor.loadPreviousEditSession() expect(editor.buffer.path).toBe "2" + + describe "split methods", -> + describe "when inside a pane", -> + fakePane = null + beforeEach -> + fakePane = { splitUp: jasmine.createSpy('splitUp') } + spyOn(editor, 'pane').andReturn(fakePane) + + it "calls the corresponding split method on the containing pane with a copy of the editor", -> + editor.splitUp() + expect(fakePane.splitUp).toHaveBeenCalled() + [editorCopy] = fakePane.splitUp.argsForCall[0] + expect(editorCopy.serialize()).toEqual editor.serialize() + expect(editorCopy).not.toBe editor + + describe "when not inside a pane", -> + it "does not split the editor, but doesn't throw an exception", -> + editor.splitUp() + editor.splitDown() + editor.splitLeft() + editor.splitRight() + + diff --git a/src/app/editor.coffee b/src/app/editor.coffee index f0228a3e2..d6935eac8 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -494,16 +494,16 @@ class Editor extends View @setCursorBufferPosition(fold.start) splitLeft: -> - @pane().splitLeft(@copy()) + @pane()?.splitLeft(@copy()) splitRight: -> - @pane().splitRight(@copy()) + @pane()?.splitRight(@copy()) splitUp: -> - @pane().splitUp(@copy()) + @pane()?.splitUp(@copy()) splitDown: -> - @pane().splitDown(@copy()) + @pane()?.splitDown(@copy()) pane: -> @parent('.pane').view()