mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-08 09:34:22 +00:00
parent
f9955f9285
commit
ccab332079
@ -119,7 +119,12 @@ local DefaultMixin = {
|
||||
initialize = function(self, ...) end,
|
||||
|
||||
isInstanceOf = function(self, aClass)
|
||||
return type(aClass) == 'table' and (aClass == self.class or self.class:isSubclassOf(aClass))
|
||||
return type(aClass) == 'table'
|
||||
and type(self) == 'table'
|
||||
and (self.class == aClass
|
||||
or type(self.class) == 'table'
|
||||
and type(self.class.isSubclassOf) == 'function'
|
||||
and self.class:isSubclassOf(aClass))
|
||||
end,
|
||||
|
||||
static = {
|
||||
|
@ -125,14 +125,24 @@ describe('Default methods', function()
|
||||
local o = Object:new()
|
||||
local primitives = {nil, 1, 'hello', {}, function() end, Object:new()}
|
||||
|
||||
for _,primitive in pairs(primitives) do
|
||||
local theType = type(primitive)
|
||||
describe('A ' .. theType, function()
|
||||
describe('used as classes', function()
|
||||
for _,primitive in pairs(primitives) do
|
||||
local theType = type(primitive)
|
||||
it('object:isInstanceOf(, '.. theType ..') returns false', function()
|
||||
assert.is_false(o:isInstanceOf(primitive))
|
||||
assert.is_falsy(o:isInstanceOf(primitive))
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
describe('used as instances', function()
|
||||
for _,primitive in pairs(primitives) do
|
||||
local theType = type(primitive)
|
||||
it('Object.isInstanceOf('.. theType ..', Object) returns false without error', function()
|
||||
assert.is_falsy(Object.isInstanceOf(primitive, Object))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
end)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user