mirror of
https://github.com/kikito/middleclass.git
synced 2024-12-11 19:44:24 +00:00
skip 5.2 tests on 5.1 mode
This commit is contained in:
parent
ff1fee2a9c
commit
b7b1b47980
@ -1,6 +1,10 @@
|
||||
local class = require 'middleclass'
|
||||
local Object = class.Object
|
||||
|
||||
local function is_lua_5_2_compatible()
|
||||
return type(rawlen) == 'function'
|
||||
end
|
||||
|
||||
describe('Metamethods', function()
|
||||
|
||||
describe('Custom Metamethods', function()
|
||||
@ -56,28 +60,45 @@ describe('Metamethods', function()
|
||||
__concat = { a..b, 28 },
|
||||
__call = { a(), math.sqrt(14) },
|
||||
__pow = { a^b, Vector(0,0,0) },
|
||||
__mul = { 4*a, Vector(4,8,12) },
|
||||
__len = { #a, 3},
|
||||
__mul = { 4*a, Vector(4,8,12) }
|
||||
--__index = { b[1], 3 }
|
||||
}) do
|
||||
it(metamethod .. ' works as expected', function()
|
||||
describe(metamethod, function()
|
||||
it('works as expected', function()
|
||||
assert.equal(values[1], values[2])
|
||||
end)
|
||||
end)
|
||||
end
|
||||
it('__pairs works as expected',function()
|
||||
|
||||
if is_lua_5_2_compatible() then
|
||||
|
||||
describe('__len', function()
|
||||
it('works as expected', function()
|
||||
assert.equal(#a, 3)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('__pairs', function()
|
||||
it('works as expected',function()
|
||||
local output = {}
|
||||
for k,v in pairs(a) do
|
||||
output[k] = v
|
||||
end
|
||||
assert.are.same(output,{x=1,y=2,z=3})
|
||||
end)
|
||||
it('__ipairs works as expected',function()
|
||||
end)
|
||||
|
||||
describe('__ipairs', function()
|
||||
it('works as expected',function()
|
||||
local output = {}
|
||||
for _,i in ipairs(a) do
|
||||
output[#output+1] = i
|
||||
end
|
||||
assert.are.same(output,{1,2,3})
|
||||
end)
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
describe('Inherited Metamethods', function()
|
||||
local Vector2= class('Vector2', Vector)
|
||||
@ -98,26 +119,43 @@ describe('Metamethods', function()
|
||||
__call = { c(), math.sqrt(14) },
|
||||
__pow = { c^d, Vector(0,0,0) },
|
||||
__mul = { 4*c, Vector(4,8,12) },
|
||||
__len = { #c, 3},
|
||||
}) do
|
||||
it(metamethod .. ' works as expected', function()
|
||||
describe(metamethod, function()
|
||||
it('works as expected', function()
|
||||
assert.equal(values[1], values[2])
|
||||
end)
|
||||
end)
|
||||
end
|
||||
it('__pairs works as expected',function()
|
||||
|
||||
if is_lua_5_2_compatible() then
|
||||
|
||||
describe('__len', function()
|
||||
it('works as expected', function()
|
||||
assert.equal(#c, 3)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('__pairs', function()
|
||||
it('works as expected',function()
|
||||
local output = {}
|
||||
for k,v in pairs(c) do
|
||||
output[k] = v
|
||||
end
|
||||
assert.are.same(output,{x=1,y=2,z=3})
|
||||
end)
|
||||
it('__ipairs works as expected',function()
|
||||
end)
|
||||
|
||||
describe('__ipairs', function()
|
||||
it('works as expected', function()
|
||||
local output = {}
|
||||
for _,i in ipairs(c) do
|
||||
output[#output+1] = i
|
||||
end
|
||||
assert.are.same(output,{1,2,3})
|
||||
end)
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user