diff --git a/test/lang/compare.lua b/test/lang/compare.lua index fdabef5e8d..9b38ff5e2f 100644 --- a/test/lang/compare.lua +++ b/test/lang/compare.lua @@ -247,3 +247,77 @@ do --- string 1 255 assert(a >= b) assert(b <= a) end + +do --- String comparisons: + local function str_cmp(a, b, lt, gt, le, ge) + assert(ab == gt) + assert(a<=b == le) + assert(a>=b == ge) + assert((not (ab)) == (not gt)) + assert((not (a<=b)) == (not le)) + assert((not (a>=b)) == (not ge)) + end + + local function str_lo(a, b) + str_cmp(a, b, true, false, true, false) + end + + local function str_eq(a, b) + str_cmp(a, b, false, false, true, true) + end + + local function str_hi(a, b) + str_cmp(a, b, false, true, false, true) + end + + str_lo("a", "b") + str_eq("a", "a") + str_hi("b", "a") + + str_lo("a", "aa") + str_hi("aa", "a") + + str_lo("a", "a\0") + str_hi("a\0", "a") +end + +do --- obj_eq/ne + local function obj_eq(a, b) + assert(a==b == true) + assert(a~=b == false) + end + + local function obj_ne(a, b) + assert(a==b == false) + assert(a~=b == true) + end + + obj_eq(nil, nil) + obj_ne(nil, false) + obj_ne(nil, true) + + obj_ne(false, nil) + obj_eq(false, false) + obj_ne(false, true) + + obj_ne(true, nil) + obj_ne(true, false) + obj_eq(true, true) + + obj_eq(1, 1) + obj_ne(1, 2) + obj_ne(2, 1) + + obj_eq("a", "a") + obj_ne("a", "b") + obj_ne("a", 1) + obj_ne(1, "a") + + local t, t2 = {}, {} + obj_eq(t, t) + obj_ne(t, t2) + obj_ne(t, 1) + obj_ne(t, "") +end diff --git a/test/lang/index b/test/lang/index index 1cdf404ee6..457490ef30 100644 --- a/test/lang/index +++ b/test/lang/index @@ -11,3 +11,4 @@ coroutine.lua tail_recursion.lua gc.lua goto.lua +goto +meta diff --git a/test/lang/meta/arith.lua b/test/lang/meta/arith.lua new file mode 100644 index 0000000000..17de4c8cde --- /dev/null +++ b/test/lang/meta/arith.lua @@ -0,0 +1,118 @@ +local function create(arith, v1, v2) + local meta = { + __add=function(a,b) return arith("add", a, b) end, + __sub=function(a,b) return arith("sub", a, b) end, + __mul=function(a,b) return arith("mul", a, b) end, + __div=function(a,b) return arith("div", a, b) end, + __mod=function(a,b) return arith("mod", a, b) end, + __pow=function(a,b) return arith("pow", a, b) end, + __unm=function(a,b) return arith("unm", a, b) end, + } + return setmetatable({v1}, meta), setmetatable({v2}, meta) +end + +do --- op + local a, b = create(function(op,a,b) return op end) + assert(a+b == "add") + assert(a-b == "sub") + assert(a*b == "mul") + assert(a/b == "div") + assert(a%b == "mod") + assert(a^b == "pow") + assert(-a == "unm") +end + +do --- lhs + local a, b = create(function(op,a,b) return a[1] end, "foo", 42) + assert(a+b == "foo") + assert(a-b == "foo") + assert(a*b == "foo") + assert(a/b == "foo") + assert(a%b == "foo") + assert(a^b == "foo") + assert(-a == "foo") +end + +do --- rhs + local a, b = create(function(op,a,b) return b[1] end, 42, "foo") + assert(a+b == "foo") + assert(a-b == "foo") + assert(a*b == "foo") + assert(a/b == "foo") + assert(a%b == "foo") + assert(a^b == "foo") + assert(-a == 42) +end + +do --- meta only lhs + local a, b = create(function(op,a,b) return a[1]+b end, 39), 3 + assert(a+b == 42) + assert(a-b == 42) + assert(a*b == 42) + assert(a/b == 42) + assert(a%b == 42) + assert(a^b == 42) +end + +do --- meta only rhs + local a, b = 39, create(function(op,a,b) return a+b[1] end, 3) + assert(a+b == 42) + assert(a-b == 42) + assert(a*b == 42) + assert(a/b == 42) + assert(a%b == 42) + assert(a^b == 42) +end + +do --- defaults string, int + local a, b = "39", 3 + assert(a+b == 42) + assert(a-b == 36) + assert(a*b == 117) + assert(a/b == 13) + assert(a%b == 0) + assert(a^b == 59319) + assert(-a == -39) +end + +do --- defaults int, string + local a, b = 39, "3" + assert(a+b == 42) + assert(a-b == 36) + assert(a*b == 117) + assert(a/b == 13) + assert(a%b == 0) + assert(a^b == 59319) + assert(-a == -39) +end + +do --- defaults string, string + local a, b = "39", "3" + assert(a+b == 42) + assert(a-b == 36) + assert(a*b == 117) + assert(a/b == 13) + assert(a%b == 0) + assert(a^b == 59319) + assert(-a == -39) +end + +do --- defaults string, kint + local a = "39" + assert(a+3 == 42) + assert(a-3 == 36) + assert(a*3 == 117) + assert(a/3 == 13) + assert(a%3 == 0) + assert(a^3 == 59319) +end + +do --- defaults kint, string + local b = "3" + assert(39+b == 42) + assert(39-b == 36) + assert(39*b == 117) + assert(39/b == 13) + assert(39%b == 0) + assert(39^b == 59319) +end diff --git a/test/misc/meta_arith_jit.lua b/test/lang/meta/arith_jit.lua similarity index 96% rename from test/misc/meta_arith_jit.lua rename to test/lang/meta/arith_jit.lua index 485cebf53e..2cb35dbb37 100644 --- a/test/misc/meta_arith_jit.lua +++ b/test/lang/meta/arith_jit.lua @@ -1,5 +1,5 @@ -do +do --- assert rhs local t = {} local mt = { __add = function(a, b) assert(b == t); return a+11 end, @@ -20,7 +20,7 @@ do do local x = 0; for i=1,100 do x = x + (-t) end; assert(x == 1700); end end -do +do --- assert lhs local t = {} local mt = { __add = function(a, b) assert(a == t); return b+11 end, @@ -39,7 +39,7 @@ do do local x = 0; for i=1,100 do x = t ^ x end; assert(x == 1600); end end -do +do --- assert both sides local t = {} local mt = { __add = function(a, b) assert(a == t and b == t); return 11 end, @@ -58,7 +58,7 @@ do do local x = 0; for i=1,100 do x = t ^ t end; assert(x == 16); end end -do +do --- adjust no result to one result local t = {} local mt = { __add = function(a, b) end } t = setmetatable(t, mt) diff --git a/test/misc/meta_call.lua b/test/lang/meta/call.lua similarity index 70% rename from test/misc/meta_call.lua rename to test/lang/meta/call.lua index 5cc22be109..c77c0dd8ff 100644 --- a/test/misc/meta_call.lua +++ b/test/lang/meta/call.lua @@ -5,7 +5,7 @@ end local meta = { __call = callmeta } -do +do --- table local t = setmetatable({}, meta) local o,a,b = t() assert(o == t and a == nil and b == nil) @@ -15,7 +15,7 @@ do assert(o == t and a == "foo" and b == "bar") end -do +do --- userdata +lua<5.2 local u = newproxy(true) getmetatable(u).__call = callmeta @@ -27,16 +27,18 @@ do assert(o == u and a == "foo" and b == "bar") end -debug.setmetatable(0, meta) -local o,a,b = (42)() -assert(o == 42 and a == nil and b == nil) -local o,a,b = (42)("foo") -assert(o == 42 and a == "foo" and b == nil) -local o,a,b = (42)("foo", "bar") -assert(o == 42 and a == "foo" and b == "bar") -debug.setmetatable(0, nil) +do --- number + debug.setmetatable(0, meta) + local o,a,b = (42)() + assert(o == 42 and a == nil and b == nil) + local o,a,b = (42)("foo") + assert(o == 42 and a == "foo" and b == nil) + local o,a,b = (42)("foo", "bar") + assert(o == 42 and a == "foo" and b == "bar") + debug.setmetatable(0, nil) +end -do +do --- table with changing metamethod local tc = setmetatable({}, { __call = function(o,a,b) return o end}) local ta = setmetatable({}, { __add = tc}) local o,a = ta + ta @@ -47,32 +49,33 @@ do assert(o == ta and a == nil) end -do +do --- jit table local t = setmetatable({}, { __call = function(t, a) return 100-a end }) for i=1,100 do assert(t(i) == 100-i) end end -do +do --- jit table rawget as metamethod local t = setmetatable({}, { __call = rawget }) for i=1,100 do t[i] = 100-i end for i=1,100 do assert(t(i) == 100-i) end end -debug.setmetatable(0, { __call = function(n) return 100-n end }) -for i=1,100 do assert((i)() == 100-i) end -debug.setmetatable(0, nil) +do --- jit number + debug.setmetatable(0, { __call = function(n) return 100-n end }) + for i=1,100 do assert((i)() == 100-i) end + debug.setmetatable(0, nil) +end -do +do --- jit newindex pcall local t = setmetatable({}, { __newindex = pcall, __call = rawset }) for i=1,100 do t[i] = 100-i end for i=1,100 do assert(t[i] == 100-i) end end -do +do --- jit index pcall local t = setmetatable({}, { __index = pcall, __newindex = rawset, __call = function(t, i) t[i] = 100-i end, }) for i=1,100 do assert(t[i] == true and rawget(t, i) == 100-i) end end - diff --git a/test/misc/meta_cat.lua b/test/lang/meta/cat.lua similarity index 94% rename from test/misc/meta_cat.lua rename to test/lang/meta/cat.lua index 6f9e9fff39..48a89e4d68 100644 --- a/test/misc/meta_cat.lua +++ b/test/lang/meta/cat.lua @@ -1,16 +1,15 @@ +local function create(cat, v1, v2) + local meta = { __concat = cat } + return setmetatable({v1}, meta), setmetatable({v2}, meta) +end -do +do --- default local a, b, c = "foo", "bar", "baz" assert(a..b == "foobar") assert(a..b..c == "foobarbaz") end -local function create(cat, v1, v2) - local meta = { __concat = cat } - return setmetatable({v1}, meta), setmetatable({v2}, meta) -end - -do +do --- lhs local a, b = create(function(a, b) return a end) assert(a..b == a) assert(b..a == b) @@ -20,7 +19,7 @@ do assert(a..b..b..b..b..b..b..b == a) end -do +do --- rhs local a, b = create(function(a, b) return b end) assert(a..b == b) assert(b..a == a) @@ -30,7 +29,7 @@ do assert(a..a..a..a..a..a..a..b == b) end -do +do --- mixed types local a, b = create(function(a, b) return (type(a) == "string" and a or a[1]).. (type(b) == "string" and b or b[1]) @@ -45,7 +44,7 @@ do assert(a..b..a..b..a.."x".."x".."x" == "ababaxxx") end -do +do --- jit mixed types local a, b = create(function(a, b) if a ~= b then local x = gg end return (type(a) == "string" and a or a[1]).. diff --git a/test/lang/meta/comp.lua b/test/lang/meta/comp.lua new file mode 100644 index 0000000000..23f18b08ec --- /dev/null +++ b/test/lang/meta/comp.lua @@ -0,0 +1,120 @@ + +local function create(comp, v1, v2) + local meta = { + __lt=function(a,b) return comp("lt", a, b) end, + __le=function(a,b) return comp("le", a, b) end, + } + return setmetatable({v1}, meta), setmetatable({v2}, meta) +end + +do --- __lt and __le xop + local xop + local a, b = create(function(op,a,b) xop = op; return "" end) + assert(ab == true and xop == "lt"); xop = nil + assert(a<=b == true and xop == "le"); xop = nil + assert(a>=b == true and xop == "le"); xop = nil + + assert(not (ab) == false and xop == "lt"); xop = nil + assert(not (a<=b) == false and xop == "le"); xop = nil + assert(not (a>=b) == false and xop == "le"); xop = nil + + -- __le metamethod is optional and substituted with arg+res inverted __lt. + local f = getmetatable(a).__le + getmetatable(a).__le = nil + assert(ab == true and xop == "lt"); xop = nil + assert(a<=b == false and xop == "lt"); xop = nil + assert(a>=b == false and xop == "lt"); xop = nil + + assert(not (ab) == false and xop == "lt"); xop = nil + assert(not (a<=b) == true and xop == "lt"); xop = nil + assert(not (a>=b) == true and xop == "lt"); xop = nil + getmetatable(a).__le = f + + -- Different metatable, but same metamethod works, too. + setmetatable(b, { __lt = getmetatable(b).__lt, __le = getmetatable(b).__le }) + assert(ab == true and xop == "lt"); xop = nil + assert(a<=b == true and xop == "le"); xop = nil + assert(a>=b == true and xop == "le"); xop = nil + + assert(not (ab) == false and xop == "lt"); xop = nil + assert(not (a<=b) == false and xop == "le"); xop = nil + assert(not (a>=b) == false and xop == "le"); xop = nil +end + +do --- __lt and __le values + local a, b = create(function(op,a,b) + if op == "lt" then return a[1]b == false) + assert(a<=b == true) + assert(a>=b == false) + + assert(not (ab) == true) + assert(not (a<=b) == false) + assert(not (a>=b) == true) + + b[1] = 1 + assert(ab == false) + assert(a<=b == true) + assert(a>=b == true) + + assert(not (ab) == true) + assert(not (a<=b) == false) + assert(not (a>=b) == false) + + a[1] = 2 + assert(ab == true) + assert(a<=b == false) + assert(a>=b == true) + + assert(not (ab) == false) + assert(not (a<=b) == true) + assert(not (a>=b) == false) + + -- __le metamethod is optional and substituted with arg+res inverted __lt. + getmetatable(a).__le = nil + a[1] = 1 + b[1] = 2 + assert(ab == false) + assert(a<=b == true) + assert(a>=b == false) + + assert(not (ab) == true) + assert(not (a<=b) == false) + assert(not (a>=b) == true) + + b[1] = 1 + assert(ab == false) + assert(a<=b == true) + assert(a>=b == true) + + assert(not (ab) == true) + assert(not (a<=b) == false) + assert(not (a>=b) == false) + + a[1] = 2 + assert(ab == true) + assert(a<=b == false) + assert(a>=b == true) + + assert(not (ab) == false) + assert(not (a<=b) == true) + assert(not (a>=b) == false) +end diff --git a/test/lang/meta/comp_jit.lua b/test/lang/meta/comp_jit.lua new file mode 100644 index 0000000000..d0a19d80a2 --- /dev/null +++ b/test/lang/meta/comp_jit.lua @@ -0,0 +1,104 @@ +do --- coverage + local lt, le = false, false + local t, u = {}, {} + local x, ax, bx + local function ck(xx, a, b) + if x ~= xx then error("bad x", 2) end + if ax ~= a then error("bad ax", 2) end + if bx ~= b then error("bad bx", 2) end + end + local mt = { + __lt = function(a, b) ax=a; bx=b; return lt end, + __le = function(a, b) ax=a; bx=b; return le end, + } + t = setmetatable(t, mt) + u = setmetatable(u, mt) + lt, le = false, false + x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(2, u, t) + lt, le = false, true + x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(1, u, t) + lt, le = true, false + x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(2, u, t) + lt, le = true, true + x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(1, u, t) + mt.__le = nil + lt = false + x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(1, t, u) + lt = true + x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(2, t, u) + x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(1, t, u) + x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(2, u, t) + x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(1, u, t) + x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(2, t, u) +end + +do --- Mixed metamethods for ordered comparisons. + local mt1 = { __lt = function(a, b) return a[1] < b[1] end } + local mt2 = { __lt = function(a, b) return a[1] < b[1] end } + local t1 = setmetatable({1}, mt1) + local t2 = setmetatable({2}, mt2) + do + local x + for i=1,100 do x = t1 <= t1 end + assert(x == true) + end + local ok, ret = pcall(function() + local x + for i=1,100 do x = t1 < t2 end + return x + end) + if table.pack then + assert(ok and ret == true) + else + assert(not ok) + end + local ok, ret = pcall(function() + local x + for i=1,100 do x = t1 <= t2 end + return x + end) + if table.pack then + assert(ok and ret == true) + else + assert(not ok) + end +end + diff --git a/test/lang/meta/eq.lua b/test/lang/meta/eq.lua new file mode 100644 index 0000000000..ebf604357c --- /dev/null +++ b/test/lang/meta/eq.lua @@ -0,0 +1,30 @@ +local function create(equal, v1, v2) + local meta = { __eq = equal } + return setmetatable({v1}, meta), setmetatable({v2}, meta) +end + +do --- __eq xop + local xop + local a, b = create(function(a,b) xop = "eq" return "" end) + assert(a==b == true and xop == "eq"); xop = nil + assert(a~=b == false and xop == "eq"); xop = nil + + -- Different metatable, but same metamethod works, too. + setmetatable(b, { __eq = getmetatable(b).__eq }) + assert(a==b == true and xop == "eq"); xop = nil + assert(a~=b == false and xop == "eq"); xop = nil +end + +do --- __eq values + local a, b = create(function(a,b) return a[1] == b[1] end, 1, 2) + assert(a==b == false) + assert(a~=b == true) + + b[1] = 1 + assert(a==b == true) + assert(a~=b == false) + + a[1] = 2 + assert(a==b == false) + assert(a~=b == true) +end diff --git a/test/misc/meta_eq_jit.lua b/test/lang/meta/eq_jit.lua similarity index 95% rename from test/misc/meta_eq_jit.lua rename to test/lang/meta/eq_jit.lua index ad5d68f18b..47e14207cf 100644 --- a/test/misc/meta_eq_jit.lua +++ b/test/lang/meta/eq_jit.lua @@ -1,5 +1,5 @@ -do +do --- coverage local eq = false local t, u = {}, {} local x, ax, bx @@ -25,7 +25,7 @@ do x = 0; for i=1,100 do x = not (t ~= u) and 2 or 1 end ck(2, t, u) end -do +do --- non-constant objects +bit local bit = require("bit") local mt = { __eq = function(a, b) return true end } local tt = { [0] = setmetatable({}, mt), setmetatable({}, mt) } @@ -33,4 +33,3 @@ do assert(tt[0] == tt[bit.band(i, 1)]) end end - diff --git a/test/lang/meta/framegap.lua b/test/lang/meta/framegap.lua new file mode 100644 index 0000000000..0080633a24 --- /dev/null +++ b/test/lang/meta/framegap.lua @@ -0,0 +1,24 @@ +do --- untitled + local t = setmetatable({}, { __add = function(a, b) + if b > 200 then + for j=1,10 do end + return b+3 + elseif b > 100 then + return b+2 + else + return b+1 + end + end }) + + local function f(t, i) + do return t+i end + -- Force large frame with unassigned slots below mm. + do local a,b,c,d,e,f,g,h,i,j,k end + end + + local x = 0 + for i=1,300 do + x = f(t, i) + end + assert(x == 303) +end diff --git a/test/lang/meta/index b/test/lang/meta/index new file mode 100644 index 0000000000..bf2f457625 --- /dev/null +++ b/test/lang/meta/index @@ -0,0 +1,13 @@ +arith.lua +arith_jit.lua +call.lua +cat.lua +comp.lua +comp_jit.lua +eq.lua +eq_jit.lua +framegap.lua +index.lua +len.lua +newindex.lua +nomm.lua diff --git a/test/lang/meta/index.lua b/test/lang/meta/index.lua new file mode 100644 index 0000000000..4d6d0ffee3 --- /dev/null +++ b/test/lang/meta/index.lua @@ -0,0 +1,60 @@ +do --- table 1 + local t=setmetatable({}, {__index=function(t,k) + return 100-k + end}) + + for i=1,100 do assert(t[i] == 100-i) end + + for i=1,100 do t[i] = i end + for i=1,100 do assert(t[i] == i) end + + for i=1,100 do t[i] = nil end + for i=1,100 do assert(t[i] == 100-i) end +end + +do --- table 2 + local x + local t2=setmetatable({}, {__index=function(t,k) + x = k + end}) + + assert(t2[1] == nil) + assert(x == 1) + + assert(t2.foo == nil) + assert(x == "foo") +end + +do --- userdata +lua<5.2 + local u = newproxy(true) + getmetatable(u).__index = { foo = u, bar = 42 } + + local x = 0 + for i=1,100 do + x = x + u.bar + u = u.foo + end + assert(x == 4200) + + x = 0 + for i=1,100 do + u = u.foo + x = x + u.bar + end + assert(x == 4200) +end + +do --- string + local s = "foo" + local mt = debug.getmetatable(s) + debug.setmetatable(s, {__index = {s = s, len = string.len}}) + local x = 0 + local t = {} + for i=1,100 do + x = x + s:len() + s = s.s + t[s] = t -- Hash store with same type prevents hoisting + end + debug.setmetatable(s, mt) + assert(x == 300) +end diff --git a/test/misc/meta_len.lua b/test/lang/meta/len.lua similarity index 75% rename from test/misc/meta_len.lua rename to test/lang/meta/len.lua index 6e77678de5..2410daa617 100644 --- a/test/misc/meta_len.lua +++ b/test/lang/meta/len.lua @@ -1,8 +1,6 @@ - -local lua52 = os.getenv("LUA52") - +local compat52 = table.pack local mt = { __len = function(o, o2) - if lua52 then + if compat52 then assert(o2 == o) else assert(o2 == nil) @@ -10,7 +8,7 @@ local mt = { __len = function(o, o2) return 42 end } -do +do --- table local t = {1,2,3} assert(#t == 3) assert(#"abcdef" == 6) @@ -20,7 +18,7 @@ do assert(#t == 3) setmetatable(t, mt) - if lua52 then + if compat52 then assert(#t == 42) -- __len DOES work on tables. assert(rawlen(t) == 3) else @@ -28,7 +26,7 @@ do end end -do +do --- userdata +lua<5.2 local u = newproxy(true) getmetatable(u).__len = function(o) return 42 end assert(#u == 42) @@ -37,7 +35,8 @@ do assert(x == 4200) end -debug.setmetatable(0, mt) -assert(#1 == 42) -debug.setmetatable(0, nil) - +do --- number + debug.setmetatable(0, mt) + assert(#1 == 42) + debug.setmetatable(0, nil) +end diff --git a/test/lang/meta/newindex.lua b/test/lang/meta/newindex.lua new file mode 100644 index 0000000000..6c46b8cbdc --- /dev/null +++ b/test/lang/meta/newindex.lua @@ -0,0 +1,69 @@ +do --- table 1 + local t=setmetatable({}, {__newindex=function(t,k,v) + rawset(t, k, 100-v) + end}) + + for i=1,100 do t[i] = i end + for i=1,100 do assert(t[i] == 100-i) end + + for i=1,100 do t[i] = i end + for i=1,100 do assert(t[i] == i) end + + for i=1,100 do t[i] = nil end + for i=1,100 do t[i] = i end + for i=1,100 do assert(t[i] == 100-i) end +end + +do --- jit gaining href + local count = 0 + local t = setmetatable({ foo = nil }, + { __newindex=function() count = count + 1 end }) + for j=1,2 do + for i=1,100 do t.foo = 1 end + rawset(t, "foo", 1) + end + assert(count == 100) +end + +do --- jit gaining aref + local count = 0 + local t = setmetatable({ nil }, + { __newindex=function() count = count + 1 end }) + for j=1,2 do + for i=1,100 do t[1] = 1 end + rawset(t, 1, 1) + end + assert(count == 100) +end + +do --- resize + local grandparent = {} + grandparent.__newindex = function(s,_,_) tostring(s) end + + local parent = {} + parent.__newindex = parent + parent.bar = 1 + setmetatable(parent, grandparent) + + local child = setmetatable({}, parent) + child.foo = _ +end + +do --- str + local t=setmetatable({}, {__newindex=function(t,k,v) + assert(v == "foo"..k) + rawset(t, k, "bar"..k) + end}) + + for i=1,100 do t[i]="foo"..i end + for i=1,100 do assert(t[i] == "bar"..i) end + + for i=1,100 do t[i]="baz"..i end + for i=1,100 do assert(t[i] == "baz"..i) end + + local t=setmetatable({foo=1,bar=1,baz=1},{}) + t.baz=nil + t.baz=2 + t.baz=nil + t.baz=2 +end diff --git a/test/misc/meta_nomm.lua b/test/lang/meta/nomm.lua similarity index 96% rename from test/misc/meta_nomm.lua rename to test/lang/meta/nomm.lua index 457d0ee288..2b3db86fd1 100644 --- a/test/misc/meta_nomm.lua +++ b/test/lang/meta/nomm.lua @@ -1,5 +1,5 @@ -do +do --- untitled local keys = {} for i=1,100 do keys[i] = "foo" end keys[95] = "__index" diff --git a/test/misc/meta_getset.lua b/test/lib/base/getsetmetatable.lua similarity index 89% rename from test/misc/meta_getset.lua rename to test/lib/base/getsetmetatable.lua index 3f5c1da19c..7d57343ec5 100644 --- a/test/misc/meta_getset.lua +++ b/test/lib/base/getsetmetatable.lua @@ -1,17 +1,17 @@ -do +do --- get __metatable local t = setmetatable({}, { __metatable = "foo" }) for i=1,100 do assert(getmetatable(t) == "foo") end end -do +do --- jit smoke local mt = {} local t = setmetatable({}, mt) for i=1,100 do assert(getmetatable(t) == mt) end for i=1,100 do assert(setmetatable(t, mt) == t) end end -do +do --- jit assorted local mt = {} local t = {} for i=1,200 do t[i] = setmetatable({}, mt) end @@ -26,9 +26,8 @@ do for i=1,200 do assert(getmetatable(t[i]) == nil or i == 150) end end -do +do --- jit get primitive metatable local x = true for i=1,100 do x = getmetatable(i) end assert(x == nil) end - diff --git a/test/lib/base/index b/test/lib/base/index index 16adea05e2..c9ddd19535 100644 --- a/test/lib/base/index +++ b/test/lib/base/index @@ -1,5 +1,7 @@ assert.lua error.lua getfenv.lua +lua<5.2 +getsetmetatable.lua +pairs.lua select.lua xpcall_jit.lua +compat5.2 diff --git a/test/misc/meta_pairs.lua b/test/lib/base/pairs.lua similarity index 94% rename from test/misc/meta_pairs.lua rename to test/lib/base/pairs.lua index 802a56ff6d..ac0b9de367 100644 --- a/test/misc/meta_pairs.lua +++ b/test/lib/base/pairs.lua @@ -1,5 +1,5 @@ -do +do --- nometatable local t = {} for i=1,10 do t[i] = i+100 end local a, b = 0, 0 @@ -12,7 +12,7 @@ do assert(b == 105500) end -do +do --- empty metatable local t = setmetatable({}, {}) for i=1,10 do t[i] = i+100 end local a, b = 0, 0 @@ -25,7 +25,7 @@ do assert(b == 105500) end -if os.getenv("LUA52") then +do --- metamethods +compat5.2 local function iter(t, i) i = i + 1 if t[i] then return i, t[i]+2 end diff --git a/test/misc/meta_arith.lua b/test/misc/meta_arith.lua deleted file mode 100644 index f9028fcd0a..0000000000 --- a/test/misc/meta_arith.lua +++ /dev/null @@ -1,103 +0,0 @@ - -local function create(arith, v1, v2) - local meta = { - __add=function(a,b) return arith("add", a, b) end, - __sub=function(a,b) return arith("sub", a, b) end, - __mul=function(a,b) return arith("mul", a, b) end, - __div=function(a,b) return arith("div", a, b) end, - __mod=function(a,b) return arith("mod", a, b) end, - __pow=function(a,b) return arith("pow", a, b) end, - __unm=function(a,b) return arith("unm", a, b) end, - } - return setmetatable({v1}, meta), setmetatable({v2}, meta) -end - -local a, b = create(function(op,a,b) return op end) -assert(a+b == "add") -assert(a-b == "sub") -assert(a*b == "mul") -assert(a/b == "div") -assert(a%b == "mod") -assert(a^b == "pow") -assert(-a == "unm") - -local a, b = create(function(op,a,b) return a[1] end, "foo", 42) -assert(a+b == "foo") -assert(a-b == "foo") -assert(a*b == "foo") -assert(a/b == "foo") -assert(a%b == "foo") -assert(a^b == "foo") -assert(-a == "foo") - -local a, b = create(function(op,a,b) return b[1] end, 42, "foo") -assert(a+b == "foo") -assert(a-b == "foo") -assert(a*b == "foo") -assert(a/b == "foo") -assert(a%b == "foo") -assert(a^b == "foo") -assert(-a == 42) - - -local a, b = create(function(op,a,b) return a[1]+b end, 39), 3 -assert(a+b == 42) -assert(a-b == 42) -assert(a*b == 42) -assert(a/b == 42) -assert(a%b == 42) -assert(a^b == 42) - -local a, b = 39, create(function(op,a,b) return a+b[1] end, 3) -assert(a+b == 42) -assert(a-b == 42) -assert(a*b == 42) -assert(a/b == 42) -assert(a%b == 42) -assert(a^b == 42) - - -local a, b = "39", 3 -assert(a+b == 42) -assert(a-b == 36) -assert(a*b == 117) -assert(a/b == 13) -assert(a%b == 0) -assert(a^b == 59319) -assert(-a == -39) - -local a, b = 39, "3" -assert(a+b == 42) -assert(a-b == 36) -assert(a*b == 117) -assert(a/b == 13) -assert(a%b == 0) -assert(a^b == 59319) -assert(-a == -39) - -local a, b = "39", "3" -assert(a+b == 42) -assert(a-b == 36) -assert(a*b == 117) -assert(a/b == 13) -assert(a%b == 0) -assert(a^b == 59319) -assert(-a == -39) - - -local a = "39" -assert(a+3 == 42) -assert(a-3 == 36) -assert(a*3 == 117) -assert(a/3 == 13) -assert(a%3 == 0) -assert(a^3 == 59319) - -local b = "3" -assert(39+b == 42) -assert(39-b == 36) -assert(39*b == 117) -assert(39/b == 13) -assert(39%b == 0) -assert(39^b == 59319) - diff --git a/test/misc/meta_comp.lua b/test/misc/meta_comp.lua deleted file mode 100644 index e265bef2c5..0000000000 --- a/test/misc/meta_comp.lua +++ /dev/null @@ -1,151 +0,0 @@ - -local function create(comp, v1, v2) - local meta = { - __lt=function(a,b) return comp("lt", a, b) end, - __le=function(a,b) return comp("le", a, b) end, - } - return setmetatable({v1}, meta), setmetatable({v2}, meta) -end - -local xop -local a, b = create(function(op,a,b) xop = op; return "" end) -assert(ab == true and xop == "lt"); xop = nil -assert(a<=b == true and xop == "le"); xop = nil -assert(a>=b == true and xop == "le"); xop = nil - -assert(not (ab) == false and xop == "lt"); xop = nil -assert(not (a<=b) == false and xop == "le"); xop = nil -assert(not (a>=b) == false and xop == "le"); xop = nil - --- __le metamethod is optional and substituted with arg+res inverted __lt. -local f = getmetatable(a).__le -getmetatable(a).__le = nil -assert(ab == true and xop == "lt"); xop = nil -assert(a<=b == false and xop == "lt"); xop = nil -assert(a>=b == false and xop == "lt"); xop = nil - -assert(not (ab) == false and xop == "lt"); xop = nil -assert(not (a<=b) == true and xop == "lt"); xop = nil -assert(not (a>=b) == true and xop == "lt"); xop = nil -getmetatable(a).__le = f - --- Different metatable, but same metamethod works, too. -setmetatable(b, { __lt = getmetatable(b).__lt, __le = getmetatable(b).__le }) -assert(ab == true and xop == "lt"); xop = nil -assert(a<=b == true and xop == "le"); xop = nil -assert(a>=b == true and xop == "le"); xop = nil - -assert(not (ab) == false and xop == "lt"); xop = nil -assert(not (a<=b) == false and xop == "le"); xop = nil -assert(not (a>=b) == false and xop == "le"); xop = nil - -local a, b = create(function(op,a,b) - if op == "lt" then return a[1]b == false) -assert(a<=b == true) -assert(a>=b == false) - -assert(not (ab) == true) -assert(not (a<=b) == false) -assert(not (a>=b) == true) - -b[1] = 1 -assert(ab == false) -assert(a<=b == true) -assert(a>=b == true) - -assert(not (ab) == true) -assert(not (a<=b) == false) -assert(not (a>=b) == false) - -a[1] = 2 -assert(ab == true) -assert(a<=b == false) -assert(a>=b == true) - -assert(not (ab) == false) -assert(not (a<=b) == true) -assert(not (a>=b) == false) - --- __le metamethod is optional and substituted with arg+res inverted __lt. -getmetatable(a).__le = nil -a[1] = 1 -b[1] = 2 -assert(ab == false) -assert(a<=b == true) -assert(a>=b == false) - -assert(not (ab) == true) -assert(not (a<=b) == false) -assert(not (a>=b) == true) - -b[1] = 1 -assert(ab == false) -assert(a<=b == true) -assert(a>=b == true) - -assert(not (ab) == true) -assert(not (a<=b) == false) -assert(not (a>=b) == false) - -a[1] = 2 -assert(ab == true) -assert(a<=b == false) -assert(a>=b == true) - -assert(not (ab) == false) -assert(not (a<=b) == true) -assert(not (a>=b) == false) - --- String comparisons: -local function str_cmp(a, b, lt, gt, le, ge) - assert(ab == gt) - assert(a<=b == le) - assert(a>=b == ge) - assert((not (ab)) == (not gt)) - assert((not (a<=b)) == (not le)) - assert((not (a>=b)) == (not ge)) -end - -local function str_lo(a, b) - str_cmp(a, b, true, false, true, false) -end - -local function str_eq(a, b) - str_cmp(a, b, false, false, true, true) -end - -local function str_hi(a, b) - str_cmp(a, b, false, true, false, true) -end - -str_lo("a", "b") -str_eq("a", "a") -str_hi("b", "a") - -str_lo("a", "aa") -str_hi("aa", "a") - -str_lo("a", "a\0") -str_hi("a\0", "a") - diff --git a/test/misc/meta_comp_jit.lua b/test/misc/meta_comp_jit.lua deleted file mode 100644 index 57f711283e..0000000000 --- a/test/misc/meta_comp_jit.lua +++ /dev/null @@ -1,104 +0,0 @@ - -local lt, le = false, false -local t, u = {}, {} -local x, ax, bx -local function ck(xx, a, b) - if x ~= xx then error("bad x", 2) end - if ax ~= a then error("bad ax", 2) end - if bx ~= b then error("bad bx", 2) end -end -local mt = { - __lt = function(a, b) ax=a; bx=b; return lt end, - __le = function(a, b) ax=a; bx=b; return le end, -} -t = setmetatable(t, mt) -u = setmetatable(u, mt) -lt, le = false, false -x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(2, u, t) -lt, le = false, true -x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(1, u, t) -lt, le = true, false -x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(2, u, t) -lt, le = true, true -x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(1, u, t) -mt.__le = nil -lt = false -x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(1, t, u) -lt = true -x = 0; for i=1,100 do x = t < u and 2 or 1 end ck(2, t, u) -x = 0; for i=1,100 do x = t <= u and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = t > u and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = t >= u and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = not (t < u) and 2 or 1 end ck(1, t, u) -x = 0; for i=1,100 do x = not (t <= u) and 2 or 1 end ck(2, u, t) -x = 0; for i=1,100 do x = not (t > u) and 2 or 1 end ck(1, u, t) -x = 0; for i=1,100 do x = not (t >= u) and 2 or 1 end ck(2, t, u) - --- Mixed metamethods for ordered comparisons. -do - local mt1 = { __lt = function(a, b) return a[1] < b[1] end } - local mt2 = { __lt = function(a, b) return a[1] < b[1] end } - local t1 = setmetatable({1}, mt1) - local t2 = setmetatable({2}, mt2) - do - local x - for i=1,100 do x = t1 <= t1 end - assert(x == true) - end - local ok, ret = pcall(function() - local x - for i=1,100 do x = t1 < t2 end - return x - end) - if os.getenv("LUA52") then - assert(ok and ret == true) - else - assert(not ok) - end - local ok, ret = pcall(function() - local x - for i=1,100 do x = t1 <= t2 end - return x - end) - if os.getenv("LUA52") then - assert(ok and ret == true) - else - assert(not ok) - end -end - diff --git a/test/misc/meta_eq.lua b/test/misc/meta_eq.lua deleted file mode 100644 index 786f480423..0000000000 --- a/test/misc/meta_eq.lua +++ /dev/null @@ -1,66 +0,0 @@ - -local function create(equal, v1, v2) - local meta = { __eq = equal } - return setmetatable({v1}, meta), setmetatable({v2}, meta) -end - -local xop -local a, b = create(function(a,b) xop = "eq" return "" end) -assert(a==b == true and xop == "eq"); xop = nil -assert(a~=b == false and xop == "eq"); xop = nil - --- Different metatable, but same metamethod works, too. -setmetatable(b, { __eq = getmetatable(b).__eq }) -assert(a==b == true and xop == "eq"); xop = nil -assert(a~=b == false and xop == "eq"); xop = nil - -local a, b = create(function(a,b) return a[1] == b[1] end, 1, 2) -assert(a==b == false) -assert(a~=b == true) - -b[1] = 1 -assert(a==b == true) -assert(a~=b == false) - -a[1] = 2 -assert(a==b == false) -assert(a~=b == true) - - -local function obj_eq(a, b) - assert(a==b == true) - assert(a~=b == false) -end - -local function obj_ne(a, b) - assert(a==b == false) - assert(a~=b == true) -end - -obj_eq(nil, nil) -obj_ne(nil, false) -obj_ne(nil, true) - -obj_ne(false, nil) -obj_eq(false, false) -obj_ne(false, true) - -obj_ne(true, nil) -obj_ne(true, false) -obj_eq(true, true) - -obj_eq(1, 1) -obj_ne(1, 2) -obj_ne(2, 1) - -obj_eq("a", "a") -obj_ne("a", "b") -obj_ne("a", 1) -obj_ne(1, "a") - -local t, t2 = {}, {} -obj_eq(t, t) -obj_ne(t, t2) -obj_ne(t, 1) -obj_ne(t, "") - diff --git a/test/misc/meta_framegap.lua b/test/misc/meta_framegap.lua deleted file mode 100644 index 4f2f719ae2..0000000000 --- a/test/misc/meta_framegap.lua +++ /dev/null @@ -1,23 +0,0 @@ - -local t = setmetatable({}, { __add = function(a, b) - if b > 200 then - for j=1,10 do end - return b+3 - elseif b > 100 then - return b+2 - else - return b+1 - end -end }) - -local function f(t, i) - do return t+i end - -- Force large frame with unassigned slots below mm. - do local a,b,c,d,e,f,g,h,i,j,k end -end - -local x = 0 -for i=1,300 do - x = f(t, i) -end -assert(x == 303) diff --git a/test/misc/meta_tget.lua b/test/misc/meta_tget.lua deleted file mode 100644 index 7c051009ec..0000000000 --- a/test/misc/meta_tget.lua +++ /dev/null @@ -1,25 +0,0 @@ - -local t=setmetatable({}, {__index=function(t,k) - return 100-k -end}) - -for i=1,100 do assert(t[i] == 100-i) end - -for i=1,100 do t[i] = i end -for i=1,100 do assert(t[i] == i) end - -for i=1,100 do t[i] = nil end -for i=1,100 do assert(t[i] == 100-i) end - - -local x -local t2=setmetatable({}, {__index=function(t,k) - x = k -end}) - -assert(t2[1] == nil) -assert(x == 1) - -assert(t2.foo == nil) -assert(x == "foo") - diff --git a/test/misc/meta_tget_nontab.lua b/test/misc/meta_tget_nontab.lua deleted file mode 100644 index 3c40a514de..0000000000 --- a/test/misc/meta_tget_nontab.lua +++ /dev/null @@ -1,33 +0,0 @@ - -do - local u = newproxy(true) - getmetatable(u).__index = { foo = u, bar = 42 } - - local x = 0 - for i=1,100 do - x = x + u.bar - u = u.foo - end - assert(x == 4200) - - x = 0 - for i=1,100 do - u = u.foo - x = x + u.bar - end - assert(x == 4200) -end - -do - local s = "foo" - string.s = s - local x = 0 - local t = {} - for i=1,100 do - x = x + s:len() - s = s.s - t[s] = t -- Hash store with same type prevents hoisting - end - assert(x == 300) -end - diff --git a/test/misc/meta_tset.lua b/test/misc/meta_tset.lua deleted file mode 100644 index f844e1b567..0000000000 --- a/test/misc/meta_tset.lua +++ /dev/null @@ -1,15 +0,0 @@ - -local t=setmetatable({}, {__newindex=function(t,k,v) - rawset(t, k, 100-v) -end}) - -for i=1,100 do t[i] = i end -for i=1,100 do assert(t[i] == 100-i) end - -for i=1,100 do t[i] = i end -for i=1,100 do assert(t[i] == i) end - -for i=1,100 do t[i] = nil end -for i=1,100 do t[i] = i end -for i=1,100 do assert(t[i] == 100-i) end - diff --git a/test/misc/meta_tset_nilget.lua b/test/misc/meta_tset_nilget.lua deleted file mode 100644 index 1fdebab383..0000000000 --- a/test/misc/meta_tset_nilget.lua +++ /dev/null @@ -1,23 +0,0 @@ - -do - local count = 0 - local t = setmetatable({ foo = nil }, - { __newindex=function() count = count + 1 end }) - for j=1,2 do - for i=1,100 do t.foo = 1 end - rawset(t, "foo", 1) - end - assert(count == 100) -end - -do - local count = 0 - local t = setmetatable({ nil }, - { __newindex=function() count = count + 1 end }) - for j=1,2 do - for i=1,100 do t[1] = 1 end - rawset(t, 1, 1) - end - assert(count == 100) -end - diff --git a/test/misc/meta_tset_resize.lua b/test/misc/meta_tset_resize.lua deleted file mode 100644 index a58dac1136..0000000000 --- a/test/misc/meta_tset_resize.lua +++ /dev/null @@ -1,10 +0,0 @@ -local grandparent = {} -grandparent.__newindex = function(s,_,_) tostring(s) end - -local parent = {} -parent.__newindex = parent -parent.bar = 1 -setmetatable(parent, grandparent) - -local child = setmetatable({}, parent) -child.foo = _ diff --git a/test/misc/meta_tset_str.lua b/test/misc/meta_tset_str.lua deleted file mode 100644 index b72be3a8e5..0000000000 --- a/test/misc/meta_tset_str.lua +++ /dev/null @@ -1,18 +0,0 @@ - -local t=setmetatable({}, {__newindex=function(t,k,v) - assert(v == "foo"..k) - rawset(t, k, "bar"..k) -end}) - -for i=1,100 do t[i]="foo"..i end -for i=1,100 do assert(t[i] == "bar"..i) end - -for i=1,100 do t[i]="baz"..i end -for i=1,100 do assert(t[i] == "baz"..i) end - -local t=setmetatable({foo=1,bar=1,baz=1},{}) -t.baz=nil -t.baz=2 -t.baz=nil -t.baz=2 -