fix setmetatable() to match C version
This commit is contained in:
@@ -1,14 +1,6 @@
|
||||
-- unit tests for functions in BaseLib.java
|
||||
local ids = {}
|
||||
local function id(obj)
|
||||
local v = ids[obj]
|
||||
if v then
|
||||
return v
|
||||
end
|
||||
table.insert(ids,obj)
|
||||
ids[obj] = type(obj)..'.'..tostring(#ids)
|
||||
return ids[obj]
|
||||
end
|
||||
package.path = "?.lua;src/test/res/?.lua"
|
||||
require 'ids'
|
||||
|
||||
-- print
|
||||
print()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
-- object ids
|
||||
package.path = "?.lua;src/test/res/?.lua"
|
||||
require 'ids'
|
||||
ids = {}
|
||||
|
||||
-- test of common types of errors
|
||||
local function c(f,...) return f(...) end
|
||||
@@ -9,7 +8,6 @@ local function b(...) return c(...) end
|
||||
local function a(...) return pcall(b,...) end
|
||||
s = 'some string'
|
||||
local t = {}
|
||||
|
||||
-- error message tests
|
||||
print( 'a(error)', a(error) )
|
||||
print( 'a(error,"msg")', a(error,"msg") )
|
||||
|
||||
@@ -1,5 +1,31 @@
|
||||
package.path = "?.lua;src/test/res/?.lua"
|
||||
require 'ids'
|
||||
|
||||
-- The purpose of this test case is to demonstrate that
|
||||
-- basic metatable operations on non-table types work.
|
||||
-- i.e. that s.sub(s,...) could be used in place of string.sub(s,...)
|
||||
local s = "hello"
|
||||
print(s:sub(2,4))
|
||||
|
||||
local t = {}
|
||||
function op(name,...)
|
||||
a,b,c,d = pcall( setmetatable, t, ... )
|
||||
print( name, id(t), id(getmetatable(t)), id(a), id(b), id(c), id(d) )
|
||||
end
|
||||
op('set{} ',{})
|
||||
op('set-nil',nil)
|
||||
op('set{} ',{})
|
||||
op('set')
|
||||
op('set{} ',{})
|
||||
op('set{} ',{})
|
||||
op('set{}{}',{},{})
|
||||
op('set-nil',nil)
|
||||
op('set{__}',{__metatable={}})
|
||||
op('set{} ',{})
|
||||
op('set-nil',nil)
|
||||
t = {}
|
||||
op('set{} ',{})
|
||||
op('set-nil',nil)
|
||||
op('set{__}',{__metatable='abc'})
|
||||
op('set{} ',{})
|
||||
op('set-nil',nil)
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
-- unit tests for require() function
|
||||
local ids = {}
|
||||
local ti = table.insert
|
||||
local function id(obj)
|
||||
if not obj or type(obj) == 'number' or type(obj) == 'string' or type(obj) == 'boolean' then
|
||||
return obj
|
||||
end
|
||||
local v = ids[obj]
|
||||
if v then
|
||||
return v
|
||||
end
|
||||
ti(ids,obj)
|
||||
ids[obj] = type(obj)..'.'..tostring(#ids)
|
||||
return ids[obj]
|
||||
end
|
||||
package.path = "?.lua;src/test/res/?.lua"
|
||||
require 'ids'
|
||||
|
||||
-- tests on require
|
||||
package.path='?.lua;src/test/res/?.lua'
|
||||
|
||||
Reference in New Issue
Block a user