mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	fixup! unittests: Add tests for vim_to_object function
This commit is contained in:
		@@ -8,6 +8,7 @@ local ffi = helpers.ffi
 | 
				
			|||||||
local list_type = eval_helpers.list_type
 | 
					local list_type = eval_helpers.list_type
 | 
				
			||||||
local dict_type = eval_helpers.dict_type
 | 
					local dict_type = eval_helpers.dict_type
 | 
				
			||||||
local func_type = eval_helpers.func_type
 | 
					local func_type = eval_helpers.func_type
 | 
				
			||||||
 | 
					local nil_value = eval_helpers.nil_value
 | 
				
			||||||
local int_type = eval_helpers.int_type
 | 
					local int_type = eval_helpers.int_type
 | 
				
			||||||
local flt_type = eval_helpers.flt_type
 | 
					local flt_type = eval_helpers.flt_type
 | 
				
			||||||
local type_key = eval_helpers.type_key
 | 
					local type_key = eval_helpers.type_key
 | 
				
			||||||
@@ -45,7 +46,7 @@ local obj2lua_tab = {
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
  end,
 | 
					  end,
 | 
				
			||||||
  [tonumber(api.kObjectTypeNil)] = function(obj)
 | 
					  [tonumber(api.kObjectTypeNil)] = function(obj)
 | 
				
			||||||
    return NIL
 | 
					    return nil_value
 | 
				
			||||||
  end,
 | 
					  end,
 | 
				
			||||||
  [tonumber(api.kObjectTypeFloat)] = function(obj)
 | 
					  [tonumber(api.kObjectTypeFloat)] = function(obj)
 | 
				
			||||||
    return tonumber(obj.data.floating)
 | 
					    return tonumber(obj.data.floating)
 | 
				
			||||||
@@ -132,7 +133,7 @@ lua2obj = function(l)
 | 
				
			|||||||
      size=#l,
 | 
					      size=#l,
 | 
				
			||||||
      data=eval.xmemdupz(to_cstr(l), #l),
 | 
					      data=eval.xmemdupz(to_cstr(l), #l),
 | 
				
			||||||
    }})
 | 
					    }})
 | 
				
			||||||
  elseif l == nil or l == NIL then
 | 
					  elseif l == nil or l == nil_value then
 | 
				
			||||||
    return obj(api.kObjectTypeNil, {integer=0})
 | 
					    return obj(api.kObjectTypeNil, {integer=0})
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
@@ -143,6 +144,9 @@ return {
 | 
				
			|||||||
  func_type=func_type,
 | 
					  func_type=func_type,
 | 
				
			||||||
  int_type=int_type,
 | 
					  int_type=int_type,
 | 
				
			||||||
  flt_type=flt_type,
 | 
					  flt_type=flt_type,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  nil_value=nil_value,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  type_key=type_key,
 | 
					  type_key=type_key,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  obj2lua=obj2lua,
 | 
					  obj2lua=obj2lua,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,6 +9,7 @@ local eq = helpers.eq
 | 
				
			|||||||
local lua2typvalt = eval_helpers.lua2typvalt
 | 
					local lua2typvalt = eval_helpers.lua2typvalt
 | 
				
			||||||
local typvalt = eval_helpers.typvalt
 | 
					local typvalt = eval_helpers.typvalt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local nil_value = api_helpers.nil_value
 | 
				
			||||||
local list_type = api_helpers.list_type
 | 
					local list_type = api_helpers.list_type
 | 
				
			||||||
local int_type = api_helpers.int_type
 | 
					local int_type = api_helpers.int_type
 | 
				
			||||||
local type_key = api_helpers.type_key
 | 
					local type_key = api_helpers.type_key
 | 
				
			||||||
@@ -33,7 +34,7 @@ describe('vim_to_object', function()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  simple_test('converts true', true)
 | 
					  simple_test('converts true', true)
 | 
				
			||||||
  simple_test('converts false', false)
 | 
					  simple_test('converts false', false)
 | 
				
			||||||
  simple_test('converts nil', NIL)
 | 
					  simple_test('converts nil', nil_value)
 | 
				
			||||||
  simple_test('converts 1', 1)
 | 
					  simple_test('converts 1', 1)
 | 
				
			||||||
  simple_test('converts -1.5', -1.5)
 | 
					  simple_test('converts -1.5', -1.5)
 | 
				
			||||||
  simple_test('converts empty string', '')
 | 
					  simple_test('converts empty string', '')
 | 
				
			||||||
@@ -48,30 +49,30 @@ describe('vim_to_object', function()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  local dct = {}
 | 
					  local dct = {}
 | 
				
			||||||
  dct.dct = dct
 | 
					  dct.dct = dct
 | 
				
			||||||
  different_output_test('outputs nil for nested dictionaries (1 level)', dct, {dct=NIL})
 | 
					  different_output_test('outputs nil for nested dictionaries (1 level)', dct, {dct=nil_value})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local lst = {}
 | 
					  local lst = {}
 | 
				
			||||||
  lst[1] = lst
 | 
					  lst[1] = lst
 | 
				
			||||||
  different_output_test('outputs nil for nested lists (1 level)', lst, {NIL})
 | 
					  different_output_test('outputs nil for nested lists (1 level)', lst, {nil_value})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local dct2 = {test=true, dict=NIL}
 | 
					  local dct2 = {test=true, dict=nil_value}
 | 
				
			||||||
  dct2.dct = {dct2}
 | 
					  dct2.dct = {dct2}
 | 
				
			||||||
  different_output_test('outputs nil for nested dictionaries (2 level, in list)',
 | 
					  different_output_test('outputs nil for nested dictionaries (2 level, in list)',
 | 
				
			||||||
                        dct2, {dct={NIL}, test=true, dict=NIL})
 | 
					                        dct2, {dct={nil_value}, test=true, dict=nil_value})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local dct3 = {test=true, dict=NIL}
 | 
					  local dct3 = {test=true, dict=nil_value}
 | 
				
			||||||
  dct3.dct = {dctin=dct3}
 | 
					  dct3.dct = {dctin=dct3}
 | 
				
			||||||
  different_output_test('outputs nil for nested dictionaries (2 level, in dict)',
 | 
					  different_output_test('outputs nil for nested dictionaries (2 level, in dict)',
 | 
				
			||||||
                        dct3, {dct={dctin=NIL}, test=true, dict=NIL})
 | 
					                        dct3, {dct={dctin=nil_value}, test=true, dict=nil_value})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local lst2 = {}
 | 
					  local lst2 = {}
 | 
				
			||||||
  lst2[1] = {lst2}
 | 
					  lst2[1] = {lst2}
 | 
				
			||||||
  different_output_test('outputs nil for nested lists (2 level, in list)', lst2, {{NIL}})
 | 
					  different_output_test('outputs nil for nested lists (2 level, in list)', lst2, {{nil_value}})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local lst3 = {nil, true, false, 'ttest'}
 | 
					  local lst3 = {nil, true, false, 'ttest'}
 | 
				
			||||||
  lst3[1] = {lst=lst3}
 | 
					  lst3[1] = {lst=lst3}
 | 
				
			||||||
  different_output_test('outputs nil for nested lists (2 level, in dict)',
 | 
					  different_output_test('outputs nil for nested lists (2 level, in dict)',
 | 
				
			||||||
                        lst3, {{lst=NIL}, true, false, 'ttest'})
 | 
					                        lst3, {{lst=nil_value}, true, false, 'ttest'})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('outputs empty list for NULL list', function()
 | 
					  it('outputs empty list for NULL list', function()
 | 
				
			||||||
    local tt = typvalt('VAR_LIST', {v_list=NULL})
 | 
					    local tt = typvalt('VAR_LIST', {v_list=NULL})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,6 +16,8 @@ local func_type = {[true]='func type'}
 | 
				
			|||||||
local int_type = {[true]='int type'}
 | 
					local int_type = {[true]='int type'}
 | 
				
			||||||
local flt_type = {[true]='flt type'}
 | 
					local flt_type = {[true]='flt type'}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					local nil_value = {[true]='nil'}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function list(...)
 | 
					local function list(...)
 | 
				
			||||||
  local ret = ffi.gc(eval.list_alloc(), eval.list_unref)
 | 
					  local ret = ffi.gc(eval.list_alloc(), eval.list_unref)
 | 
				
			||||||
  eq(0, ret.lv_refcount)
 | 
					  eq(0, ret.lv_refcount)
 | 
				
			||||||
@@ -43,7 +45,7 @@ end
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
local special_tab = {
 | 
					local special_tab = {
 | 
				
			||||||
  [eval.kSpecialVarFalse] = false,
 | 
					  [eval.kSpecialVarFalse] = false,
 | 
				
			||||||
  [eval.kSpecialVarNull] = NIL,
 | 
					  [eval.kSpecialVarNull] = nil_value,
 | 
				
			||||||
  [eval.kSpecialVarTrue] = true,
 | 
					  [eval.kSpecialVarTrue] = true,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -163,7 +165,9 @@ local lua2typvalt_type_tab = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
lua2typvalt = function(l, processed)
 | 
					lua2typvalt = function(l, processed)
 | 
				
			||||||
  processed = processed or {}
 | 
					  processed = processed or {}
 | 
				
			||||||
  if type(l) == 'table' then
 | 
					  if l == nil or l == nil_value then
 | 
				
			||||||
 | 
					    return typvalt(eval.VAR_SPECIAL, {v_special=eval.kSpecialVarNull})
 | 
				
			||||||
 | 
					  elseif type(l) == 'table' then
 | 
				
			||||||
    if l[type_key] then
 | 
					    if l[type_key] then
 | 
				
			||||||
      return lua2typvalt_type_tab[l[type_key]](l, processed)
 | 
					      return lua2typvalt_type_tab[l[type_key]](l, processed)
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
@@ -181,8 +185,6 @@ lua2typvalt = function(l, processed)
 | 
				
			|||||||
    })
 | 
					    })
 | 
				
			||||||
  elseif type(l) == 'string' then
 | 
					  elseif type(l) == 'string' then
 | 
				
			||||||
    return typvalt(eval.VAR_STRING, {v_string=eval.xmemdupz(to_cstr(l), #l)})
 | 
					    return typvalt(eval.VAR_STRING, {v_string=eval.xmemdupz(to_cstr(l), #l)})
 | 
				
			||||||
  elseif l == nil or l == NIL then
 | 
					 | 
				
			||||||
    return typvalt(eval.VAR_SPECIAL, {v_special=eval.kSpecialVarNull})
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -194,6 +196,9 @@ return {
 | 
				
			|||||||
  func_type=func_type,
 | 
					  func_type=func_type,
 | 
				
			||||||
  int_type=int_type,
 | 
					  int_type=int_type,
 | 
				
			||||||
  flt_type=flt_type,
 | 
					  flt_type=flt_type,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  nil_value=nil_value,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  type_key=type_key,
 | 
					  type_key=type_key,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  list=list,
 | 
					  list=list,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user