Skip to content

Commit

Permalink
TMP: messing with testing different syntaxes
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Sep 29, 2020
1 parent e0ec7e9 commit b41e061
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests/test-class-mix.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
_G.___w = false

local class = require("pl.class")
local tablex = require("pl.tablex")

local function subclass_hack (base, model)
return tablex.update(class(base), model)
end

-- print("duck")
_G.___w = "foo"
local foo = class({
-- attr = "original base",
_init = function (self)
print("Init foo class")
self.attr = "foo"
end,
finish = function (self, arg)
print("Finish foo class "..arg.." as "..self.attr.."\n")
end
})

_G.___w = "bar"
local bar = class(foo, nil, {
_init = function (self, arg)
print("Init bar class")
self:super(arg)
self.attr = "bar"
end
})

_G.___w = "baz"
local baz = class(foo)
function baz:_init (arg)
print("Init baz class")
self:super(arg)
end

_G.___w = "qiz"
local qiz = subclass_hack(foo, {
attr = "qiz",
_init = function (self, arg)
print("Init qiz class")
self:super(arg)
end
})

_G.___w = "zar"
local zar = class({
_base = foo,
_init = function (self, arg)
print("Init zar class")
self._base._init(self, arg)
-- self:super(arg)
self.attr = "zar"
end
})

-- Base class works as expected
foo():finish("1st")

-- This does *not* work as expected, it functions as an instance of foo
bar():finish("2nd")

-- This syntax works, its just cumbersome
local c = baz()
c.attr = "baz"
c:finish("3rd")

-- This hack to do what I expected pl.class to do in the bar class
qiz():finish("4th")

-- This gets the job done, but there is no super() function available
zar():finish("5th")

0 comments on commit b41e061

Please sign in to comment.