skip 5.2 tests on 5.1 mode

This commit is contained in:
kikito 2013-12-05 01:15:28 +01:00
parent ff1fee2a9c
commit b7b1b47980

View File

@ -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()
assert.equal(values[1], values[2])
describe(metamethod, function()
it('works as expected', function()
assert.equal(values[1], values[2])
end)
end)
end
it('__pairs 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()
local output = {}
for _,i in ipairs(a) do
output[#output+1] = i
end
assert.are.same(output,{1,2,3})
end)
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)
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()
assert.equal(values[1], values[2])
describe(metamethod, function()
it('works as expected', function()
assert.equal(values[1], values[2])
end)
end)
end
it('__pairs 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()
local output = {}
for _,i in ipairs(c) do
output[#output+1] = i
end
assert.are.same(output,{1,2,3})
end)
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)
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)