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 class = require 'middleclass'
local Object = class.Object local Object = class.Object
local function is_lua_5_2_compatible()
return type(rawlen) == 'function'
end
describe('Metamethods', function() describe('Metamethods', function()
describe('Custom Metamethods', function() describe('Custom Metamethods', function()
@ -56,28 +60,45 @@ describe('Metamethods', function()
__concat = { a..b, 28 }, __concat = { a..b, 28 },
__call = { a(), math.sqrt(14) }, __call = { a(), math.sqrt(14) },
__pow = { a^b, Vector(0,0,0) }, __pow = { a^b, Vector(0,0,0) },
__mul = { 4*a, Vector(4,8,12) }, __mul = { 4*a, Vector(4,8,12) }
__len = { #a, 3},
--__index = { b[1], 3 } --__index = { b[1], 3 }
}) do }) do
it(metamethod .. ' works as expected', function() describe(metamethod, function()
assert.equal(values[1], values[2]) it('works as expected', function()
assert.equal(values[1], values[2])
end)
end) end)
end end
it('__pairs works as expected',function()
local output = {} if is_lua_5_2_compatible() then
for k,v in pairs(a) do
output[k] = v describe('__len', function()
end it('works as expected', function()
assert.are.same(output,{x=1,y=2,z=3}) assert.equal(#a, 3)
end) end)
it('__ipairs works as expected',function() end)
local output = {}
for _,i in ipairs(a) do describe('__pairs', function()
output[#output+1] = i it('works as expected',function()
end local output = {}
assert.are.same(output,{1,2,3}) for k,v in pairs(a) do
end) 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() describe('Inherited Metamethods', function()
local Vector2= class('Vector2', Vector) local Vector2= class('Vector2', Vector)
@ -98,26 +119,43 @@ describe('Metamethods', function()
__call = { c(), math.sqrt(14) }, __call = { c(), math.sqrt(14) },
__pow = { c^d, Vector(0,0,0) }, __pow = { c^d, Vector(0,0,0) },
__mul = { 4*c, Vector(4,8,12) }, __mul = { 4*c, Vector(4,8,12) },
__len = { #c, 3},
}) do }) do
it(metamethod .. ' works as expected', function() describe(metamethod, function()
assert.equal(values[1], values[2]) it('works as expected', function()
assert.equal(values[1], values[2])
end)
end) end)
end end
it('__pairs works as expected',function()
local output = {} if is_lua_5_2_compatible() then
for k,v in pairs(c) do
output[k] = v describe('__len', function()
end it('works as expected', function()
assert.are.same(output,{x=1,y=2,z=3}) assert.equal(#c, 3)
end) end)
it('__ipairs works as expected',function() end)
local output = {}
for _,i in ipairs(c) do describe('__pairs', function()
output[#output+1] = i it('works as expected',function()
end local output = {}
assert.are.same(output,{1,2,3}) for k,v in pairs(c) do
end) 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) end)