     describe "the _ register", ->
       describe "reading", ->
         it "is always the empty string", ->
-          expect(vimState.getRegister("_").text).toEqual ''
+          register('_').toEqual ''
 
       describe "writing", ->
         it "throws away anything written to it", ->
-          vimState.setRegister('_', text: 'new content')
-          expect(vimState.getRegister("_").text).toEqual ''
+          register('_', text: 'new content')
+          register("_").toEqual ''
 
     describe "the % register", ->
       beforeEach ->


      describe "reading", ->
        it "returns the filename of the current editor", ->
          expect(vimState.getRegister('%').text).toEqual '/Users/atom/known_value.txt'

      describe "writing", ->
        it "throws away anything written to it", ->
          vimState.setRegister('%', "new content")
          expect(vimState.getRegister('%').text).toEqual '/Users/atom/known_value.txt'

    describe "the ctrl-r command in insert mode", ->
      beforeEach ->
        editor.setText "02\n"
        editor.setCursorScreenPosition [0, 0]
        vimState.setRegister('"', text: '345')
        vimState.setRegister('a', text: 'abc')
        atom.clipboard.write "clip"
        keydown 'a'
        editor.insertText '1'

    for key in keys.split('')
      helpers.keydown(key, options)

  text = (text=null)->
    if text
      editor.setText(text)
    else
      expect(editor.getText())

  cursor = (point=null)->
    if point
      editor.setCursorScreenPosition(point)
    else
      expect(editor.getCursorScreenPosition())

  register = (name, value)->
    if value
      vimState.setRegister(name, value)
    else
      expect(vimState.getRegister(name).text)

  describe "Repeat", ->
    describe "with operations", ->
      beforeEach ->
        text "123456789abc"
        cursor [0, 0]

      it "repeats N times", ->
        keystroke '3x'
        text().toBe '456789abc'

      it "repeats NN times", ->
        keystroke '10x'
        text().toBe 'bc'

    describe "with motions", ->
      beforeEach ->
        text 'one two three'
        cursor [0, 0]

      it "repeats N times", ->
        keystroke 'd2w'
        text().toBe 'three'

    describe "in visual mode", ->
      beforeEach ->
        text 'one two three'
        cursor [0, 0]

      it "repeats movements in visual mode", ->
        keystroke 'v2w'
        cursor().toEqual [0, 9]

  describe "Register", ->
    describe "the a register", ->
      it "saves a value for future reading", ->
        register('a', text: 'new content')
        register('a').toEqual 'new content'

      it "overwrites a value previously in the register", ->
        register('a', text: 'content')
        register('a', text: 'new content')
        register('a').toEqual 'new content'

    describe "the B register", ->
      it "saves a value for future reading", ->
        register('B', text: 'new content')
        register('b').toEqual 'new content'
        register('B').toEqual 'new content'

      it "appends to a value previously in the register", ->
        register('b', text: 'content')
        register('B', text: 'new content')
        register("b").toEqual 'contentnew content'

      it "appends linewise to a linewise value previously in the register", ->
        register('b', {type: 'linewise', text: 'content\n'})
        register('B', text: 'new content')
        register('b').toEqual 'content\nnew content\n'

      it "appends linewise to a character value previously in the register", ->
        register('b', text: 'content')
        register('B', {type: 'linewise', text: 'new content\n'})
        register("b").toEqual 'content\nnew content\n'


    describe "the * register", ->
      describe "reading", ->
        it "is the same the system clipboard", ->
          register('*').toEqual 'initial clipboard content'
          expect(vimState.getRegister('*').type).toEqual 'character'

      describe "writing", ->
        beforeEach ->
          register('*', text: 'new content')

        it "overwrites the contents of the system clipboard", ->
          expect(atom.clipboard.read()).toEqual 'new content'
