annotate src/testdir/test_environ.vim @ 33591:288da62613ba v9.0.2040

patch 9.0.2040: trim(): hard to use default mask Commit: https://github.com/vim/vim/commit/6e6386716f9494ae86027c6d34f657fd03dfec42 Author: Illia Bobyr <illia.bobyr@gmail.com> Date: Tue Oct 17 11:09:45 2023 +0200 patch 9.0.2040: trim(): hard to use default mask Problem: trim(): hard to use default mask Solution: Use default 'mask' when it is v:none The default 'mask' value is pretty complex, as it includes many characters. Yet, if one needs to specify the trimming direction, the third argument, 'trim()' currently requires the 'mask' value to be provided explicitly. 'v:none' is already used to mean "use the default argument value" in user defined functions. See |none-function_argument| in help. closes: #13363 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Illia Bobyr <illia.bobyr@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Tue, 17 Oct 2023 11:15:09 +0200
parents e3ab1d0f2ef9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
1 " Test for environment variables.
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
2
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 scriptencoding utf-8
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4
22417
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
5 source check.vim
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
6
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 func Test_environ()
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 unlet! $TESTENV
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 call assert_equal(0, has_key(environ(), 'TESTENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 let $TESTENV = 'foo'
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 call assert_equal(1, has_key(environ(), 'TESTENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 let $TESTENV = 'こんにちわ'
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 call assert_equal('こんにちわ', environ()['TESTENV'])
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 endfunc
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 func Test_getenv()
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 unlet! $TESTENV
17857
4935244c1128 patch 8.1.1925: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 16922
diff changeset
18 call assert_equal(v:null, 'TESTENV'->getenv())
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 let $TESTENV = 'foo'
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 call assert_equal('foo', getenv('TESTENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 endfunc
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 func Test_setenv()
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 unlet! $TESTENV
17994
0dcc2ee838dd patch 8.1.1993: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents: 17857
diff changeset
25 eval 'foo'->setenv('TEST ENV')
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 call assert_equal('foo', getenv('TEST ENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 call setenv('TEST ENV', v:null)
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 call assert_equal(v:null, getenv('TEST ENV'))
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 endfunc
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30
28459
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
31 func Test_special_env()
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
32 " The value for $HOME is cached internally by Vim, ensure the value is up to
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
33 " date.
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
34 let orig_ENV = $HOME
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
35
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
36 let $HOME = 'foo'
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
37 call assert_equal('foo', expand('~'))
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
38 " old $HOME value is kept until a new one is set
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
39 unlet $HOME
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
40 call assert_equal('foo', expand('~'))
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
41
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
42 call setenv('HOME', 'bar')
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
43 call assert_equal('bar', expand('~'))
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
44 " old $HOME value is kept until a new one is set
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
45 call setenv('HOME', v:null)
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
46 call assert_equal('bar', expand('~'))
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
47
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
48 let $HOME = orig_ENV
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
49 endfunc
52ef65c0637f patch 8.2.4754: using cached values after unsetting some environment variables
Bram Moolenaar <Bram@vim.org>
parents: 22417
diff changeset
50
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 func Test_external_env()
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 call setenv('FOO', 'HelloWorld')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 if has('win32')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 let result = system('echo %FOO%')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 else
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 let result = system('echo $FOO')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 endif
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 let result = substitute(result, '[ \r\n]', '', 'g')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 call assert_equal('HelloWorld', result)
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 call setenv('FOO', v:null)
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 if has('win32')
16922
4ba323df874a patch 8.1.1462: MS-Windows: using special character requires quoting
Bram Moolenaar <Bram@vim.org>
parents: 16920
diff changeset
63 let result = system('set | findstr "^FOO="')
16604
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 else
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 let result = system('env | grep ^FOO=')
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 endif
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 call assert_equal('', result)
1e0a5f09fdf1 patch 8.1.1305: there is no easy way to manipulate environment variables
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 endfunc
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
69
22417
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
70 func Test_mac_locale()
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
71 CheckFeature osxdarwin
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
72
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
73 " If $LANG is not set then the system locale will be used.
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
74 " Run Vim after unsetting all the locale environmental vars, and capture the
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
75 " output of :lang.
31930
e3ab1d0f2ef9 patch 9.0.1297: wrong value for $LC_CTYPE makes the environ test fail
Bram Moolenaar <Bram@vim.org>
parents: 28459
diff changeset
76 let lang_results = system("unset LANG; unset LC_MESSAGES; unset LC_CTYPE; " ..
22417
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
77 \ shellescape(v:progpath) ..
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
78 \ " --clean -esX -c 'redir @a' -c 'lang' -c 'put a' -c 'print' -c 'qa!' ")
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
79
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
80 " Check that:
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
81 " 1. The locale is the form of <locale>.UTF-8.
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
82 " 2. Check that fourth item (LC_NUMERIC) is properly set to "C".
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
83 " Example match: "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8"
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
84 call assert_match('"\([a-zA-Z_]\+\.UTF-8/\)\{3}C\(/[a-zA-Z_]\+\.UTF-8\)\{2}"',
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
85 \ lang_results,
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
86 \ "Default locale should have UTF-8 encoding set, and LC_NUMERIC set to 'C'")
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
87 endfunc
68115baaf9e4 patch 8.2.1757: Mac: default locale is lacking the encoding
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
88
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 17994
diff changeset
89 " vim: shiftwidth=2 sts=2 expandtab