From b0b655d1c0edd7c63905d725f4aadf6d470284bc Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 19 Nov 2015 13:59:19 +0300 Subject: [PATCH] Add tests for __metatable --- spec/metamethods_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/metamethods_spec.lua b/spec/metamethods_spec.lua index 53fc645..234e618 100644 --- a/spec/metamethods_spec.lua +++ b/spec/metamethods_spec.lua @@ -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(a)=="number" then return b.class:new(a*b.x, a*b.y, a*b.z) end end + Vector.__metatable = "metatable of a vector" a = Vector:new(1,2,3) b = Vector:new(2,4,6) @@ -89,6 +90,10 @@ describe('Metamethods', function() assert.equal(4*a, Vector(4,8,12)) end) + it('implements __metatable', function() + assert.equal("metatable of a vector", getmetatable(a)) + end) + --[[ it('implements __index', function() assert.equal(b[1], 3) @@ -149,6 +154,10 @@ describe('Metamethods', function() assert.equal(4*c, Vector2(4,8,12)) end) + it('implements __metatable', function() + assert.equal("metatable of a vector", getmetatable(c)) + end) + describe('Updates', function() it('overrides __add', function() Vector2.__add = function(a, b) return Vector.__add(a, b)/2 end