aboutsummaryrefslogtreecommitdiff
path: root/test/unit/eval/tricks_spec.lua
blob: 54029734fba2c46fa6a391db6135af7435430093 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)

local cimport = helpers.cimport
local to_cstr = helpers.to_cstr
local ffi = helpers.ffi
local eq = helpers.eq

local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h',
                     './src/nvim/memory.h')

local eval0 = function(expr)
  local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}),
                    eval.tv_clear)
  if eval.eval0(to_cstr(expr), tv, nil, true) == 0 then
    return nil
  else
    return tv
  end
end

describe('NULL typval_T', function()
  itp('is produced by $XXX_UNEXISTENT_VAR_XXX', function()
    -- Required for various tests which need to check whether typval_T with NULL
    -- string works correctly. This test checks that unexistent environment
    -- variable produces NULL string, not that some specific environment
    -- variable does not exist. Last bit is left for the test writers.
    local unexistent_env = 'XXX_UNEXISTENT_VAR_XXX'
    while os.getenv(unexistent_env) ~= nil do
      unexistent_env = unexistent_env .. '_XXX'
    end
    local rettv = eval0('$' .. unexistent_env)
    eq(eval.VAR_STRING, rettv.v_type)
    eq(nil, rettv.vval.v_string)
  end)

  itp('is produced by v:_null_list', function()
    local rettv = eval0('v:_null_list')
    eq(eval.VAR_LIST, rettv.v_type)
    eq(nil, rettv.vval.v_list)
  end)

  itp('is produced by v:_null_dict', function()
    local rettv = eval0('v:_null_dict')
    eq(eval.VAR_DICT, rettv.v_type)
    eq(nil, rettv.vval.v_dict)
  end)
end)