mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-25 02:44:20 +00:00
fixed test with Object()
This commit is contained in:
parent
40e14838a2
commit
90bef60d86
@ -66,16 +66,6 @@ end
|
||||
|
||||
-- creates a subclass
|
||||
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, {
|
||||
__index = dict, -- look for stuff on the dict
|
||||
|
@ -13,14 +13,13 @@ context('Object', function()
|
||||
assert_equal(tostring(Object), 'class Object')
|
||||
end)
|
||||
end)
|
||||
|
||||
context('Object()', function()
|
||||
|
||||
context('()', function()
|
||||
test('returns an object, like Object:new()', function()
|
||||
local obj = Object()
|
||||
assert_true(instanceOf(Object))
|
||||
assert_true(instanceOf(Object, obj))
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
context('instance creation', function()
|
||||
|
||||
|
@ -16,6 +16,14 @@ context('Class', function()
|
||||
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()
|
||||
|
||||
local A, B
|
||||
|
Loading…
Reference in New Issue
Block a user