-{WorkspaceView} = require 'atom'
 shell = require 'shell'
 
 describe "link package", ->


          spyOn(shell, 'openExternal')
          editor.setCursorBufferPosition([0,0])
          editorView.trigger('link:open')
          expect(shell.openExternal).not.toHaveBeenCalled()

          editor.setCursorBufferPosition([0,20])
          editorView.trigger('link:open')

          expect(shell.openExternal).toHaveBeenCalled()
          expect(shell.openExternal.argsForCall[0][0]).toBe 'http://github.com'

          shell.openExternal.reset()
          editor.setCursorBufferPosition([1,24])
          editorView.trigger('link:open')

          expect(shell.openExternal).not.toHaveBeenCalled()


        atom.workspace.open('sample.js')

      runs ->
        editor = atom.workspace.getActiveTextEditor()
        editor.setText("// \"http://github.com\"")

        spyOn(shell, 'openExternal')
        atom.commands.dispatch(atom.views.getView(editor), 'link:open')
        expect(shell.openExternal).not.toHaveBeenCalled()

        editor.setCursorBufferPosition([0,4])
        atom.commands.dispatch(atom.views.getView(editor), 'link:open')

        expect(shell.openExternal).toHaveBeenCalled()
        expect(shell.openExternal.argsForCall[0][0]).toBe 'http://github.com'

        shell.openExternal.reset()
        editor.setCursorBufferPosition([0,8])
        atom.commands.dispatch(atom.views.getView(editor), 'link:open')

        expect(shell.openExternal).toHaveBeenCalled()
        expect(shell.openExternal.argsForCall[0][0]).toBe 'http://github.com'

        shell.openExternal.reset()
        editor.setCursorBufferPosition([0,21])
        atom.commands.dispatch(atom.views.getView(editor), 'link:open')

        expect(shell.openExternal).toHaveBeenCalled()
        expect(shell.openExternal.argsForCall[0][0]).toBe 'http://github.com'
