robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

dundargoctest: move oldtests to test directory (#22536)af23d17388

master
2.5 KiB89 linesraw
1" Test for environment variables.
2
3scriptencoding utf-8
4
5source check.vim
6
7func Test_environ()
8  unlet! $TESTENV
9  call assert_equal(0, has_key(environ(), 'TESTENV'))
10  let $TESTENV = 'foo'
11  call assert_equal(1, has_key(environ(), 'TESTENV'))
12  let $TESTENV = 'こんにちわ'
13  call assert_equal('こんにちわ', environ()['TESTENV'])
14endfunc
15
16func Test_getenv()
17  unlet! $TESTENV
18  call assert_equal(v:null, 'TESTENV'->getenv())
19  let $TESTENV = 'foo'
20  call assert_equal('foo', getenv('TESTENV'))
21endfunc
22
23func Test_setenv()
24  unlet! $TESTENV
25  eval 'foo'->setenv('TEST ENV')
26  call assert_equal('foo', getenv('TEST ENV'))
27  call setenv('TEST ENV', v:null)
28  call 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.
34  let orig_ENV = $HOME
35
36  let $HOME = 'foo'
37  call assert_equal('foo', expand('~'))
38  " old $HOME value is kept until a new one is set
39  unlet $HOME
40  call assert_equal('foo', expand('~'))
41
42  call setenv('HOME', 'bar')
43  call assert_equal('bar', expand('~'))
44  " old $HOME value is kept until a new one is set
45  call setenv('HOME', v:null)
46  call assert_equal('bar', expand('~'))
47
48  let $HOME = orig_ENV
49endfunc
50
51func Test_external_env()
52  call setenv('FOO', 'HelloWorld')
53  if has('win32')
54    let result = system('echo %FOO%')
55  else
56    let result = system('echo $FOO')
57  endif
58  let result = substitute(result, '[ \r\n]', '', 'g')
59  call assert_equal('HelloWorld', result)
60
61  call setenv('FOO', v:null)
62  if has('win32')
63    let result = system('set | findstr "^FOO="')
64  else
65    let result = system('env | grep ^FOO=')
66  endif
67  call assert_equal('', result)
68endfunc
69
70func Test_mac_locale()
71  CheckFeature 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.
76  let 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"
84  call 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