aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHinidu <hinidu@gmail.com>2014-04-01 23:27:39 +0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-04 16:03:55 -0300
commita3ff83ce7efa54f65a6815aefa178fde6504a6e7 (patch)
tree0df15c6126a1a01fa9bbe46113ad7d787369d0e8 /test
parent86b6f1ccff1ac0face3a0be4ae3e57bf608f8ea9 (diff)
downloadrneovim-a3ff83ce7efa54f65a6815aefa178fde6504a6e7.tar.gz
rneovim-a3ff83ce7efa54f65a6815aefa178fde6504a6e7.tar.bz2
rneovim-a3ff83ce7efa54f65a6815aefa178fde6504a6e7.zip
Replace mch_rename and vim_rename with libuv
Diffstat (limited to 'test')
-rw-r--r--test/unit/os/fs.moon44
1 files changed, 38 insertions, 6 deletions
diff --git a/test/unit/os/fs.moon b/test/unit/os/fs.moon
index 5c04bef2e5..734c8a2c5d 100644
--- a/test/unit/os/fs.moon
+++ b/test/unit/os/fs.moon
@@ -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')
-
- it 'returns TRUE when given an existing file', ->
- eq TRUE, (os_file_exists 'unit-test-directory/test.file')
+ os_rename = (path, new_path) ->
+ fs.os_rename (to_cstr path), (to_cstr new_path)
+
+ 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!