fixed test with Object()

This commit is contained in:
Enrique García Cota 2011-08-11 11:36:23 +02:00
parent 40e14838a2
commit 90bef60d86
3 changed files with 11 additions and 14 deletions

View File

@ -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

View File

@ -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()

View File

@ -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