diff options
Diffstat (limited to '')
| -rw-r--r-- | spec/outputs/test/class_expression_spec.lua | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/spec/outputs/test/class_expression_spec.lua b/spec/outputs/test/class_expression_spec.lua new file mode 100644 index 0000000..fd9083b --- /dev/null +++ b/spec/outputs/test/class_expression_spec.lua | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | local _anon_func_0 = function(setmetatable) | ||
| 2 | local _class_0 | ||
| 3 | local _base_0 = { } | ||
| 4 | if _base_0.__index == nil then | ||
| 5 | _base_0.__index = _base_0 | ||
| 6 | end | ||
| 7 | _class_0 = setmetatable({ | ||
| 8 | __init = function(self) | ||
| 9 | self.value = 1 | ||
| 10 | end, | ||
| 11 | __base = _base_0 | ||
| 12 | }, { | ||
| 13 | __index = _base_0, | ||
| 14 | __call = function(cls, ...) | ||
| 15 | local _self_0 = setmetatable({ }, _base_0) | ||
| 16 | cls.__init(_self_0, ...) | ||
| 17 | return _self_0 | ||
| 18 | end | ||
| 19 | }) | ||
| 20 | _base_0.__class = _class_0 | ||
| 21 | return _class_0 | ||
| 22 | end | ||
| 23 | local _anon_func_1 = function(setmetatable) | ||
| 24 | local _class_0 | ||
| 25 | local _base_0 = { } | ||
| 26 | if _base_0.__index == nil then | ||
| 27 | _base_0.__index = _base_0 | ||
| 28 | end | ||
| 29 | _class_0 = setmetatable({ | ||
| 30 | __init = function(self) | ||
| 31 | self.value = 2 | ||
| 32 | end, | ||
| 33 | __base = _base_0 | ||
| 34 | }, { | ||
| 35 | __index = _base_0, | ||
| 36 | __call = function(cls, ...) | ||
| 37 | local _self_0 = setmetatable({ }, _base_0) | ||
| 38 | cls.__init(_self_0, ...) | ||
| 39 | return _self_0 | ||
| 40 | end | ||
| 41 | }) | ||
| 42 | _base_0.__class = _class_0 | ||
| 43 | return _class_0 | ||
| 44 | end | ||
| 45 | return describe("class expression", function() | ||
| 46 | it("should support class expression assignment", function() | ||
| 47 | local MyClass | ||
| 48 | do | ||
| 49 | local _class_0 | ||
| 50 | local _base_0 = { | ||
| 51 | value = 100 | ||
| 52 | } | ||
| 53 | if _base_0.__index == nil then | ||
| 54 | _base_0.__index = _base_0 | ||
| 55 | end | ||
| 56 | _class_0 = setmetatable({ | ||
| 57 | __init = function() end, | ||
| 58 | __base = _base_0, | ||
| 59 | __name = "MyClass" | ||
| 60 | }, { | ||
| 61 | __index = _base_0, | ||
| 62 | __call = function(cls, ...) | ||
| 63 | local _self_0 = setmetatable({ }, _base_0) | ||
| 64 | cls.__init(_self_0, ...) | ||
| 65 | return _self_0 | ||
| 66 | end | ||
| 67 | }) | ||
| 68 | _base_0.__class = _class_0 | ||
| 69 | MyClass = _class_0 | ||
| 70 | end | ||
| 71 | return assert.same(MyClass.value, 100) | ||
| 72 | end) | ||
| 73 | it("should support class expression in table", function() | ||
| 74 | local classes = { | ||
| 75 | Alpha = _anon_func_0(setmetatable), | ||
| 76 | Beta = _anon_func_1(setmetatable) | ||
| 77 | } | ||
| 78 | local a = classes.Alpha() | ||
| 79 | local b = classes.Beta() | ||
| 80 | assert.same(a.value, 1) | ||
| 81 | return assert.same(b.value, 2) | ||
| 82 | end) | ||
| 83 | return it("should work with return", function() | ||
| 84 | local fn | ||
| 85 | fn = function() | ||
| 86 | local _class_0 | ||
| 87 | local _base_0 = { | ||
| 88 | value = 50 | ||
| 89 | } | ||
| 90 | if _base_0.__index == nil then | ||
| 91 | _base_0.__index = _base_0 | ||
| 92 | end | ||
| 93 | _class_0 = setmetatable({ | ||
| 94 | __init = function() end, | ||
| 95 | __base = _base_0 | ||
| 96 | }, { | ||
| 97 | __index = _base_0, | ||
| 98 | __call = function(cls, ...) | ||
| 99 | local _self_0 = setmetatable({ }, _base_0) | ||
| 100 | cls.__init(_self_0, ...) | ||
| 101 | return _self_0 | ||
| 102 | end | ||
| 103 | }) | ||
| 104 | _base_0.__class = _class_0 | ||
| 105 | return _class_0 | ||
| 106 | end | ||
| 107 | local Instance = fn() | ||
| 108 | return assert.same(Instance().value, 50) | ||
| 109 | end) | ||
| 110 | end) | ||
