Fix mark addresses and add specs for addresses

Enables properly parsing marks as addresses. Also adds some specs for
addresses by checking how ex-mode behaves when used as a motion.

Fixes #70.
This commit is contained in:
jazzpi 2016-08-16 00:36:05 +02:00
parent 1799706e95
commit 3c952ccbfe
2 changed files with 63 additions and 1 deletions

View file

@ -24,7 +24,7 @@ class Command
mark = @vimState.marks[str[1]] mark = @vimState.marks[str[1]]
unless mark? unless mark?
throw new CommandError("Mark #{str} not set.") throw new CommandError("Mark #{str} not set.")
addr = mark.bufferMarker.range.end.row addr = mark.getEndBufferPosition().row
else if str[0] is "/" else if str[0] is "/"
addr = Find.findNextInBuffer(@editor.buffer, curPos, str[1...-1]) addr = Find.findNextInBuffer(@editor.buffer, curPos, str[1...-1])
unless addr? unless addr?

View file

@ -65,6 +65,68 @@ describe "the commands", ->
openEx = -> openEx = ->
atom.commands.dispatch(editorElement, "ex-mode:open") atom.commands.dispatch(editorElement, "ex-mode:open")
describe "as a motion", ->
beforeEach ->
editor.setCursorBufferPosition([0, 0])
it "moves the cursor to a specific line", ->
openEx()
submitNormalModeInputText '2'
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
it "moves to the second address", ->
openEx()
submitNormalModeInputText '1,3'
expect(editor.getCursorBufferPosition()).toEqual [2, 0]
it "works with offsets", ->
openEx()
submitNormalModeInputText '2+1'
expect(editor.getCursorBufferPosition()).toEqual [2, 0]
openEx()
submitNormalModeInputText '-2'
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
it "doesn't move when the address is the current line", ->
openEx()
submitNormalModeInputText '.'
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
openEx()
submitNormalModeInputText ','
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
it "moves to the last line", ->
openEx()
submitNormalModeInputText '$'
expect(editor.getCursorBufferPosition()).toEqual [3, 0]
it "moves to a mark's line", ->
keydown('l')
keydown('m')
commandModeInputKeydown 'a'
keydown('j')
openEx()
submitNormalModeInputText "'a"
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
it "moves to a specified search", ->
openEx()
submitNormalModeInputText '/def'
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
openEx()
submitNormalModeInputText '?abc'
expect(editor.getCursorBufferPosition()).toEqual [0, 0]
editor.setCursorBufferPosition([3, 0])
openEx()
submitNormalModeInputText '/ef'
expect(editor.getCursorBufferPosition()).toEqual [1, 0]
describe ":write", -> describe ":write", ->
describe "when editing a new file", -> describe "when editing a new file", ->
beforeEach -> beforeEach ->