aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/vimscript')
-rw-r--r--test/functional/vimscript/environ_spec.lua32
1 files changed, 26 insertions, 6 deletions
diff --git a/test/functional/vimscript/environ_spec.lua b/test/functional/vimscript/environ_spec.lua
index abb093a6c8..9046d2d696 100644
--- a/test/functional/vimscript/environ_spec.lua
+++ b/test/functional/vimscript/environ_spec.lua
@@ -11,17 +11,37 @@ local command = n.command
local eval = n.eval
local setenv = n.fn.setenv
-describe('environment variables', function()
- it('environ() handles empty env variable', function()
+describe('vim.fn.environ()', function()
+ it('exists() handles empty env variable', function()
+ clear({ env = { EMPTY_VAR = '' } })
+ eq(1, exists('$EMPTY_VAR'))
+ eq(0, exists('$DOES_NOT_EXIST'))
+ end)
+
+ it('handles empty env variable', function()
clear({ env = { EMPTY_VAR = '' } })
eq('', environ()['EMPTY_VAR'])
+ -- vim.env returns nil if the value is empty string. 🤷
+ eq(vim.NIL, n.exec_lua('return vim.env.EMPTY_VAR'))
eq(nil, environ()['DOES_NOT_EXIST'])
+ eq(vim.NIL, n.exec_lua('return vim.env.DOES_NOT_EXIST'))
end)
- it('exists() handles empty env variable', function()
- clear({ env = { EMPTY_VAR = '' } })
- eq(1, exists('$EMPTY_VAR'))
- eq(0, exists('$DOES_NOT_EXIST'))
+ it('results match getenv()', function()
+ clear()
+ eq(
+ true,
+ n.exec_lua([[
+ local env = vim.fn.environ()
+ assert(vim.tbl_count(env) > 10, 'environ() should have some env vars!')
+ for k, v in pairs(env) do
+ if v ~= '' and vim.fn.getenv(k) ~= v then
+ error(('environ()[%q] = %q, but vim.fn.getenv(%q) = %q'):format(k, v, k, vim.fn.getenv(k)))
+ end
+ end
+ return true
+ ]])
+ )
end)
end)