robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
af23d17388
master
1" Test for environment variables. 2 3scriptencoding utf-8 4 5source check.vim 6 7func Test_environ () 8unlet ! $ TESTENV 9call assert_equal ( 0 , has_key ( environ (), 'TESTENV' )) 10let $ TESTENV = 'foo' 11call assert_equal ( 1 , has_key ( environ (), 'TESTENV' )) 12let $ TESTENV = 'こんにちわ' 13call assert_equal ( 'こんにちわ' , environ ()[ 'TESTENV' ]) 14endfunc 15 16func Test_getenv () 17unlet ! $ TESTENV 18call assert_equal ( v: null , 'TESTENV' ->getenv ()) 19let $ TESTENV = 'foo' 20call assert_equal ( 'foo' , getenv ( 'TESTENV' )) 21endfunc 22 23func Test_setenv () 24unlet ! $ TESTENV 25eval 'foo' ->setenv ( 'TEST ENV' ) 26call assert_equal ( 'foo' , getenv ( 'TEST ENV' )) 27call setenv ( 'TEST ENV' , v: null ) 28call assert_equal ( v: null , getenv ( 'TEST ENV' )) 29endfunc 30 31func Test_special_env () 32" The value for $HOME is cached internally by Vim, ensure the value is up to 33" date. 34let orig_ENV = $ HOME 35 36let $ HOME = 'foo' 37call assert_equal ( 'foo' , expand ( '~' )) 38" old $HOME value is kept until a new one is set 39unlet $ HOME 40call assert_equal ( 'foo' , expand ( '~' )) 41 42call setenv ( 'HOME' , 'bar' ) 43call assert_equal ( 'bar' , expand ( '~' )) 44" old $HOME value is kept until a new one is set 45call setenv ( 'HOME' , v: null ) 46call assert_equal ( 'bar' , expand ( '~' )) 47 48let $ HOME = orig_ENV 49endfunc 50 51func Test_external_env () 52call setenv ( 'FOO' , 'HelloWorld' ) 53if has ( 'win32' ) 54let result = system ( 'echo %FOO%' ) 55else 56let result = system ( 'echo $FOO' ) 57endif 58let result = substitute ( result , '[ \r\n]' , '' , 'g' ) 59call assert_equal ( 'HelloWorld' , result ) 60 61call setenv ( 'FOO' , v: null ) 62if has ( 'win32' ) 63let result = system ( 'set | findstr "^FOO="' ) 64else 65let result = system ( 'env | grep ^FOO=' ) 66endif 67call assert_equal ( '' , result ) 68endfunc 69 70func Test_mac_locale () 71CheckFeature osxdarwin 72 73" If $LANG is not set then the system locale will be used. 74" Run Vim after unsetting all the locale environmental vars, and capture the 75" output of :lang. 76let lang_results = system ( "unset LANG; unset LC_MESSAGES; unset LC_CTYPE; " .. 77 \shellescape ( v: progpath ) .. 78 \" --clean -esX -c 'redir @a' -c 'lang' -c 'put a' -c 'print' -c 'qa!' " ) 79 80" Check that: 81" 1. The locale is the form of <locale>.UTF-8. 82" 2. Check that fourth item (LC_NUMERIC) is properly set to "C". 83" Example match: "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8" 84call assert_match ( '"\([a-zA-Z_]\+\.UTF-8/\)\{3}C\(/[a-zA-Z_]\+\.UTF-8\)\{2}"' , 85 \lang_results , 86 \"Default locale should have UTF-8 encoding set, and LC_NUMERIC set to 'C'" ) 87endfunc 88 89" vim: shiftwidth=2 sts=2 expandtab