2010-07-27 23:32:10 +00:00
|
|
|
require('MiddleClass')
|
|
|
|
|
2010-07-22 22:56:40 +00:00
|
|
|
context( 'subclassOf', function()
|
|
|
|
|
|
|
|
context( 'Primitives', function()
|
|
|
|
local primitives = {nil, 1, 'hello', {}, function() end}
|
|
|
|
|
|
|
|
for _,primitive in pairs(primitives) do
|
|
|
|
local theType = type(primitive)
|
|
|
|
context('A ' .. theType, function()
|
|
|
|
|
|
|
|
local f1 = function() return subclassOf(Object, primitive) end
|
|
|
|
local f2 = function() return subclassOf(primitive, o) end
|
|
|
|
local f3 = function() return subclassOf(primitive, primitive) end
|
|
|
|
|
2010-07-28 23:18:11 +00:00
|
|
|
context('should not throw errors', function()
|
2010-07-22 22:56:40 +00:00
|
|
|
test('subclassOf(Object, '.. theType ..')', function()
|
|
|
|
assert_not_error(f1)
|
|
|
|
end)
|
|
|
|
test('subclassOf(' .. theType .. ', Object:new())', function()
|
|
|
|
assert_not_error(f2)
|
|
|
|
end)
|
|
|
|
test('subclassOf(' .. theType .. ',' .. theType ..')', function()
|
|
|
|
assert_not_error(f3)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2010-07-28 23:18:11 +00:00
|
|
|
test('should make subclassOf return false', function()
|
2010-07-22 22:56:40 +00:00
|
|
|
assert_false(f1())
|
|
|
|
assert_false(f2())
|
|
|
|
assert_false(f3())
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
end -- for
|
|
|
|
end)
|
|
|
|
|
2010-07-28 23:18:11 +00:00
|
|
|
context( 'Any class (except Object)', function()
|
2010-07-22 22:56:40 +00:00
|
|
|
local Class1 = class('Class1')
|
|
|
|
local Class2 = class('Class2', Class1)
|
|
|
|
local Class3 = class('Class3', Class2)
|
|
|
|
local UnrelatedClass = class('Unrelated')
|
|
|
|
|
2010-07-28 23:18:11 +00:00
|
|
|
test('should be subclassOf(Object)', function()
|
2010-07-22 22:56:40 +00:00
|
|
|
assert_true(subclassOf(Object, Class1))
|
|
|
|
assert_true(subclassOf(Object, Class2))
|
|
|
|
assert_true(subclassOf(Object, Class3))
|
|
|
|
end)
|
|
|
|
|
2010-07-28 23:18:11 +00:00
|
|
|
test('should be subclassOf its direct superclass', function()
|
2010-07-22 22:56:40 +00:00
|
|
|
assert_true(subclassOf(Class1, Class2))
|
|
|
|
assert_true(subclassOf(Class2, Class3))
|
|
|
|
end)
|
|
|
|
|
2010-07-28 23:18:11 +00:00
|
|
|
test('should be subclassOf its ancestors', function()
|
2010-07-22 22:56:40 +00:00
|
|
|
assert_true(subclassOf(Class1, Class3))
|
|
|
|
end)
|
|
|
|
|
2010-07-28 23:18:11 +00:00
|
|
|
test('should not be an subclassOf its class\' subclasses', function()
|
2010-07-22 22:56:40 +00:00
|
|
|
assert_false(subclassOf(Class2, Class1))
|
|
|
|
assert_false(subclassOf(Class3, Class1))
|
|
|
|
assert_false(subclassOf(Class3, Class2))
|
|
|
|
end)
|
|
|
|
|
2010-07-28 23:18:11 +00:00
|
|
|
test('should not be an subclassOf an unrelated class', function()
|
2010-07-22 22:56:40 +00:00
|
|
|
assert_false(subclassOf(UnrelatedClass, Class1))
|
|
|
|
assert_false(subclassOf(UnrelatedClass, Class2))
|
|
|
|
assert_false(subclassOf(UnrelatedClass, Class3))
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|