Add tests for __metatable

This commit is contained in:
mpeterv 2015-11-19 13:59:19 +03:00
parent f331dc4248
commit b0b655d1c0

View File

@ -40,6 +40,7 @@ describe('Metamethods', function()
if type(b)=="number" then return a.class:new(a.x*b, a.y*b, a.z*b) end if type(b)=="number" then return a.class:new(a.x*b, a.y*b, a.z*b) end
if type(a)=="number" then return b.class:new(a*b.x, a*b.y, a*b.z) end if type(a)=="number" then return b.class:new(a*b.x, a*b.y, a*b.z) end
end end
Vector.__metatable = "metatable of a vector"
a = Vector:new(1,2,3) a = Vector:new(1,2,3)
b = Vector:new(2,4,6) b = Vector:new(2,4,6)
@ -89,6 +90,10 @@ describe('Metamethods', function()
assert.equal(4*a, Vector(4,8,12)) assert.equal(4*a, Vector(4,8,12))
end) end)
it('implements __metatable', function()
assert.equal("metatable of a vector", getmetatable(a))
end)
--[[ --[[
it('implements __index', function() it('implements __index', function()
assert.equal(b[1], 3) assert.equal(b[1], 3)
@ -149,6 +154,10 @@ describe('Metamethods', function()
assert.equal(4*c, Vector2(4,8,12)) assert.equal(4*c, Vector2(4,8,12))
end) end)
it('implements __metatable', function()
assert.equal("metatable of a vector", getmetatable(c))
end)
describe('Updates', function() describe('Updates', function()
it('overrides __add', function() it('overrides __add', function()
Vector2.__add = function(a, b) return Vector.__add(a, b)/2 end Vector2.__add = function(a, b) return Vector.__add(a, b)/2 end