diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/legacy/test2-filename-recognition.vroom | 40 | ||||
| -rw-r--r-- | test/unit/os/fs_spec.moon | 43 | ||||
| -rw-r--r-- | test/unit/path_spec.moon | 59 |
3 files changed, 142 insertions, 0 deletions
diff --git a/test/legacy/test2-filename-recognition.vroom b/test/legacy/test2-filename-recognition.vroom new file mode 100644 index 0000000000..b8169ec207 --- /dev/null +++ b/test/legacy/test2-filename-recognition.vroom @@ -0,0 +1,40 @@ +Test if URLs are recognized as filenames by commands such as "gf". Here +we'll use `expand("<cfile>")` since "gf" would need to open the file. + +Insert some URLs: + + % first test for URL://machine.name/tmp/vimtest2a and other text<cr> + % second test for URL://machine.name/tmp/vimtest2b. And other text<cr> + % third test for URL:\\machine.name\vimtest2c and other text<cr> + % fourth test for URL:\\machine.name\tmp\vimtest2d, and other text + +Go to the first URL: + + :/^first<cr>/tmp + +Append the url to the beginning of the buffer: + + :call append(0, expand("<cfile>")) + +Repeat for the second URL, but navigate to the 'URL' word: + + :/^second<cr>/URL<cr>:call append(1, expand("<cfile>")) + +Repeat for the other two, but first the 'isfname' option must be set to +allow '\' in filenames + + :set isf=@,48-57,/,.,-,_,+,,,$,:,~,\ + :/^third<cr>/name<cr>:call append(2, expand("<cfile>")) + :/^fourth<cr>/URL<cr>:call append(3, expand("<cfile>")) + +Delete the initial text which starts at line 5: + + > 5GdG + +Result: + + URL://machine.name/tmp/vimtest2a + URL://machine.name/tmp/vimtest2b + URL:\\machine.name\vimtest2c + URL:\\machine.name\tmp\vimtest2d + @end diff --git a/test/unit/os/fs_spec.moon b/test/unit/os/fs_spec.moon index 52f587d6f9..dd787e76cd 100644 --- a/test/unit/os/fs_spec.moon +++ b/test/unit/os/fs_spec.moon @@ -112,6 +112,12 @@ describe 'fs function', -> os_setperm = (filename, perm) -> fs.os_setperm (to_cstr filename), perm + os_fchown = (filename, user_id, group_id) -> + fd = ffi.C.open filename, 0 + res = fs.os_fchown fd, user_id, group_id + ffi.C.close fd + return res + os_file_is_readonly = (filename) -> fs.os_file_is_readonly (to_cstr filename) @@ -158,6 +164,43 @@ describe 'fs function', -> perm = ffi.C.kS_IXUSR eq FAIL, (os_setperm 'non-existing-file', perm) + describe 'os_fchown', -> + filename = 'unit-test-directory/test.file' + + it 'does not change owner and group if respective IDs are equal to -1', -> + uid = lfs.attributes filename, 'uid' + gid = lfs.attributes filename, 'gid' + eq 0, os_fchown filename, -1, -1 + eq uid, lfs.attributes filename, 'uid' + eq gid, lfs.attributes filename, 'gid' + + it 'owner of a file may change the group of the file + to any group of which that owner is a member', -> + -- Some systems may not have `id` utility. + if (os.execute('id -G &> /dev/null') == 0) + file_gid = lfs.attributes filename, 'gid' + + -- Gets ID of any group of which current user is a member except the + -- group that owns the file. + id_fd = io.popen('id -G') + new_gid = id_fd\read '*n' + if (new_gid == file_gid) + new_gid = id_fd\read '*n' + id_fd\close! + + -- User can be a member of only one group. + -- In that case we can not perform this test. + if new_gid + eq 0, (os_fchown filename, -1, new_gid) + eq new_gid, (lfs.attributes filename, 'gid') + + it 'returns nonzero if process has not enough permissions', -> + -- On Windows `os_fchown` always returns 0 + -- because `uv_fs_chown` is no-op on this platform. + if (ffi.os != 'Windows' and ffi.C.geteuid! != 0) + -- chown to root + neq 0, os_fchown filename, 0, 0 + describe 'os_file_is_readonly', -> it 'returns true if the file is readonly', -> perm = os_getperm 'unit-test-directory/test.file' diff --git a/test/unit/path_spec.moon b/test/unit/path_spec.moon index 0786fe6c01..f7e5ed00bc 100644 --- a/test/unit/path_spec.moon +++ b/test/unit/path_spec.moon @@ -114,6 +114,65 @@ describe 'path function', -> it 'returns the whole file name if there is no separator', -> eq 'file.txt', path_tail_with_sep 'file.txt' + describe 'invocation_path_tail', -> + -- Returns the path tail and length (out param) of the tail. + -- Does not convert the tail from C-pointer to lua string for use with + -- strcmp. + invocation_path_tail = (invk) -> + plen = ffi.new 'size_t[?]', 1 + ptail = path.invocation_path_tail (to_cstr invk), plen + neq NULL, ptail + + -- it does not change the output if len==NULL + tail2 = path.invocation_path_tail (to_cstr invk), NULL + neq NULL, tail2 + eq (ffi.string ptail), (ffi.string tail2) + + ptail, plen[0] + + -- This test mimics the intended use in C. + compare = (base, pinvk, len) -> + eq 0, (ffi.C.strncmp (to_cstr base), pinvk, len) + + it 'returns the executable name of an invocation given a relative invocation', -> + invk, len = invocation_path_tail 'directory/exe a b c' + compare "exe a b c", invk, len + eq 3, len + + it 'returns the executable name of an invocation given an absolute invocation', -> + if ffi.os == 'Windows' + invk, len = invocation_path_tail 'C:\\Users\\anyone\\Program Files\\z a b' + compare 'z a b', invk, len + eq 1, len + else + invk, len = invocation_path_tail '/usr/bin/z a b' + compare 'z a b', invk, len + eq 1, len + + it 'does not count arguments to the executable as part of its path', -> + invk, len = invocation_path_tail 'exe a/b\\c' + compare "exe a/b\\c", invk, len + eq 3, len + + it 'only accepts whitespace as a terminator for the executable name', -> + invk, len = invocation_path_tail 'exe-a+b_c[]()|#!@$%^&*' + eq 'exe-a+b_c[]()|#!@$%^&*', (ffi.string invk) + + it 'is equivalent to path_tail when args do not contain a path separator', -> + ptail = path.path_tail to_cstr "a/b/c x y z" + neq NULL, ptail + tail = ffi.string ptail + + invk, len = invocation_path_tail "a/b/c x y z" + eq tail, ffi.string invk + + it 'is not equivalent to path_tail when args contain a path separator', -> + ptail = path.path_tail to_cstr "a/b/c x y/z" + neq NULL, ptail + + invk, len = invocation_path_tail "a/b/c x y/z" + neq (ffi.string ptail), (ffi.string invk) + describe 'path_next_component', -> path_next_component = (file) -> res = path.path_next_component (to_cstr file) |