From b66ba54ccb563b827e915a5d98de78c236cf3963 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 19 Nov 2015 14:10:38 +0300 Subject: [PATCH] Add tests for __mode --- spec/metamethods_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/metamethods_spec.lua b/spec/metamethods_spec.lua index 234e618..f9a79a9 100644 --- a/spec/metamethods_spec.lua +++ b/spec/metamethods_spec.lua @@ -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