Mercurial > vim
comparison src/testdir/test_functions.vim @ 14137:0d534adbcc2f v8.1.0086
patch 8.1.0086: no tests for libcall() and libcallnr()
commit https://github.com/vim/vim/commit/1ceebb4efc455dc6c34e0cd2c2adbd00939f038b
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 19 19:46:06 2018 +0200
patch 8.1.0086: no tests for libcall() and libcallnr()
Problem: No tests for libcall() and libcallnr().
Solution: Add tests. (Dominique Pelle, closes https://github.com/vim/vim/issues/2982)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 19 Jun 2018 20:00:07 +0200 |
parents | e124262d435e |
children | e73c0a0e7e87 |
comparison
equal
deleted
inserted
replaced
14136:a150d64020e9 | 14137:0d534adbcc2f |
---|---|
946 | 946 |
947 bwipe! | 947 bwipe! |
948 delfunc s:save_reg_stat | 948 delfunc s:save_reg_stat |
949 unlet s:reg_stat | 949 unlet s:reg_stat |
950 endfunc | 950 endfunc |
951 | |
952 func Test_libcall_libcallnr() | |
953 if !has('libcall') | |
954 return | |
955 endif | |
956 | |
957 if has('win32') | |
958 let libc = 'msvcrt.dll' | |
959 elseif has('mac') | |
960 let libc = 'libSystem.B.dylib' | |
961 else | |
962 " On Unix, libc.so can be in various places. | |
963 " Interestingly, using an empty string for the 1st argument of libcall | |
964 " allows to call functions from libc which is not documented. | |
965 let libc = '' | |
966 endif | |
967 | |
968 if has('win32') | |
969 call assert_equal($USERPROFILE, libcall(libc, 'getenv', 'USERPROFILE')) | |
970 else | |
971 call assert_equal($HOME, libcall(libc, 'getenv', 'HOME')) | |
972 endif | |
973 | |
974 " If function returns NULL, libcall() should return an empty string. | |
975 call assert_equal('', libcall(libc, 'getenv', 'X_ENV_DOES_NOT_EXIT')) | |
976 | |
977 " Test libcallnr() with string and integer argument. | |
978 call assert_equal(4, libcallnr(libc, 'strlen', 'abcd')) | |
979 call assert_equal(char2nr('A'), libcallnr(libc, 'toupper', char2nr('a'))) | |
980 | |
981 call assert_fails("call libcall(libc, 'Xdoesnotexist_', '')", 'E364:') | |
982 call assert_fails("call libcallnr(libc, 'Xdoesnotexist_', '')", 'E364:') | |
983 | |
984 call assert_fails("call libcall('Xdoesnotexist_', 'getenv', 'HOME')", 'E364:') | |
985 call assert_fails("call libcallnr('Xdoesnotexist_', 'strlen', 'abcd')", 'E364:') | |
986 endfunc |