kana / vim-vspec

Vim plugin: Testing framework for Vim script
http://www.vim.org/scripts/script.php?script_id=3012
222 stars 13 forks source link

The read command does not leave an empty line #30

Closed stefandtw closed 10 years ago

stefandtw commented 10 years ago

Try this test. It wil fail:

describe 'the read command'
    it 'inserts text after the current line'
        Expect getline(1) ==# ''
        " read any file with text in the first line
        read ~/.vimrc
        Expect getline(1) ==# ''
    end
end

Vim normally leaves an empty line if you read a file. For some reason vim-vspec does not seem to do this.

kana commented 10 years ago

Thank you for the report. vim-vspec runs a test script with a Vim process in Ex mode (-e) for automation. And :read behaves differently in Ex mode. This is an intentional behavior. From :help new-posix:

  • In Ex mode with an empty buffer ":read file" doesn't keep an empty line above or below the new lines.

So, if you want to emulate the normal :read in an empty buffer, you have to mark the current buffer is not empty -- for example:

describe 'the read command'
  it 'inserts text after the current line'
    Expect getline(1) ==# ''
    call setline(1, '')
    read ~/.vimrc
    Expect getline(1) ==# ''
  end
end
stefandtw commented 10 years ago

That behaviour is fine. I just couldn't figure out why it worked that way. Thanks for the explanation!