Replace mch_rename and vim_rename with libuv

This commit is contained in:
Hinidu
2014-04-01 23:27:39 +03:00
committed by Thiago de Arruda
parent 86b6f1ccff
commit a3ff83ce7e
8 changed files with 88 additions and 197 deletions

View File

@@ -21,6 +21,7 @@ int os_setperm(char_u *name, long perm);
int os_file_exists(const char_u *name);
int os_file_is_readonly(char *fname);
int os_file_is_writable(const char *name);
int os_rename(const char_u *path, const char_u *new_path);
]]
-- import constants parsed by ffi
@@ -361,12 +362,43 @@ describe 'fs function', ->
it 'returns 2 when given a folder with rights to write into', ->
eq 2, os_file_is_writable 'unit-test-directory'
describe 'os_file_exists', ->
describe 'file operations', ->
os_file_exists = (filename) ->
fs.os_file_exists (to_cstr filename)
it 'returns FALSE when given a non-existing file', ->
eq FALSE, (os_file_exists 'non-existing-file')
os_rename = (path, new_path) ->
fs.os_rename (to_cstr path), (to_cstr new_path)
it 'returns TRUE when given an existing file', ->
eq TRUE, (os_file_exists 'unit-test-directory/test.file')
describe 'os_file_exists', ->
it 'returns FALSE when given a non-existing file', ->
eq FALSE, (os_file_exists 'non-existing-file')
it 'returns TRUE when given an existing file', ->
eq TRUE, (os_file_exists 'unit-test-directory/test.file')
describe 'os_rename', ->
test = 'unit-test-directory/test.file'
not_exist = 'unit-test-directory/not_exist.file'
it 'can rename file if destination file does not exist', ->
eq OK, (os_rename test, not_exist)
eq FALSE, (os_file_exists test)
eq TRUE, (os_file_exists not_exist)
eq OK, (os_rename not_exist, test) -- restore test file
it 'fail if source file does not exist', ->
eq FAIL, (os_rename not_exist, test)
it 'can overwrite destination file if it exists', ->
other = 'unit-test-directory/other.file'
file = io.open other, 'w'
file\write 'other'
file\flush!
file\close!
eq OK, (os_rename other, test)
eq FALSE, (os_file_exists other)
eq TRUE, (os_file_exists test)
file = io.open test, 'r'
eq 'other', (file\read '*all')
file\close!