Add tests for __mode

This commit is contained in:
mpeterv 2015-11-19 14:10:38 +03:00
parent b0b655d1c0
commit b66ba54ccb

View File

@ -41,6 +41,7 @@ describe('Metamethods', function()
if type(a)=="number" then return b.class:new(a*b.x, a*b.y, a*b.z) end
end
Vector.__metatable = "metatable of a vector"
Vector.__mode = "k"
a = Vector:new(1,2,3)
b = Vector:new(2,4,6)
@ -94,6 +95,12 @@ describe('Metamethods', function()
assert.equal("metatable of a vector", getmetatable(a))
end)
it('implements __mode', function()
a[{}] = true
collectgarbage()
for k in pairs(a) do assert.not_table(k) end
end)
--[[
it('implements __index', function()
assert.equal(b[1], 3)
@ -158,6 +165,12 @@ describe('Metamethods', function()
assert.equal("metatable of a vector", getmetatable(c))
end)
it('implements __mode', function()
c[{}] = true
collectgarbage()
for k in pairs(c) do assert.not_table(k) end
end)
describe('Updates', function()
it('overrides __add', function()
Vector2.__add = function(a, b) return Vector.__add(a, b)/2 end