mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-08 09:34:22 +00:00
Add tests for __mode
This commit is contained in:
parent
b0b655d1c0
commit
b66ba54ccb
@ -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
|
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"
|
Vector.__metatable = "metatable of a vector"
|
||||||
|
Vector.__mode = "k"
|
||||||
|
|
||||||
a = Vector:new(1,2,3)
|
a = Vector:new(1,2,3)
|
||||||
b = Vector:new(2,4,6)
|
b = Vector:new(2,4,6)
|
||||||
@ -94,6 +95,12 @@ describe('Metamethods', function()
|
|||||||
assert.equal("metatable of a vector", getmetatable(a))
|
assert.equal("metatable of a vector", getmetatable(a))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('implements __mode', function()
|
||||||
|
a[{}] = true
|
||||||
|
collectgarbage()
|
||||||
|
for k in pairs(a) do assert.not_table(k) end
|
||||||
|
end)
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
it('implements __index', function()
|
it('implements __index', function()
|
||||||
assert.equal(b[1], 3)
|
assert.equal(b[1], 3)
|
||||||
@ -158,6 +165,12 @@ describe('Metamethods', function()
|
|||||||
assert.equal("metatable of a vector", getmetatable(c))
|
assert.equal("metatable of a vector", getmetatable(c))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('implements __mode', function()
|
||||||
|
c[{}] = true
|
||||||
|
collectgarbage()
|
||||||
|
for k in pairs(c) do assert.not_table(k) end
|
||||||
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user