2011-08-10 19:45:15 +00:00
|
|
|
require 'middleclass'
|
|
|
|
|
2011-08-12 08:33:58 +00:00
|
|
|
context('A Class', function()
|
2011-08-10 19:45:15 +00:00
|
|
|
|
2011-08-13 01:12:21 +00:00
|
|
|
context('Default stuff', function()
|
|
|
|
|
|
|
|
local AClass
|
|
|
|
|
|
|
|
before(function()
|
|
|
|
AClass = class('AClass')
|
2011-08-10 19:45:15 +00:00
|
|
|
end)
|
|
|
|
|
2011-08-13 01:12:21 +00:00
|
|
|
context('name', function()
|
|
|
|
test('is correctly set', function()
|
|
|
|
assert_equal(AClass.name, 'AClass')
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
context('tostring', function()
|
|
|
|
test('returns "class *name*"', function()
|
|
|
|
assert_equal(tostring(AClass), 'class AClass')
|
|
|
|
end)
|
2011-08-10 19:45:15 +00:00
|
|
|
end)
|
|
|
|
|
2011-08-13 01:12:21 +00:00
|
|
|
context('()', function()
|
|
|
|
test('returns an object, like Class:new()', function()
|
|
|
|
local obj = AClass()
|
|
|
|
assert_equal(obj.class, AClass)
|
|
|
|
end)
|
2011-08-11 09:36:23 +00:00
|
|
|
end)
|
2011-08-13 01:12:21 +00:00
|
|
|
|
2011-08-11 09:36:23 +00:00
|
|
|
end)
|
|
|
|
|
2011-08-10 19:45:15 +00:00
|
|
|
context('attributes', function()
|
|
|
|
|
|
|
|
local A, B
|
|
|
|
|
|
|
|
before(function()
|
|
|
|
A = class('A')
|
|
|
|
A.static.foo = 'foo'
|
|
|
|
|
|
|
|
B = class('B', A)
|
|
|
|
end)
|
|
|
|
|
2011-08-12 08:33:58 +00:00
|
|
|
test('are available after being initialized', function()
|
2011-08-10 19:45:15 +00:00
|
|
|
assert_equal(A.foo, 'foo')
|
|
|
|
end)
|
|
|
|
|
2011-08-12 08:33:58 +00:00
|
|
|
test('are available for subclasses', function()
|
2011-08-10 19:45:15 +00:00
|
|
|
assert_equal(B.foo, 'foo')
|
|
|
|
end)
|
|
|
|
|
2011-08-12 08:33:58 +00:00
|
|
|
test('are overridable by subclasses, without affecting the superclasses', function()
|
|
|
|
B.static.foo = 'chunky bacon'
|
2011-08-10 19:45:15 +00:00
|
|
|
assert_equal(B.foo, 'chunky bacon')
|
|
|
|
assert_equal(A.foo, 'foo')
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
context('methods', function()
|
|
|
|
|
|
|
|
local A, B
|
|
|
|
|
|
|
|
before(function()
|
|
|
|
A = class('A')
|
2011-08-12 08:33:58 +00:00
|
|
|
function A.static:foo() return 'foo' end
|
2011-08-10 19:45:15 +00:00
|
|
|
|
|
|
|
B = class('B', A)
|
|
|
|
end)
|
|
|
|
|
2011-08-12 08:33:58 +00:00
|
|
|
test('are available after being initialized', function()
|
2011-08-10 19:45:15 +00:00
|
|
|
assert_equal(A:foo(), 'foo')
|
|
|
|
end)
|
|
|
|
|
2011-08-12 08:33:58 +00:00
|
|
|
test('are available for subclasses', function()
|
2011-08-10 19:45:15 +00:00
|
|
|
assert_equal(B:foo(), 'foo')
|
|
|
|
end)
|
|
|
|
|
2011-08-12 08:33:58 +00:00
|
|
|
test('are overridable by subclasses, without affecting the superclasses', function()
|
|
|
|
function B.static:foo() return 'chunky bacon' end
|
2011-08-10 19:45:15 +00:00
|
|
|
assert_equal(B:foo(), 'chunky bacon')
|
|
|
|
assert_equal(A:foo(), 'foo')
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
end)
|