spacevim/bundle/vimproc.vim/test/fopen.vim
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

178 lines
3.7 KiB
VimL

let s:suite = themis#suite('fopen')
let s:assert = themis#helper('assert')
call themis#helper('command').with(s:)
let s:filename = 'test.txt'
let s:contents = ['foo', 'bar']
function! s:suite.before_each() abort
call writefile(s:contents, s:filename, 'b')
endfunction
function! s:suite.after_each() abort
if filereadable(s:filename)
call delete(s:filename)
endif
endfunction
function! s:suite.read() abort
let file = vimproc#fopen(s:filename)
let res = file.read()
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
endfunction
function! s:suite.read_lines() abort
let file = vimproc#fopen(s:filename, 'r')
let res = file.read_lines()
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename, 'b'), res)
endfunction
function! s:suite.read_line() abort
let file = vimproc#fopen(s:filename, 'r', 0)
let res = []
while !file.eof
let res += [file.read_line()]
endwhile
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(readfile(s:filename), res)
endfunction
function! s:suite.write() abort
let file = vimproc#fopen(s:filename, 'w')
let res = "hello\nvimproc\n.vim"
call s:assert.true(file.is_valid)
call file.write(res)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
endfunction
function! s:suite.append() abort
let file = vimproc#fopen(s:filename, 'a')
let res = "\nhello\nvimproc\n.vim"
call s:assert.true(file.is_valid)
call file.write(res)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ s:contents + split(res, '\r\n\|\r\|\n'))
endfunction
function! s:suite.read_write() abort
let file = vimproc#fopen(s:filename, 'r+')
let res = file.read()
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
call s:assert.true(file.is_valid)
let res = "\nhello\nvimproc\n.vim"
call file.write(res)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ s:contents + split(res, '\r\n\|\r\|\n'))
endfunction
function! s:suite.with_oflag() abort
let file = vimproc#fopen(s:filename, 'O_RDONLY')
let res = file.read()
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
let file = vimproc#fopen(s:filename, 'O_WRONLY|O_TRUNC')
let res = "hello\nvimproc\n.vim"
call file.write(res)
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res, '\r\n\|\r\|\n'))
let file = vimproc#fopen(s:filename, 'O_RDWR|O_APPEND')
let res2 = "\nworld\n!"
call file.write(res2)
call s:assert.true(file.is_valid)
call file.close()
call s:assert.false(file.is_valid)
call s:assert.equals(
\ readfile(s:filename),
\ split(res . res2, '\r\n\|\r\|\n'))
endfunction
function! s:suite.invalid_fmode() abort
let file = vimproc#fopen(s:filename, 'r')
Throws /write() error/ file.write('foo')
call file.close()
call s:assert.equals(readfile(s:filename), s:contents)
let file = vimproc#fopen(s:filename, 'w')
Throws /read() error/ file.read()
call file.close()
call s:assert.true(empty(readfile(s:filename)))
endfunction
" vim:foldmethod=marker:fen: