mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-08 09:34:22 +00:00
fixed test with Object()
This commit is contained in:
parent
40e14838a2
commit
90bef60d86
@ -66,16 +66,6 @@ end
|
|||||||
|
|
||||||
-- creates a subclass
|
-- creates a subclass
|
||||||
function Object.subclass(klass, name)
|
function Object.subclass(klass, name)
|
||||||
assert(_classes[klass], "Use Class:subclass instead of Class.subclass")
|
|
||||||
assert( type(name)=="string", "You must provide a name(string) for your class")
|
|
||||||
|
|
||||||
local thesubclass = { name = name, super = klass, __classDict = {}, __mixins={} }
|
|
||||||
|
|
||||||
local dict = thesubclass.__classDict -- classDict contains all the [meta]methods of the class
|
|
||||||
dict.__index = dict -- It "points to itself" so instances can use it as a metatable.
|
|
||||||
local superDict = klass.__classDict -- The super' classDict
|
|
||||||
|
|
||||||
setmetatable(dict, superDict) -- when a method isn't found on classDict, 'escalate upwards'.
|
|
||||||
|
|
||||||
setmetatable(thesubclass, {
|
setmetatable(thesubclass, {
|
||||||
__index = dict, -- look for stuff on the dict
|
__index = dict, -- look for stuff on the dict
|
||||||
|
@ -14,14 +14,13 @@ context('Object', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
context('Object()', function()
|
context('()', function()
|
||||||
test('returns an object, like Object:new()', function()
|
test('returns an object, like Object:new()', function()
|
||||||
local obj = Object()
|
local obj = Object()
|
||||||
assert_true(instanceOf(Object))
|
assert_true(instanceOf(Object, obj))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
context('instance creation', function()
|
context('instance creation', function()
|
||||||
|
|
||||||
local MyClass
|
local MyClass
|
||||||
|
@ -16,6 +16,14 @@ context('Class', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
context('()', function()
|
||||||
|
test('returns an object, like Class:new()', function()
|
||||||
|
local TheClass = class('TheClass')
|
||||||
|
local obj = TheClass()
|
||||||
|
assert_true(instanceOf(TheClass, obj))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
context('attributes', function()
|
context('attributes', function()
|
||||||
|
|
||||||
local A, B
|
local A, B
|
||||||
|
Loading…
Reference in New Issue
Block a user