diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-05-24 10:06:53 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-05-24 10:06:53 +0800 |
| commit | 30a11b0023ad1bc59662d1ead279ba92f6f57cdc (patch) | |
| tree | 0a871f2eb1819a2689ea931a0a07004be909465c | |
| parent | ac2f4ff4cdd3286ecaf31aec47d9d8aadfa75b0f (diff) | |
| download | yuescript-30a11b0023ad1bc59662d1ead279ba92f6f57cdc.tar.gz yuescript-30a11b0023ad1bc59662d1ead279ba92f6f57cdc.tar.bz2 yuescript-30a11b0023ad1bc59662d1ead279ba92f6f57cdc.zip | |
add favicon and tests.v0.10.23
| -rwxr-xr-x | doc/docs/.vuepress/config.js | 9 | ||||
| -rwxr-xr-x | doc/docs/.vuepress/public/image/favicon/android-chrome-192x192.png | bin | 0 -> 13954 bytes | |||
| -rwxr-xr-x | doc/docs/.vuepress/public/image/favicon/android-chrome-512x512.png | bin | 0 -> 35977 bytes | |||
| -rwxr-xr-x | doc/docs/.vuepress/public/image/favicon/apple-touch-icon.png | bin | 0 -> 12771 bytes | |||
| -rwxr-xr-x | doc/docs/.vuepress/public/image/favicon/favicon-16x16.png | bin | 0 -> 695 bytes | |||
| -rwxr-xr-x | doc/docs/.vuepress/public/image/favicon/favicon-32x32.png | bin | 0 -> 1565 bytes | |||
| -rwxr-xr-x | doc/docs/.vuepress/public/image/favicon/favicon.ico | bin | 0 -> 15406 bytes | |||
| -rwxr-xr-x | doc/docs/doc/README.md | 2 | ||||
| -rw-r--r-- | spec/inputs/test/class_spec.yue | 297 | ||||
| -rw-r--r-- | spec/inputs/test/loops_spec.yue | 9 | ||||
| -rw-r--r-- | spec/outputs/test/class_spec.lua | 1668 | ||||
| -rw-r--r-- | spec/outputs/test/loops_spec.lua | 39 |
12 files changed, 2021 insertions, 3 deletions
diff --git a/doc/docs/.vuepress/config.js b/doc/docs/.vuepress/config.js index b3f7313..c6f8f39 100755 --- a/doc/docs/.vuepress/config.js +++ b/doc/docs/.vuepress/config.js | |||
| @@ -23,11 +23,16 @@ module.exports = { | |||
| 23 | ['meta', { property: 'og:description', content: description }], | 23 | ['meta', { property: 'og:description', content: description }], |
| 24 | // Should probably have a og:url but I'm not sure how to add that without it being the same on all pages | 24 | // Should probably have a og:url but I'm not sure how to add that without it being the same on all pages |
| 25 | ['meta', { property: 'og:type', content: 'website' }], | 25 | ['meta', { property: 'og:type', content: 'website' }], |
| 26 | ['meta', { property: 'og:image', content: 'https://yuescript.org/image/yuescript.png' }], | 26 | ['meta', { property: 'og:image', content: '/image/yuescript.png' }], |
| 27 | ['meta', { property: 'og:image:secure_url', content: 'https://yuescript.org/image/yuescript.png' }], | 27 | ['meta', { property: 'og:image:secure_url', content: '/image/yuescript.png' }], |
| 28 | ['meta', { property: 'og:image:type', content: 'image/png' }], | 28 | ['meta', { property: 'og:image:type', content: 'image/png' }], |
| 29 | ['meta', { property: 'og:image:width', content: '1200' }], | 29 | ['meta', { property: 'og:image:width', content: '1200' }], |
| 30 | ['meta', { property: 'og:image:height', content: '1200' }], | 30 | ['meta', { property: 'og:image:height', content: '1200' }], |
| 31 | ['link', { rel: 'icon', href: '/image/favicon/favicon-16x16.png', sizes: '16x16', type: 'image/png' }], | ||
| 32 | ['link', { rel: 'icon', href: '/image/favicon/favicon-32x32.png', sizes: '32x32', type: 'image/png' }], | ||
| 33 | ['link', { rel: 'apple-touch-icon', href: '/image/favicon/apple-touch-icon-180x180.png', sizes: '180x180', type: 'image/png' }], | ||
| 34 | ['link', { rel: 'android-chrome', href: '/image/favicon/android-chrome-192x192.png', sizes: '192x192', type: 'image/png' }], | ||
| 35 | ['link', { rel: 'android-chrome', href: '/image/favicon/android-chrome-512x512.png', sizes: '512x512', type: 'image/png' }], | ||
| 31 | ['script', {}, `window.global = window;`], | 36 | ['script', {}, `window.global = window;`], |
| 32 | ['script', {}, ` | 37 | ['script', {}, ` |
| 33 | var Module = { | 38 | var Module = { |
diff --git a/doc/docs/.vuepress/public/image/favicon/android-chrome-192x192.png b/doc/docs/.vuepress/public/image/favicon/android-chrome-192x192.png new file mode 100755 index 0000000..08c42cc --- /dev/null +++ b/doc/docs/.vuepress/public/image/favicon/android-chrome-192x192.png | |||
| Binary files differ | |||
diff --git a/doc/docs/.vuepress/public/image/favicon/android-chrome-512x512.png b/doc/docs/.vuepress/public/image/favicon/android-chrome-512x512.png new file mode 100755 index 0000000..557d8af --- /dev/null +++ b/doc/docs/.vuepress/public/image/favicon/android-chrome-512x512.png | |||
| Binary files differ | |||
diff --git a/doc/docs/.vuepress/public/image/favicon/apple-touch-icon.png b/doc/docs/.vuepress/public/image/favicon/apple-touch-icon.png new file mode 100755 index 0000000..5780626 --- /dev/null +++ b/doc/docs/.vuepress/public/image/favicon/apple-touch-icon.png | |||
| Binary files differ | |||
diff --git a/doc/docs/.vuepress/public/image/favicon/favicon-16x16.png b/doc/docs/.vuepress/public/image/favicon/favicon-16x16.png new file mode 100755 index 0000000..f067228 --- /dev/null +++ b/doc/docs/.vuepress/public/image/favicon/favicon-16x16.png | |||
| Binary files differ | |||
diff --git a/doc/docs/.vuepress/public/image/favicon/favicon-32x32.png b/doc/docs/.vuepress/public/image/favicon/favicon-32x32.png new file mode 100755 index 0000000..2865ef5 --- /dev/null +++ b/doc/docs/.vuepress/public/image/favicon/favicon-32x32.png | |||
| Binary files differ | |||
diff --git a/doc/docs/.vuepress/public/image/favicon/favicon.ico b/doc/docs/.vuepress/public/image/favicon/favicon.ico new file mode 100755 index 0000000..2c1360d --- /dev/null +++ b/doc/docs/.vuepress/public/image/favicon/favicon.ico | |||
| Binary files differ | |||
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 1e55c07..5d856bb 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
| @@ -3,7 +3,7 @@ sidebar: auto | |||
| 3 | --- | 3 | --- |
| 4 | 4 | ||
| 5 | # Yuescript | 5 | # Yuescript |
| 6 | <img src="/image/yuescript.svg" width="300" height="300" alt="logo"/> | 6 | <img src="/image/yuescript.svg" width="300px" height="300px" alt="logo"/> |
| 7 | 7 | ||
| 8 | ## Introduction | 8 | ## Introduction |
| 9 | 9 | ||
diff --git a/spec/inputs/test/class_spec.yue b/spec/inputs/test/class_spec.yue new file mode 100644 index 0000000..394c59b --- /dev/null +++ b/spec/inputs/test/class_spec.yue | |||
| @@ -0,0 +1,297 @@ | |||
| 1 | |||
| 2 | describe "class", -> | ||
| 3 | it "should make a class with constructor", -> | ||
| 4 | class Thing | ||
| 5 | new: => | ||
| 6 | @color = "blue" | ||
| 7 | |||
| 8 | instance = Thing! | ||
| 9 | |||
| 10 | assert.same instance, { color: "blue" } | ||
| 11 | |||
| 12 | it "should have instance methods", -> | ||
| 13 | class Thing | ||
| 14 | get_color: => @color | ||
| 15 | |||
| 16 | new: => | ||
| 17 | @color = "blue" | ||
| 18 | |||
| 19 | instance = Thing! | ||
| 20 | assert.same instance\get_color!, "blue" | ||
| 21 | |||
| 22 | it "should have base properies from class", -> | ||
| 23 | class Thing | ||
| 24 | color: "blue" | ||
| 25 | get_color: => @color | ||
| 26 | |||
| 27 | instance = Thing! | ||
| 28 | assert.same instance\get_color!, "blue" | ||
| 29 | assert.same Thing.color, "blue" | ||
| 30 | |||
| 31 | it "should inherit another class", -> | ||
| 32 | class Base | ||
| 33 | get_property: => @[@property] | ||
| 34 | |||
| 35 | new: (@property) => | ||
| 36 | |||
| 37 | class Thing extends Base | ||
| 38 | color: "green" | ||
| 39 | |||
| 40 | instance = Thing "color" | ||
| 41 | assert.same instance\get_property!, "green" | ||
| 42 | |||
| 43 | |||
| 44 | it "should have class properties", -> | ||
| 45 | class Base | ||
| 46 | class Thing extends Base | ||
| 47 | |||
| 48 | instance = Thing! | ||
| 49 | |||
| 50 | assert.same Base.__name, "Base" | ||
| 51 | assert.same Thing.__name, "Thing" | ||
| 52 | assert.is_true Thing.__parent == Base | ||
| 53 | |||
| 54 | assert.is_true instance.__class == Thing | ||
| 55 | |||
| 56 | it "should have name when assigned", -> | ||
| 57 | Thing = class | ||
| 58 | assert.same Thing.__name, "Thing" | ||
| 59 | |||
| 60 | it "should not expose class properties on instance", -> | ||
| 61 | class Thing | ||
| 62 | @height: 10 | ||
| 63 | |||
| 64 | Thing.color = "blue" | ||
| 65 | |||
| 66 | instance = Thing! | ||
| 67 | assert.same instance.color, nil | ||
| 68 | assert.same instance.height, nil | ||
| 69 | |||
| 70 | it "should expose new things added to __base", -> | ||
| 71 | class Thing | ||
| 72 | |||
| 73 | instance = Thing! | ||
| 74 | Thing.__base.color = "green" | ||
| 75 | |||
| 76 | assert.same instance.color, "green" | ||
| 77 | |||
| 78 | it "should call with correct receiver", -> | ||
| 79 | local instance | ||
| 80 | |||
| 81 | class Thing | ||
| 82 | is_class: => assert.is_true @ == Thing | ||
| 83 | is_instance: => assert.is_true @ == instance | ||
| 84 | |||
| 85 | go: => | ||
| 86 | @@is_class! | ||
| 87 | @is_instance! | ||
| 88 | |||
| 89 | instance = Thing! | ||
| 90 | instance\go! | ||
| 91 | |||
| 92 | it "should have class properies take precedence over base properties", -> | ||
| 93 | class Thing | ||
| 94 | @prop: "hello" | ||
| 95 | prop: "world" | ||
| 96 | |||
| 97 | assert.same "hello", Thing.prop | ||
| 98 | |||
| 99 | describe "super", -> | ||
| 100 | it "should call super constructor", -> | ||
| 101 | class Base | ||
| 102 | new: (@property) => | ||
| 103 | |||
| 104 | class Thing extends Base | ||
| 105 | new: (@name) => | ||
| 106 | super "name" | ||
| 107 | |||
| 108 | instance = Thing "the_thing" | ||
| 109 | |||
| 110 | assert.same instance.property, "name" | ||
| 111 | assert.same instance.name, "the_thing" | ||
| 112 | |||
| 113 | it "should call super method", -> | ||
| 114 | class Base | ||
| 115 | _count: 111 | ||
| 116 | counter: => @_count | ||
| 117 | |||
| 118 | class Thing extends Base | ||
| 119 | counter: => "%08d"\format super! | ||
| 120 | |||
| 121 | instance = Thing! | ||
| 122 | assert.same instance\counter!, "00000111" | ||
| 123 | |||
| 124 | it "should call other method from super", -> | ||
| 125 | class Base | ||
| 126 | _count: 111 | ||
| 127 | counter: => | ||
| 128 | @_count | ||
| 129 | |||
| 130 | class Thing extends Base | ||
| 131 | other_method: => super\counter! | ||
| 132 | |||
| 133 | instance = Thing! | ||
| 134 | assert.same instance\other_method!, 111 | ||
| 135 | |||
| 136 | it "should get super class", -> | ||
| 137 | class Base | ||
| 138 | class Thing extends Base | ||
| 139 | get_super: => super | ||
| 140 | |||
| 141 | instance = Thing! | ||
| 142 | assert.is_true instance\get_super! == Base | ||
| 143 | |||
| 144 | it "should get a bound method from super", -> | ||
| 145 | class Base | ||
| 146 | count: 1 | ||
| 147 | get_count: => @count | ||
| 148 | |||
| 149 | class Thing extends Base | ||
| 150 | get_count: => "this is wrong" | ||
| 151 | get_method: => super\get_count | ||
| 152 | |||
| 153 | instance = Thing! | ||
| 154 | assert.same instance\get_method!!, 1 | ||
| 155 | |||
| 156 | it "class properties take precedence in super class over base", -> | ||
| 157 | class Thing | ||
| 158 | @prop: "hello" | ||
| 159 | prop: "world" | ||
| 160 | |||
| 161 | class OtherThing extends Thing | ||
| 162 | |||
| 163 | assert.same "hello", OtherThing.prop | ||
| 164 | |||
| 165 | it "gets value from base in super class", -> | ||
| 166 | class Thing | ||
| 167 | prop: "world" | ||
| 168 | |||
| 169 | class OtherThing extends Thing | ||
| 170 | assert.same "world", OtherThing.prop | ||
| 171 | |||
| 172 | it "should let parent be replaced on class", -> | ||
| 173 | class A | ||
| 174 | @prop: "yeah" | ||
| 175 | cool: => 1234 | ||
| 176 | plain: => "a" | ||
| 177 | |||
| 178 | class B | ||
| 179 | @prop: "okay" | ||
| 180 | cool: => 9999 | ||
| 181 | plain: => "b" | ||
| 182 | |||
| 183 | class Thing extends A | ||
| 184 | cool: => | ||
| 185 | super! + 1 | ||
| 186 | |||
| 187 | get_super: => | ||
| 188 | super | ||
| 189 | |||
| 190 | instance = Thing! | ||
| 191 | |||
| 192 | assert.same "a", instance\plain! | ||
| 193 | assert.same 1235, instance\cool! | ||
| 194 | assert A == instance\get_super!, "expected super to be B" | ||
| 195 | |||
| 196 | Thing.__parent = B | ||
| 197 | setmetatable Thing.__base, B.__base | ||
| 198 | |||
| 199 | assert.same "b", instance\plain! | ||
| 200 | assert.same 10000, instance\cool! | ||
| 201 | assert B == instance\get_super!, "expected super to be B" | ||
| 202 | |||
| 203 | it "should resolve many levels of super", -> | ||
| 204 | class One | ||
| 205 | a: => | ||
| 206 | 1 | ||
| 207 | |||
| 208 | class Two extends One | ||
| 209 | a: => | ||
| 210 | super! + 2 | ||
| 211 | |||
| 212 | class Three extends Two | ||
| 213 | a: => | ||
| 214 | super! + 3 | ||
| 215 | |||
| 216 | i = Three! | ||
| 217 | |||
| 218 | assert.same 6, i\a! | ||
| 219 | |||
| 220 | |||
| 221 | it "should resolve many levels of super with a gap", -> | ||
| 222 | class One | ||
| 223 | a: => | ||
| 224 | 1 | ||
| 225 | |||
| 226 | class Two extends One | ||
| 227 | |||
| 228 | class Three extends Two | ||
| 229 | a: => | ||
| 230 | super! + 3 | ||
| 231 | |||
| 232 | class Four extends Three | ||
| 233 | a: => | ||
| 234 | super! + 4 | ||
| 235 | |||
| 236 | i = Four! | ||
| 237 | |||
| 238 | assert.same 8, i\a! | ||
| 239 | |||
| 240 | |||
| 241 | it "should call correct class/instance super methods", -> | ||
| 242 | class Base | ||
| 243 | doit: => | ||
| 244 | "instance" | ||
| 245 | |||
| 246 | @doit: => | ||
| 247 | "class" | ||
| 248 | |||
| 249 | class One extends Base | ||
| 250 | doit: => super! | ||
| 251 | @doit: => super! | ||
| 252 | |||
| 253 | assert.same "instance", One!\doit! | ||
| 254 | assert.same "class", One\doit! | ||
| 255 | |||
| 256 | |||
| 257 | it "should resolve many levels of super on class methods", -> | ||
| 258 | class One | ||
| 259 | @a: => | ||
| 260 | 1 | ||
| 261 | |||
| 262 | class Two extends One | ||
| 263 | |||
| 264 | class Three extends Two | ||
| 265 | @a: => | ||
| 266 | super! + 3 | ||
| 267 | |||
| 268 | class Four extends Three | ||
| 269 | @a: => | ||
| 270 | super! + 4 | ||
| 271 | |||
| 272 | assert.same 8, Four\a! | ||
| 273 | |||
| 274 | it "super should still work when method wrapped", -> | ||
| 275 | add_some = (opts) -> | ||
| 276 | => opts.amount + opts[1] @ | ||
| 277 | |||
| 278 | class Base | ||
| 279 | value: => 1 | ||
| 280 | |||
| 281 | class Sub extends Base | ||
| 282 | value: add_some { | ||
| 283 | amount: 12 | ||
| 284 | => | ||
| 285 | super! + 100 | ||
| 286 | } | ||
| 287 | |||
| 288 | class OtherSub extends Base | ||
| 289 | value: if true | ||
| 290 | => 5 + super! | ||
| 291 | else | ||
| 292 | => 2 + super! | ||
| 293 | |||
| 294 | assert.same 1 + 100 + 12, Sub!\value! | ||
| 295 | assert.same 6, OtherSub!\value! | ||
| 296 | |||
| 297 | |||
diff --git a/spec/inputs/test/loops_spec.yue b/spec/inputs/test/loops_spec.yue new file mode 100644 index 0000000..68b5f97 --- /dev/null +++ b/spec/inputs/test/loops_spec.yue | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | |||
| 2 | describe "loops", -> | ||
| 3 | it "should continue", -> | ||
| 4 | input = {1,2,3,4,5,6} | ||
| 5 | output = for x in *input | ||
| 6 | continue if x % 2 == 1 | ||
| 7 | x | ||
| 8 | |||
| 9 | assert.same output, { 2,4,6 } | ||
diff --git a/spec/outputs/test/class_spec.lua b/spec/outputs/test/class_spec.lua new file mode 100644 index 0000000..b4062e0 --- /dev/null +++ b/spec/outputs/test/class_spec.lua | |||
| @@ -0,0 +1,1668 @@ | |||
| 1 | return describe("class", function() | ||
| 2 | it("should make a class with constructor", function() | ||
| 3 | local Thing | ||
| 4 | do | ||
| 5 | local _class_0 | ||
| 6 | local _base_0 = { } | ||
| 7 | if _base_0.__index == nil then | ||
| 8 | _base_0.__index = _base_0 | ||
| 9 | end | ||
| 10 | _class_0 = setmetatable({ | ||
| 11 | __init = function(self) | ||
| 12 | self.color = "blue" | ||
| 13 | end, | ||
| 14 | __base = _base_0, | ||
| 15 | __name = "Thing" | ||
| 16 | }, { | ||
| 17 | __index = _base_0, | ||
| 18 | __call = function(cls, ...) | ||
| 19 | local _self_0 = setmetatable({ }, _base_0) | ||
| 20 | cls.__init(_self_0, ...) | ||
| 21 | return _self_0 | ||
| 22 | end | ||
| 23 | }) | ||
| 24 | _base_0.__class = _class_0 | ||
| 25 | Thing = _class_0 | ||
| 26 | end | ||
| 27 | local instance = Thing() | ||
| 28 | return assert.same(instance, { | ||
| 29 | color = "blue" | ||
| 30 | }) | ||
| 31 | end) | ||
| 32 | it("should have instance methods", function() | ||
| 33 | local Thing | ||
| 34 | do | ||
| 35 | local _class_0 | ||
| 36 | local _base_0 = { | ||
| 37 | get_color = function(self) | ||
| 38 | return self.color | ||
| 39 | end | ||
| 40 | } | ||
| 41 | if _base_0.__index == nil then | ||
| 42 | _base_0.__index = _base_0 | ||
| 43 | end | ||
| 44 | _class_0 = setmetatable({ | ||
| 45 | __init = function(self) | ||
| 46 | self.color = "blue" | ||
| 47 | end, | ||
| 48 | __base = _base_0, | ||
| 49 | __name = "Thing" | ||
| 50 | }, { | ||
| 51 | __index = _base_0, | ||
| 52 | __call = function(cls, ...) | ||
| 53 | local _self_0 = setmetatable({ }, _base_0) | ||
| 54 | cls.__init(_self_0, ...) | ||
| 55 | return _self_0 | ||
| 56 | end | ||
| 57 | }) | ||
| 58 | _base_0.__class = _class_0 | ||
| 59 | Thing = _class_0 | ||
| 60 | end | ||
| 61 | local instance = Thing() | ||
| 62 | return assert.same(instance:get_color(), "blue") | ||
| 63 | end) | ||
| 64 | it("should have base properies from class", function() | ||
| 65 | local Thing | ||
| 66 | do | ||
| 67 | local _class_0 | ||
| 68 | local _base_0 = { | ||
| 69 | color = "blue", | ||
| 70 | get_color = function(self) | ||
| 71 | return self.color | ||
| 72 | end | ||
| 73 | } | ||
| 74 | if _base_0.__index == nil then | ||
| 75 | _base_0.__index = _base_0 | ||
| 76 | end | ||
| 77 | _class_0 = setmetatable({ | ||
| 78 | __init = function() end, | ||
| 79 | __base = _base_0, | ||
| 80 | __name = "Thing" | ||
| 81 | }, { | ||
| 82 | __index = _base_0, | ||
| 83 | __call = function(cls, ...) | ||
| 84 | local _self_0 = setmetatable({ }, _base_0) | ||
| 85 | cls.__init(_self_0, ...) | ||
| 86 | return _self_0 | ||
| 87 | end | ||
| 88 | }) | ||
| 89 | _base_0.__class = _class_0 | ||
| 90 | Thing = _class_0 | ||
| 91 | end | ||
| 92 | local instance = Thing() | ||
| 93 | assert.same(instance:get_color(), "blue") | ||
| 94 | return assert.same(Thing.color, "blue") | ||
| 95 | end) | ||
| 96 | it("should inherit another class", function() | ||
| 97 | local Base | ||
| 98 | do | ||
| 99 | local _class_0 | ||
| 100 | local _base_0 = { | ||
| 101 | get_property = function(self) | ||
| 102 | return self[self.property] | ||
| 103 | end | ||
| 104 | } | ||
| 105 | if _base_0.__index == nil then | ||
| 106 | _base_0.__index = _base_0 | ||
| 107 | end | ||
| 108 | _class_0 = setmetatable({ | ||
| 109 | __init = function(self, property) | ||
| 110 | self.property = property | ||
| 111 | end, | ||
| 112 | __base = _base_0, | ||
| 113 | __name = "Base" | ||
| 114 | }, { | ||
| 115 | __index = _base_0, | ||
| 116 | __call = function(cls, ...) | ||
| 117 | local _self_0 = setmetatable({ }, _base_0) | ||
| 118 | cls.__init(_self_0, ...) | ||
| 119 | return _self_0 | ||
| 120 | end | ||
| 121 | }) | ||
| 122 | _base_0.__class = _class_0 | ||
| 123 | Base = _class_0 | ||
| 124 | end | ||
| 125 | local Thing | ||
| 126 | do | ||
| 127 | local _class_0 | ||
| 128 | local _parent_0 = Base | ||
| 129 | local _base_0 = { | ||
| 130 | color = "green" | ||
| 131 | } | ||
| 132 | if _base_0.__index == nil then | ||
| 133 | _base_0.__index = _base_0 | ||
| 134 | end | ||
| 135 | setmetatable(_base_0, _parent_0.__base) | ||
| 136 | _class_0 = setmetatable({ | ||
| 137 | __init = function(self, ...) | ||
| 138 | return _class_0.__parent.__init(self, ...) | ||
| 139 | end, | ||
| 140 | __base = _base_0, | ||
| 141 | __name = "Thing", | ||
| 142 | __parent = _parent_0 | ||
| 143 | }, { | ||
| 144 | __index = function(cls, name) | ||
| 145 | local val = rawget(_base_0, name) | ||
| 146 | if val == nil then | ||
| 147 | local parent = rawget(cls, "__parent") | ||
| 148 | if parent then | ||
| 149 | return parent[name] | ||
| 150 | end | ||
| 151 | else | ||
| 152 | return val | ||
| 153 | end | ||
| 154 | end, | ||
| 155 | __call = function(cls, ...) | ||
| 156 | local _self_0 = setmetatable({ }, _base_0) | ||
| 157 | cls.__init(_self_0, ...) | ||
| 158 | return _self_0 | ||
| 159 | end | ||
| 160 | }) | ||
| 161 | _base_0.__class = _class_0 | ||
| 162 | if _parent_0.__inherited then | ||
| 163 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 164 | end | ||
| 165 | Thing = _class_0 | ||
| 166 | end | ||
| 167 | local instance = Thing("color") | ||
| 168 | return assert.same(instance:get_property(), "green") | ||
| 169 | end) | ||
| 170 | it("should have class properties", function() | ||
| 171 | local Base | ||
| 172 | do | ||
| 173 | local _class_0 | ||
| 174 | local _base_0 = { } | ||
| 175 | if _base_0.__index == nil then | ||
| 176 | _base_0.__index = _base_0 | ||
| 177 | end | ||
| 178 | _class_0 = setmetatable({ | ||
| 179 | __init = function() end, | ||
| 180 | __base = _base_0, | ||
| 181 | __name = "Base" | ||
| 182 | }, { | ||
| 183 | __index = _base_0, | ||
| 184 | __call = function(cls, ...) | ||
| 185 | local _self_0 = setmetatable({ }, _base_0) | ||
| 186 | cls.__init(_self_0, ...) | ||
| 187 | return _self_0 | ||
| 188 | end | ||
| 189 | }) | ||
| 190 | _base_0.__class = _class_0 | ||
| 191 | Base = _class_0 | ||
| 192 | end | ||
| 193 | local Thing | ||
| 194 | do | ||
| 195 | local _class_0 | ||
| 196 | local _parent_0 = Base | ||
| 197 | local _base_0 = { } | ||
| 198 | if _base_0.__index == nil then | ||
| 199 | _base_0.__index = _base_0 | ||
| 200 | end | ||
| 201 | setmetatable(_base_0, _parent_0.__base) | ||
| 202 | _class_0 = setmetatable({ | ||
| 203 | __init = function(self, ...) | ||
| 204 | return _class_0.__parent.__init(self, ...) | ||
| 205 | end, | ||
| 206 | __base = _base_0, | ||
| 207 | __name = "Thing", | ||
| 208 | __parent = _parent_0 | ||
| 209 | }, { | ||
| 210 | __index = function(cls, name) | ||
| 211 | local val = rawget(_base_0, name) | ||
| 212 | if val == nil then | ||
| 213 | local parent = rawget(cls, "__parent") | ||
| 214 | if parent then | ||
| 215 | return parent[name] | ||
| 216 | end | ||
| 217 | else | ||
| 218 | return val | ||
| 219 | end | ||
| 220 | end, | ||
| 221 | __call = function(cls, ...) | ||
| 222 | local _self_0 = setmetatable({ }, _base_0) | ||
| 223 | cls.__init(_self_0, ...) | ||
| 224 | return _self_0 | ||
| 225 | end | ||
| 226 | }) | ||
| 227 | _base_0.__class = _class_0 | ||
| 228 | if _parent_0.__inherited then | ||
| 229 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 230 | end | ||
| 231 | Thing = _class_0 | ||
| 232 | end | ||
| 233 | local instance = Thing() | ||
| 234 | assert.same(Base.__name, "Base") | ||
| 235 | assert.same(Thing.__name, "Thing") | ||
| 236 | assert.is_true(Thing.__parent == Base) | ||
| 237 | return assert.is_true(instance.__class == Thing) | ||
| 238 | end) | ||
| 239 | it("should have name when assigned", function() | ||
| 240 | local Thing | ||
| 241 | do | ||
| 242 | local _class_0 | ||
| 243 | local _base_0 = { } | ||
| 244 | if _base_0.__index == nil then | ||
| 245 | _base_0.__index = _base_0 | ||
| 246 | end | ||
| 247 | _class_0 = setmetatable({ | ||
| 248 | __init = function() end, | ||
| 249 | __base = _base_0, | ||
| 250 | __name = "Thing" | ||
| 251 | }, { | ||
| 252 | __index = _base_0, | ||
| 253 | __call = function(cls, ...) | ||
| 254 | local _self_0 = setmetatable({ }, _base_0) | ||
| 255 | cls.__init(_self_0, ...) | ||
| 256 | return _self_0 | ||
| 257 | end | ||
| 258 | }) | ||
| 259 | _base_0.__class = _class_0 | ||
| 260 | Thing = _class_0 | ||
| 261 | end | ||
| 262 | return assert.same(Thing.__name, "Thing") | ||
| 263 | end) | ||
| 264 | it("should not expose class properties on instance", function() | ||
| 265 | local Thing | ||
| 266 | do | ||
| 267 | local _class_0 | ||
| 268 | local _base_0 = { } | ||
| 269 | if _base_0.__index == nil then | ||
| 270 | _base_0.__index = _base_0 | ||
| 271 | end | ||
| 272 | _class_0 = setmetatable({ | ||
| 273 | __init = function() end, | ||
| 274 | __base = _base_0, | ||
| 275 | __name = "Thing" | ||
| 276 | }, { | ||
| 277 | __index = _base_0, | ||
| 278 | __call = function(cls, ...) | ||
| 279 | local _self_0 = setmetatable({ }, _base_0) | ||
| 280 | cls.__init(_self_0, ...) | ||
| 281 | return _self_0 | ||
| 282 | end | ||
| 283 | }) | ||
| 284 | _base_0.__class = _class_0 | ||
| 285 | local self = _class_0; | ||
| 286 | self.height = 10 | ||
| 287 | Thing = _class_0 | ||
| 288 | end | ||
| 289 | Thing.color = "blue" | ||
| 290 | local instance = Thing() | ||
| 291 | assert.same(instance.color, nil) | ||
| 292 | return assert.same(instance.height, nil) | ||
| 293 | end) | ||
| 294 | it("should expose new things added to __base", function() | ||
| 295 | local Thing | ||
| 296 | do | ||
| 297 | local _class_0 | ||
| 298 | local _base_0 = { } | ||
| 299 | if _base_0.__index == nil then | ||
| 300 | _base_0.__index = _base_0 | ||
| 301 | end | ||
| 302 | _class_0 = setmetatable({ | ||
| 303 | __init = function() end, | ||
| 304 | __base = _base_0, | ||
| 305 | __name = "Thing" | ||
| 306 | }, { | ||
| 307 | __index = _base_0, | ||
| 308 | __call = function(cls, ...) | ||
| 309 | local _self_0 = setmetatable({ }, _base_0) | ||
| 310 | cls.__init(_self_0, ...) | ||
| 311 | return _self_0 | ||
| 312 | end | ||
| 313 | }) | ||
| 314 | _base_0.__class = _class_0 | ||
| 315 | Thing = _class_0 | ||
| 316 | end | ||
| 317 | local instance = Thing() | ||
| 318 | Thing.__base.color = "green" | ||
| 319 | return assert.same(instance.color, "green") | ||
| 320 | end) | ||
| 321 | it("should call with correct receiver", function() | ||
| 322 | local instance | ||
| 323 | local Thing | ||
| 324 | do | ||
| 325 | local _class_0 | ||
| 326 | local _base_0 = { | ||
| 327 | is_class = function(self) | ||
| 328 | return assert.is_true(self == Thing) | ||
| 329 | end, | ||
| 330 | is_instance = function(self) | ||
| 331 | return assert.is_true(self == instance) | ||
| 332 | end, | ||
| 333 | go = function(self) | ||
| 334 | self.__class:is_class() | ||
| 335 | return self:is_instance() | ||
| 336 | end | ||
| 337 | } | ||
| 338 | if _base_0.__index == nil then | ||
| 339 | _base_0.__index = _base_0 | ||
| 340 | end | ||
| 341 | _class_0 = setmetatable({ | ||
| 342 | __init = function() end, | ||
| 343 | __base = _base_0, | ||
| 344 | __name = "Thing" | ||
| 345 | }, { | ||
| 346 | __index = _base_0, | ||
| 347 | __call = function(cls, ...) | ||
| 348 | local _self_0 = setmetatable({ }, _base_0) | ||
| 349 | cls.__init(_self_0, ...) | ||
| 350 | return _self_0 | ||
| 351 | end | ||
| 352 | }) | ||
| 353 | _base_0.__class = _class_0 | ||
| 354 | Thing = _class_0 | ||
| 355 | end | ||
| 356 | instance = Thing() | ||
| 357 | return instance:go() | ||
| 358 | end) | ||
| 359 | it("should have class properies take precedence over base properties", function() | ||
| 360 | local Thing | ||
| 361 | do | ||
| 362 | local _class_0 | ||
| 363 | local _base_0 = { | ||
| 364 | prop = "world" | ||
| 365 | } | ||
| 366 | if _base_0.__index == nil then | ||
| 367 | _base_0.__index = _base_0 | ||
| 368 | end | ||
| 369 | _class_0 = setmetatable({ | ||
| 370 | __init = function() end, | ||
| 371 | __base = _base_0, | ||
| 372 | __name = "Thing" | ||
| 373 | }, { | ||
| 374 | __index = _base_0, | ||
| 375 | __call = function(cls, ...) | ||
| 376 | local _self_0 = setmetatable({ }, _base_0) | ||
| 377 | cls.__init(_self_0, ...) | ||
| 378 | return _self_0 | ||
| 379 | end | ||
| 380 | }) | ||
| 381 | _base_0.__class = _class_0 | ||
| 382 | local self = _class_0; | ||
| 383 | self.prop = "hello" | ||
| 384 | Thing = _class_0 | ||
| 385 | end | ||
| 386 | return assert.same("hello", Thing.prop) | ||
| 387 | end) | ||
| 388 | return describe("super", function() | ||
| 389 | it("should call super constructor", function() | ||
| 390 | local Base | ||
| 391 | do | ||
| 392 | local _class_0 | ||
| 393 | local _base_0 = { } | ||
| 394 | if _base_0.__index == nil then | ||
| 395 | _base_0.__index = _base_0 | ||
| 396 | end | ||
| 397 | _class_0 = setmetatable({ | ||
| 398 | __init = function(self, property) | ||
| 399 | self.property = property | ||
| 400 | end, | ||
| 401 | __base = _base_0, | ||
| 402 | __name = "Base" | ||
| 403 | }, { | ||
| 404 | __index = _base_0, | ||
| 405 | __call = function(cls, ...) | ||
| 406 | local _self_0 = setmetatable({ }, _base_0) | ||
| 407 | cls.__init(_self_0, ...) | ||
| 408 | return _self_0 | ||
| 409 | end | ||
| 410 | }) | ||
| 411 | _base_0.__class = _class_0 | ||
| 412 | Base = _class_0 | ||
| 413 | end | ||
| 414 | local Thing | ||
| 415 | do | ||
| 416 | local _class_0 | ||
| 417 | local _parent_0 = Base | ||
| 418 | local _base_0 = { } | ||
| 419 | if _base_0.__index == nil then | ||
| 420 | _base_0.__index = _base_0 | ||
| 421 | end | ||
| 422 | setmetatable(_base_0, _parent_0.__base) | ||
| 423 | _class_0 = setmetatable({ | ||
| 424 | __init = function(self, name) | ||
| 425 | self.name = name | ||
| 426 | return _class_0.__parent.__init(self, "name") | ||
| 427 | end, | ||
| 428 | __base = _base_0, | ||
| 429 | __name = "Thing", | ||
| 430 | __parent = _parent_0 | ||
| 431 | }, { | ||
| 432 | __index = function(cls, name) | ||
| 433 | local val = rawget(_base_0, name) | ||
| 434 | if val == nil then | ||
| 435 | local parent = rawget(cls, "__parent") | ||
| 436 | if parent then | ||
| 437 | return parent[name] | ||
| 438 | end | ||
| 439 | else | ||
| 440 | return val | ||
| 441 | end | ||
| 442 | end, | ||
| 443 | __call = function(cls, ...) | ||
| 444 | local _self_0 = setmetatable({ }, _base_0) | ||
| 445 | cls.__init(_self_0, ...) | ||
| 446 | return _self_0 | ||
| 447 | end | ||
| 448 | }) | ||
| 449 | _base_0.__class = _class_0 | ||
| 450 | if _parent_0.__inherited then | ||
| 451 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 452 | end | ||
| 453 | Thing = _class_0 | ||
| 454 | end | ||
| 455 | local instance = Thing("the_thing") | ||
| 456 | assert.same(instance.property, "name") | ||
| 457 | return assert.same(instance.name, "the_thing") | ||
| 458 | end) | ||
| 459 | it("should call super method", function() | ||
| 460 | local Base | ||
| 461 | do | ||
| 462 | local _class_0 | ||
| 463 | local _base_0 = { | ||
| 464 | _count = 111, | ||
| 465 | counter = function(self) | ||
| 466 | return self._count | ||
| 467 | end | ||
| 468 | } | ||
| 469 | if _base_0.__index == nil then | ||
| 470 | _base_0.__index = _base_0 | ||
| 471 | end | ||
| 472 | _class_0 = setmetatable({ | ||
| 473 | __init = function() end, | ||
| 474 | __base = _base_0, | ||
| 475 | __name = "Base" | ||
| 476 | }, { | ||
| 477 | __index = _base_0, | ||
| 478 | __call = function(cls, ...) | ||
| 479 | local _self_0 = setmetatable({ }, _base_0) | ||
| 480 | cls.__init(_self_0, ...) | ||
| 481 | return _self_0 | ||
| 482 | end | ||
| 483 | }) | ||
| 484 | _base_0.__class = _class_0 | ||
| 485 | Base = _class_0 | ||
| 486 | end | ||
| 487 | local Thing | ||
| 488 | do | ||
| 489 | local _class_0 | ||
| 490 | local _parent_0 = Base | ||
| 491 | local _base_0 = { | ||
| 492 | counter = function(self) | ||
| 493 | return ("%08d"):format(_class_0.__parent.__base.counter(self)) | ||
| 494 | end | ||
| 495 | } | ||
| 496 | if _base_0.__index == nil then | ||
| 497 | _base_0.__index = _base_0 | ||
| 498 | end | ||
| 499 | setmetatable(_base_0, _parent_0.__base) | ||
| 500 | _class_0 = setmetatable({ | ||
| 501 | __init = function(self, ...) | ||
| 502 | return _class_0.__parent.__init(self, ...) | ||
| 503 | end, | ||
| 504 | __base = _base_0, | ||
| 505 | __name = "Thing", | ||
| 506 | __parent = _parent_0 | ||
| 507 | }, { | ||
| 508 | __index = function(cls, name) | ||
| 509 | local val = rawget(_base_0, name) | ||
| 510 | if val == nil then | ||
| 511 | local parent = rawget(cls, "__parent") | ||
| 512 | if parent then | ||
| 513 | return parent[name] | ||
| 514 | end | ||
| 515 | else | ||
| 516 | return val | ||
| 517 | end | ||
| 518 | end, | ||
| 519 | __call = function(cls, ...) | ||
| 520 | local _self_0 = setmetatable({ }, _base_0) | ||
| 521 | cls.__init(_self_0, ...) | ||
| 522 | return _self_0 | ||
| 523 | end | ||
| 524 | }) | ||
| 525 | _base_0.__class = _class_0 | ||
| 526 | if _parent_0.__inherited then | ||
| 527 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 528 | end | ||
| 529 | Thing = _class_0 | ||
| 530 | end | ||
| 531 | local instance = Thing() | ||
| 532 | return assert.same(instance:counter(), "00000111") | ||
| 533 | end) | ||
| 534 | it("should call other method from super", function() | ||
| 535 | local Base | ||
| 536 | do | ||
| 537 | local _class_0 | ||
| 538 | local _base_0 = { | ||
| 539 | _count = 111, | ||
| 540 | counter = function(self) | ||
| 541 | return self._count | ||
| 542 | end | ||
| 543 | } | ||
| 544 | if _base_0.__index == nil then | ||
| 545 | _base_0.__index = _base_0 | ||
| 546 | end | ||
| 547 | _class_0 = setmetatable({ | ||
| 548 | __init = function() end, | ||
| 549 | __base = _base_0, | ||
| 550 | __name = "Base" | ||
| 551 | }, { | ||
| 552 | __index = _base_0, | ||
| 553 | __call = function(cls, ...) | ||
| 554 | local _self_0 = setmetatable({ }, _base_0) | ||
| 555 | cls.__init(_self_0, ...) | ||
| 556 | return _self_0 | ||
| 557 | end | ||
| 558 | }) | ||
| 559 | _base_0.__class = _class_0 | ||
| 560 | Base = _class_0 | ||
| 561 | end | ||
| 562 | local Thing | ||
| 563 | do | ||
| 564 | local _class_0 | ||
| 565 | local _parent_0 = Base | ||
| 566 | local _base_0 = { | ||
| 567 | other_method = function(self) | ||
| 568 | return _class_0.__parent.counter(self) | ||
| 569 | end | ||
| 570 | } | ||
| 571 | if _base_0.__index == nil then | ||
| 572 | _base_0.__index = _base_0 | ||
| 573 | end | ||
| 574 | setmetatable(_base_0, _parent_0.__base) | ||
| 575 | _class_0 = setmetatable({ | ||
| 576 | __init = function(self, ...) | ||
| 577 | return _class_0.__parent.__init(self, ...) | ||
| 578 | end, | ||
| 579 | __base = _base_0, | ||
| 580 | __name = "Thing", | ||
| 581 | __parent = _parent_0 | ||
| 582 | }, { | ||
| 583 | __index = function(cls, name) | ||
| 584 | local val = rawget(_base_0, name) | ||
| 585 | if val == nil then | ||
| 586 | local parent = rawget(cls, "__parent") | ||
| 587 | if parent then | ||
| 588 | return parent[name] | ||
| 589 | end | ||
| 590 | else | ||
| 591 | return val | ||
| 592 | end | ||
| 593 | end, | ||
| 594 | __call = function(cls, ...) | ||
| 595 | local _self_0 = setmetatable({ }, _base_0) | ||
| 596 | cls.__init(_self_0, ...) | ||
| 597 | return _self_0 | ||
| 598 | end | ||
| 599 | }) | ||
| 600 | _base_0.__class = _class_0 | ||
| 601 | if _parent_0.__inherited then | ||
| 602 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 603 | end | ||
| 604 | Thing = _class_0 | ||
| 605 | end | ||
| 606 | local instance = Thing() | ||
| 607 | return assert.same(instance:other_method(), 111) | ||
| 608 | end) | ||
| 609 | it("should get super class", function() | ||
| 610 | local Base | ||
| 611 | do | ||
| 612 | local _class_0 | ||
| 613 | local _base_0 = { } | ||
| 614 | if _base_0.__index == nil then | ||
| 615 | _base_0.__index = _base_0 | ||
| 616 | end | ||
| 617 | _class_0 = setmetatable({ | ||
| 618 | __init = function() end, | ||
| 619 | __base = _base_0, | ||
| 620 | __name = "Base" | ||
| 621 | }, { | ||
| 622 | __index = _base_0, | ||
| 623 | __call = function(cls, ...) | ||
| 624 | local _self_0 = setmetatable({ }, _base_0) | ||
| 625 | cls.__init(_self_0, ...) | ||
| 626 | return _self_0 | ||
| 627 | end | ||
| 628 | }) | ||
| 629 | _base_0.__class = _class_0 | ||
| 630 | Base = _class_0 | ||
| 631 | end | ||
| 632 | local Thing | ||
| 633 | do | ||
| 634 | local _class_0 | ||
| 635 | local _parent_0 = Base | ||
| 636 | local _base_0 = { | ||
| 637 | get_super = function(self) | ||
| 638 | return _class_0.__parent | ||
| 639 | end | ||
| 640 | } | ||
| 641 | if _base_0.__index == nil then | ||
| 642 | _base_0.__index = _base_0 | ||
| 643 | end | ||
| 644 | setmetatable(_base_0, _parent_0.__base) | ||
| 645 | _class_0 = setmetatable({ | ||
| 646 | __init = function(self, ...) | ||
| 647 | return _class_0.__parent.__init(self, ...) | ||
| 648 | end, | ||
| 649 | __base = _base_0, | ||
| 650 | __name = "Thing", | ||
| 651 | __parent = _parent_0 | ||
| 652 | }, { | ||
| 653 | __index = function(cls, name) | ||
| 654 | local val = rawget(_base_0, name) | ||
| 655 | if val == nil then | ||
| 656 | local parent = rawget(cls, "__parent") | ||
| 657 | if parent then | ||
| 658 | return parent[name] | ||
| 659 | end | ||
| 660 | else | ||
| 661 | return val | ||
| 662 | end | ||
| 663 | end, | ||
| 664 | __call = function(cls, ...) | ||
| 665 | local _self_0 = setmetatable({ }, _base_0) | ||
| 666 | cls.__init(_self_0, ...) | ||
| 667 | return _self_0 | ||
| 668 | end | ||
| 669 | }) | ||
| 670 | _base_0.__class = _class_0 | ||
| 671 | if _parent_0.__inherited then | ||
| 672 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 673 | end | ||
| 674 | Thing = _class_0 | ||
| 675 | end | ||
| 676 | local instance = Thing() | ||
| 677 | return assert.is_true(instance:get_super() == Base) | ||
| 678 | end) | ||
| 679 | it("should get a bound method from super", function() | ||
| 680 | local Base | ||
| 681 | do | ||
| 682 | local _class_0 | ||
| 683 | local _base_0 = { | ||
| 684 | count = 1, | ||
| 685 | get_count = function(self) | ||
| 686 | return self.count | ||
| 687 | end | ||
| 688 | } | ||
| 689 | if _base_0.__index == nil then | ||
| 690 | _base_0.__index = _base_0 | ||
| 691 | end | ||
| 692 | _class_0 = setmetatable({ | ||
| 693 | __init = function() end, | ||
| 694 | __base = _base_0, | ||
| 695 | __name = "Base" | ||
| 696 | }, { | ||
| 697 | __index = _base_0, | ||
| 698 | __call = function(cls, ...) | ||
| 699 | local _self_0 = setmetatable({ }, _base_0) | ||
| 700 | cls.__init(_self_0, ...) | ||
| 701 | return _self_0 | ||
| 702 | end | ||
| 703 | }) | ||
| 704 | _base_0.__class = _class_0 | ||
| 705 | Base = _class_0 | ||
| 706 | end | ||
| 707 | local Thing | ||
| 708 | do | ||
| 709 | local _class_0 | ||
| 710 | local _parent_0 = Base | ||
| 711 | local _base_0 = { | ||
| 712 | get_count = function(self) | ||
| 713 | return "this is wrong" | ||
| 714 | end, | ||
| 715 | get_method = function(self) | ||
| 716 | local _base_1 = _class_0.__parent | ||
| 717 | local _fn_0 = _base_1.get_count | ||
| 718 | return _fn_0 and function(...) | ||
| 719 | return _fn_0(_base_1, ...) | ||
| 720 | end | ||
| 721 | end | ||
| 722 | } | ||
| 723 | if _base_0.__index == nil then | ||
| 724 | _base_0.__index = _base_0 | ||
| 725 | end | ||
| 726 | setmetatable(_base_0, _parent_0.__base) | ||
| 727 | _class_0 = setmetatable({ | ||
| 728 | __init = function(self, ...) | ||
| 729 | return _class_0.__parent.__init(self, ...) | ||
| 730 | end, | ||
| 731 | __base = _base_0, | ||
| 732 | __name = "Thing", | ||
| 733 | __parent = _parent_0 | ||
| 734 | }, { | ||
| 735 | __index = function(cls, name) | ||
| 736 | local val = rawget(_base_0, name) | ||
| 737 | if val == nil then | ||
| 738 | local parent = rawget(cls, "__parent") | ||
| 739 | if parent then | ||
| 740 | return parent[name] | ||
| 741 | end | ||
| 742 | else | ||
| 743 | return val | ||
| 744 | end | ||
| 745 | end, | ||
| 746 | __call = function(cls, ...) | ||
| 747 | local _self_0 = setmetatable({ }, _base_0) | ||
| 748 | cls.__init(_self_0, ...) | ||
| 749 | return _self_0 | ||
| 750 | end | ||
| 751 | }) | ||
| 752 | _base_0.__class = _class_0 | ||
| 753 | if _parent_0.__inherited then | ||
| 754 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 755 | end | ||
| 756 | Thing = _class_0 | ||
| 757 | end | ||
| 758 | local instance = Thing() | ||
| 759 | return assert.same(instance:get_method()(), 1) | ||
| 760 | end) | ||
| 761 | it("class properties take precedence in super class over base", function() | ||
| 762 | local Thing | ||
| 763 | do | ||
| 764 | local _class_0 | ||
| 765 | local _base_0 = { | ||
| 766 | prop = "world" | ||
| 767 | } | ||
| 768 | if _base_0.__index == nil then | ||
| 769 | _base_0.__index = _base_0 | ||
| 770 | end | ||
| 771 | _class_0 = setmetatable({ | ||
| 772 | __init = function() end, | ||
| 773 | __base = _base_0, | ||
| 774 | __name = "Thing" | ||
| 775 | }, { | ||
| 776 | __index = _base_0, | ||
| 777 | __call = function(cls, ...) | ||
| 778 | local _self_0 = setmetatable({ }, _base_0) | ||
| 779 | cls.__init(_self_0, ...) | ||
| 780 | return _self_0 | ||
| 781 | end | ||
| 782 | }) | ||
| 783 | _base_0.__class = _class_0 | ||
| 784 | local self = _class_0; | ||
| 785 | self.prop = "hello" | ||
| 786 | Thing = _class_0 | ||
| 787 | end | ||
| 788 | local OtherThing | ||
| 789 | do | ||
| 790 | local _class_0 | ||
| 791 | local _parent_0 = Thing | ||
| 792 | local _base_0 = { } | ||
| 793 | if _base_0.__index == nil then | ||
| 794 | _base_0.__index = _base_0 | ||
| 795 | end | ||
| 796 | setmetatable(_base_0, _parent_0.__base) | ||
| 797 | _class_0 = setmetatable({ | ||
| 798 | __init = function(self, ...) | ||
| 799 | return _class_0.__parent.__init(self, ...) | ||
| 800 | end, | ||
| 801 | __base = _base_0, | ||
| 802 | __name = "OtherThing", | ||
| 803 | __parent = _parent_0 | ||
| 804 | }, { | ||
| 805 | __index = function(cls, name) | ||
| 806 | local val = rawget(_base_0, name) | ||
| 807 | if val == nil then | ||
| 808 | local parent = rawget(cls, "__parent") | ||
| 809 | if parent then | ||
| 810 | return parent[name] | ||
| 811 | end | ||
| 812 | else | ||
| 813 | return val | ||
| 814 | end | ||
| 815 | end, | ||
| 816 | __call = function(cls, ...) | ||
| 817 | local _self_0 = setmetatable({ }, _base_0) | ||
| 818 | cls.__init(_self_0, ...) | ||
| 819 | return _self_0 | ||
| 820 | end | ||
| 821 | }) | ||
| 822 | _base_0.__class = _class_0 | ||
| 823 | if _parent_0.__inherited then | ||
| 824 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 825 | end | ||
| 826 | OtherThing = _class_0 | ||
| 827 | end | ||
| 828 | return assert.same("hello", OtherThing.prop) | ||
| 829 | end) | ||
| 830 | it("gets value from base in super class", function() | ||
| 831 | local Thing | ||
| 832 | do | ||
| 833 | local _class_0 | ||
| 834 | local _base_0 = { | ||
| 835 | prop = "world" | ||
| 836 | } | ||
| 837 | if _base_0.__index == nil then | ||
| 838 | _base_0.__index = _base_0 | ||
| 839 | end | ||
| 840 | _class_0 = setmetatable({ | ||
| 841 | __init = function() end, | ||
| 842 | __base = _base_0, | ||
| 843 | __name = "Thing" | ||
| 844 | }, { | ||
| 845 | __index = _base_0, | ||
| 846 | __call = function(cls, ...) | ||
| 847 | local _self_0 = setmetatable({ }, _base_0) | ||
| 848 | cls.__init(_self_0, ...) | ||
| 849 | return _self_0 | ||
| 850 | end | ||
| 851 | }) | ||
| 852 | _base_0.__class = _class_0 | ||
| 853 | Thing = _class_0 | ||
| 854 | end | ||
| 855 | local OtherThing | ||
| 856 | do | ||
| 857 | local _class_0 | ||
| 858 | local _parent_0 = Thing | ||
| 859 | local _base_0 = { } | ||
| 860 | if _base_0.__index == nil then | ||
| 861 | _base_0.__index = _base_0 | ||
| 862 | end | ||
| 863 | setmetatable(_base_0, _parent_0.__base) | ||
| 864 | _class_0 = setmetatable({ | ||
| 865 | __init = function(self, ...) | ||
| 866 | return _class_0.__parent.__init(self, ...) | ||
| 867 | end, | ||
| 868 | __base = _base_0, | ||
| 869 | __name = "OtherThing", | ||
| 870 | __parent = _parent_0 | ||
| 871 | }, { | ||
| 872 | __index = function(cls, name) | ||
| 873 | local val = rawget(_base_0, name) | ||
| 874 | if val == nil then | ||
| 875 | local parent = rawget(cls, "__parent") | ||
| 876 | if parent then | ||
| 877 | return parent[name] | ||
| 878 | end | ||
| 879 | else | ||
| 880 | return val | ||
| 881 | end | ||
| 882 | end, | ||
| 883 | __call = function(cls, ...) | ||
| 884 | local _self_0 = setmetatable({ }, _base_0) | ||
| 885 | cls.__init(_self_0, ...) | ||
| 886 | return _self_0 | ||
| 887 | end | ||
| 888 | }) | ||
| 889 | _base_0.__class = _class_0 | ||
| 890 | if _parent_0.__inherited then | ||
| 891 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 892 | end | ||
| 893 | OtherThing = _class_0 | ||
| 894 | end | ||
| 895 | return assert.same("world", OtherThing.prop) | ||
| 896 | end) | ||
| 897 | it("should let parent be replaced on class", function() | ||
| 898 | local A | ||
| 899 | do | ||
| 900 | local _class_0 | ||
| 901 | local _base_0 = { | ||
| 902 | cool = function(self) | ||
| 903 | return 1234 | ||
| 904 | end, | ||
| 905 | plain = function(self) | ||
| 906 | return "a" | ||
| 907 | end | ||
| 908 | } | ||
| 909 | if _base_0.__index == nil then | ||
| 910 | _base_0.__index = _base_0 | ||
| 911 | end | ||
| 912 | _class_0 = setmetatable({ | ||
| 913 | __init = function() end, | ||
| 914 | __base = _base_0, | ||
| 915 | __name = "A" | ||
| 916 | }, { | ||
| 917 | __index = _base_0, | ||
| 918 | __call = function(cls, ...) | ||
| 919 | local _self_0 = setmetatable({ }, _base_0) | ||
| 920 | cls.__init(_self_0, ...) | ||
| 921 | return _self_0 | ||
| 922 | end | ||
| 923 | }) | ||
| 924 | _base_0.__class = _class_0 | ||
| 925 | local self = _class_0; | ||
| 926 | self.prop = "yeah" | ||
| 927 | A = _class_0 | ||
| 928 | end | ||
| 929 | local B | ||
| 930 | do | ||
| 931 | local _class_0 | ||
| 932 | local _base_0 = { | ||
| 933 | cool = function(self) | ||
| 934 | return 9999 | ||
| 935 | end, | ||
| 936 | plain = function(self) | ||
| 937 | return "b" | ||
| 938 | end | ||
| 939 | } | ||
| 940 | if _base_0.__index == nil then | ||
| 941 | _base_0.__index = _base_0 | ||
| 942 | end | ||
| 943 | _class_0 = setmetatable({ | ||
| 944 | __init = function() end, | ||
| 945 | __base = _base_0, | ||
| 946 | __name = "B" | ||
| 947 | }, { | ||
| 948 | __index = _base_0, | ||
| 949 | __call = function(cls, ...) | ||
| 950 | local _self_0 = setmetatable({ }, _base_0) | ||
| 951 | cls.__init(_self_0, ...) | ||
| 952 | return _self_0 | ||
| 953 | end | ||
| 954 | }) | ||
| 955 | _base_0.__class = _class_0 | ||
| 956 | local self = _class_0; | ||
| 957 | self.prop = "okay" | ||
| 958 | B = _class_0 | ||
| 959 | end | ||
| 960 | local Thing | ||
| 961 | do | ||
| 962 | local _class_0 | ||
| 963 | local _parent_0 = A | ||
| 964 | local _base_0 = { | ||
| 965 | cool = function(self) | ||
| 966 | return _class_0.__parent.__base.cool(self) + 1 | ||
| 967 | end, | ||
| 968 | get_super = function(self) | ||
| 969 | return _class_0.__parent | ||
| 970 | end | ||
| 971 | } | ||
| 972 | if _base_0.__index == nil then | ||
| 973 | _base_0.__index = _base_0 | ||
| 974 | end | ||
| 975 | setmetatable(_base_0, _parent_0.__base) | ||
| 976 | _class_0 = setmetatable({ | ||
| 977 | __init = function(self, ...) | ||
| 978 | return _class_0.__parent.__init(self, ...) | ||
| 979 | end, | ||
| 980 | __base = _base_0, | ||
| 981 | __name = "Thing", | ||
| 982 | __parent = _parent_0 | ||
| 983 | }, { | ||
| 984 | __index = function(cls, name) | ||
| 985 | local val = rawget(_base_0, name) | ||
| 986 | if val == nil then | ||
| 987 | local parent = rawget(cls, "__parent") | ||
| 988 | if parent then | ||
| 989 | return parent[name] | ||
| 990 | end | ||
| 991 | else | ||
| 992 | return val | ||
| 993 | end | ||
| 994 | end, | ||
| 995 | __call = function(cls, ...) | ||
| 996 | local _self_0 = setmetatable({ }, _base_0) | ||
| 997 | cls.__init(_self_0, ...) | ||
| 998 | return _self_0 | ||
| 999 | end | ||
| 1000 | }) | ||
| 1001 | _base_0.__class = _class_0 | ||
| 1002 | if _parent_0.__inherited then | ||
| 1003 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1004 | end | ||
| 1005 | Thing = _class_0 | ||
| 1006 | end | ||
| 1007 | local instance = Thing() | ||
| 1008 | assert.same("a", instance:plain()) | ||
| 1009 | assert.same(1235, instance:cool()) | ||
| 1010 | assert(A == instance:get_super(), "expected super to be B") | ||
| 1011 | Thing.__parent = B | ||
| 1012 | setmetatable(Thing.__base, B.__base) | ||
| 1013 | assert.same("b", instance:plain()) | ||
| 1014 | assert.same(10000, instance:cool()) | ||
| 1015 | return assert(B == instance:get_super(), "expected super to be B") | ||
| 1016 | end) | ||
| 1017 | it("should resolve many levels of super", function() | ||
| 1018 | local One | ||
| 1019 | do | ||
| 1020 | local _class_0 | ||
| 1021 | local _base_0 = { | ||
| 1022 | a = function(self) | ||
| 1023 | return 1 | ||
| 1024 | end | ||
| 1025 | } | ||
| 1026 | if _base_0.__index == nil then | ||
| 1027 | _base_0.__index = _base_0 | ||
| 1028 | end | ||
| 1029 | _class_0 = setmetatable({ | ||
| 1030 | __init = function() end, | ||
| 1031 | __base = _base_0, | ||
| 1032 | __name = "One" | ||
| 1033 | }, { | ||
| 1034 | __index = _base_0, | ||
| 1035 | __call = function(cls, ...) | ||
| 1036 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1037 | cls.__init(_self_0, ...) | ||
| 1038 | return _self_0 | ||
| 1039 | end | ||
| 1040 | }) | ||
| 1041 | _base_0.__class = _class_0 | ||
| 1042 | One = _class_0 | ||
| 1043 | end | ||
| 1044 | local Two | ||
| 1045 | do | ||
| 1046 | local _class_0 | ||
| 1047 | local _parent_0 = One | ||
| 1048 | local _base_0 = { | ||
| 1049 | a = function(self) | ||
| 1050 | return _class_0.__parent.__base.a(self) + 2 | ||
| 1051 | end | ||
| 1052 | } | ||
| 1053 | if _base_0.__index == nil then | ||
| 1054 | _base_0.__index = _base_0 | ||
| 1055 | end | ||
| 1056 | setmetatable(_base_0, _parent_0.__base) | ||
| 1057 | _class_0 = setmetatable({ | ||
| 1058 | __init = function(self, ...) | ||
| 1059 | return _class_0.__parent.__init(self, ...) | ||
| 1060 | end, | ||
| 1061 | __base = _base_0, | ||
| 1062 | __name = "Two", | ||
| 1063 | __parent = _parent_0 | ||
| 1064 | }, { | ||
| 1065 | __index = function(cls, name) | ||
| 1066 | local val = rawget(_base_0, name) | ||
| 1067 | if val == nil then | ||
| 1068 | local parent = rawget(cls, "__parent") | ||
| 1069 | if parent then | ||
| 1070 | return parent[name] | ||
| 1071 | end | ||
| 1072 | else | ||
| 1073 | return val | ||
| 1074 | end | ||
| 1075 | end, | ||
| 1076 | __call = function(cls, ...) | ||
| 1077 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1078 | cls.__init(_self_0, ...) | ||
| 1079 | return _self_0 | ||
| 1080 | end | ||
| 1081 | }) | ||
| 1082 | _base_0.__class = _class_0 | ||
| 1083 | if _parent_0.__inherited then | ||
| 1084 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1085 | end | ||
| 1086 | Two = _class_0 | ||
| 1087 | end | ||
| 1088 | local Three | ||
| 1089 | do | ||
| 1090 | local _class_0 | ||
| 1091 | local _parent_0 = Two | ||
| 1092 | local _base_0 = { | ||
| 1093 | a = function(self) | ||
| 1094 | return _class_0.__parent.__base.a(self) + 3 | ||
| 1095 | end | ||
| 1096 | } | ||
| 1097 | if _base_0.__index == nil then | ||
| 1098 | _base_0.__index = _base_0 | ||
| 1099 | end | ||
| 1100 | setmetatable(_base_0, _parent_0.__base) | ||
| 1101 | _class_0 = setmetatable({ | ||
| 1102 | __init = function(self, ...) | ||
| 1103 | return _class_0.__parent.__init(self, ...) | ||
| 1104 | end, | ||
| 1105 | __base = _base_0, | ||
| 1106 | __name = "Three", | ||
| 1107 | __parent = _parent_0 | ||
| 1108 | }, { | ||
| 1109 | __index = function(cls, name) | ||
| 1110 | local val = rawget(_base_0, name) | ||
| 1111 | if val == nil then | ||
| 1112 | local parent = rawget(cls, "__parent") | ||
| 1113 | if parent then | ||
| 1114 | return parent[name] | ||
| 1115 | end | ||
| 1116 | else | ||
| 1117 | return val | ||
| 1118 | end | ||
| 1119 | end, | ||
| 1120 | __call = function(cls, ...) | ||
| 1121 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1122 | cls.__init(_self_0, ...) | ||
| 1123 | return _self_0 | ||
| 1124 | end | ||
| 1125 | }) | ||
| 1126 | _base_0.__class = _class_0 | ||
| 1127 | if _parent_0.__inherited then | ||
| 1128 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1129 | end | ||
| 1130 | Three = _class_0 | ||
| 1131 | end | ||
| 1132 | local i = Three() | ||
| 1133 | return assert.same(6, i:a()) | ||
| 1134 | end) | ||
| 1135 | it("should resolve many levels of super with a gap", function() | ||
| 1136 | local One | ||
| 1137 | do | ||
| 1138 | local _class_0 | ||
| 1139 | local _base_0 = { | ||
| 1140 | a = function(self) | ||
| 1141 | return 1 | ||
| 1142 | end | ||
| 1143 | } | ||
| 1144 | if _base_0.__index == nil then | ||
| 1145 | _base_0.__index = _base_0 | ||
| 1146 | end | ||
| 1147 | _class_0 = setmetatable({ | ||
| 1148 | __init = function() end, | ||
| 1149 | __base = _base_0, | ||
| 1150 | __name = "One" | ||
| 1151 | }, { | ||
| 1152 | __index = _base_0, | ||
| 1153 | __call = function(cls, ...) | ||
| 1154 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1155 | cls.__init(_self_0, ...) | ||
| 1156 | return _self_0 | ||
| 1157 | end | ||
| 1158 | }) | ||
| 1159 | _base_0.__class = _class_0 | ||
| 1160 | One = _class_0 | ||
| 1161 | end | ||
| 1162 | local Two | ||
| 1163 | do | ||
| 1164 | local _class_0 | ||
| 1165 | local _parent_0 = One | ||
| 1166 | local _base_0 = { } | ||
| 1167 | if _base_0.__index == nil then | ||
| 1168 | _base_0.__index = _base_0 | ||
| 1169 | end | ||
| 1170 | setmetatable(_base_0, _parent_0.__base) | ||
| 1171 | _class_0 = setmetatable({ | ||
| 1172 | __init = function(self, ...) | ||
| 1173 | return _class_0.__parent.__init(self, ...) | ||
| 1174 | end, | ||
| 1175 | __base = _base_0, | ||
| 1176 | __name = "Two", | ||
| 1177 | __parent = _parent_0 | ||
| 1178 | }, { | ||
| 1179 | __index = function(cls, name) | ||
| 1180 | local val = rawget(_base_0, name) | ||
| 1181 | if val == nil then | ||
| 1182 | local parent = rawget(cls, "__parent") | ||
| 1183 | if parent then | ||
| 1184 | return parent[name] | ||
| 1185 | end | ||
| 1186 | else | ||
| 1187 | return val | ||
| 1188 | end | ||
| 1189 | end, | ||
| 1190 | __call = function(cls, ...) | ||
| 1191 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1192 | cls.__init(_self_0, ...) | ||
| 1193 | return _self_0 | ||
| 1194 | end | ||
| 1195 | }) | ||
| 1196 | _base_0.__class = _class_0 | ||
| 1197 | if _parent_0.__inherited then | ||
| 1198 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1199 | end | ||
| 1200 | Two = _class_0 | ||
| 1201 | end | ||
| 1202 | local Three | ||
| 1203 | do | ||
| 1204 | local _class_0 | ||
| 1205 | local _parent_0 = Two | ||
| 1206 | local _base_0 = { | ||
| 1207 | a = function(self) | ||
| 1208 | return _class_0.__parent.__base.a(self) + 3 | ||
| 1209 | end | ||
| 1210 | } | ||
| 1211 | if _base_0.__index == nil then | ||
| 1212 | _base_0.__index = _base_0 | ||
| 1213 | end | ||
| 1214 | setmetatable(_base_0, _parent_0.__base) | ||
| 1215 | _class_0 = setmetatable({ | ||
| 1216 | __init = function(self, ...) | ||
| 1217 | return _class_0.__parent.__init(self, ...) | ||
| 1218 | end, | ||
| 1219 | __base = _base_0, | ||
| 1220 | __name = "Three", | ||
| 1221 | __parent = _parent_0 | ||
| 1222 | }, { | ||
| 1223 | __index = function(cls, name) | ||
| 1224 | local val = rawget(_base_0, name) | ||
| 1225 | if val == nil then | ||
| 1226 | local parent = rawget(cls, "__parent") | ||
| 1227 | if parent then | ||
| 1228 | return parent[name] | ||
| 1229 | end | ||
| 1230 | else | ||
| 1231 | return val | ||
| 1232 | end | ||
| 1233 | end, | ||
| 1234 | __call = function(cls, ...) | ||
| 1235 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1236 | cls.__init(_self_0, ...) | ||
| 1237 | return _self_0 | ||
| 1238 | end | ||
| 1239 | }) | ||
| 1240 | _base_0.__class = _class_0 | ||
| 1241 | if _parent_0.__inherited then | ||
| 1242 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1243 | end | ||
| 1244 | Three = _class_0 | ||
| 1245 | end | ||
| 1246 | local Four | ||
| 1247 | do | ||
| 1248 | local _class_0 | ||
| 1249 | local _parent_0 = Three | ||
| 1250 | local _base_0 = { | ||
| 1251 | a = function(self) | ||
| 1252 | return _class_0.__parent.__base.a(self) + 4 | ||
| 1253 | end | ||
| 1254 | } | ||
| 1255 | if _base_0.__index == nil then | ||
| 1256 | _base_0.__index = _base_0 | ||
| 1257 | end | ||
| 1258 | setmetatable(_base_0, _parent_0.__base) | ||
| 1259 | _class_0 = setmetatable({ | ||
| 1260 | __init = function(self, ...) | ||
| 1261 | return _class_0.__parent.__init(self, ...) | ||
| 1262 | end, | ||
| 1263 | __base = _base_0, | ||
| 1264 | __name = "Four", | ||
| 1265 | __parent = _parent_0 | ||
| 1266 | }, { | ||
| 1267 | __index = function(cls, name) | ||
| 1268 | local val = rawget(_base_0, name) | ||
| 1269 | if val == nil then | ||
| 1270 | local parent = rawget(cls, "__parent") | ||
| 1271 | if parent then | ||
| 1272 | return parent[name] | ||
| 1273 | end | ||
| 1274 | else | ||
| 1275 | return val | ||
| 1276 | end | ||
| 1277 | end, | ||
| 1278 | __call = function(cls, ...) | ||
| 1279 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1280 | cls.__init(_self_0, ...) | ||
| 1281 | return _self_0 | ||
| 1282 | end | ||
| 1283 | }) | ||
| 1284 | _base_0.__class = _class_0 | ||
| 1285 | if _parent_0.__inherited then | ||
| 1286 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1287 | end | ||
| 1288 | Four = _class_0 | ||
| 1289 | end | ||
| 1290 | local i = Four() | ||
| 1291 | return assert.same(8, i:a()) | ||
| 1292 | end) | ||
| 1293 | it("should call correct class/instance super methods", function() | ||
| 1294 | local Base | ||
| 1295 | do | ||
| 1296 | local _class_0 | ||
| 1297 | local _base_0 = { | ||
| 1298 | doit = function(self) | ||
| 1299 | return "instance" | ||
| 1300 | end | ||
| 1301 | } | ||
| 1302 | if _base_0.__index == nil then | ||
| 1303 | _base_0.__index = _base_0 | ||
| 1304 | end | ||
| 1305 | _class_0 = setmetatable({ | ||
| 1306 | __init = function() end, | ||
| 1307 | __base = _base_0, | ||
| 1308 | __name = "Base" | ||
| 1309 | }, { | ||
| 1310 | __index = _base_0, | ||
| 1311 | __call = function(cls, ...) | ||
| 1312 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1313 | cls.__init(_self_0, ...) | ||
| 1314 | return _self_0 | ||
| 1315 | end | ||
| 1316 | }) | ||
| 1317 | _base_0.__class = _class_0 | ||
| 1318 | local self = _class_0; | ||
| 1319 | self.doit = function(self) | ||
| 1320 | return "class" | ||
| 1321 | end | ||
| 1322 | Base = _class_0 | ||
| 1323 | end | ||
| 1324 | local One | ||
| 1325 | do | ||
| 1326 | local _class_0 | ||
| 1327 | local _parent_0 = Base | ||
| 1328 | local _base_0 = { | ||
| 1329 | doit = function(self) | ||
| 1330 | return _class_0.__parent.__base.doit(self) | ||
| 1331 | end | ||
| 1332 | } | ||
| 1333 | if _base_0.__index == nil then | ||
| 1334 | _base_0.__index = _base_0 | ||
| 1335 | end | ||
| 1336 | setmetatable(_base_0, _parent_0.__base) | ||
| 1337 | _class_0 = setmetatable({ | ||
| 1338 | __init = function(self, ...) | ||
| 1339 | return _class_0.__parent.__init(self, ...) | ||
| 1340 | end, | ||
| 1341 | __base = _base_0, | ||
| 1342 | __name = "One", | ||
| 1343 | __parent = _parent_0 | ||
| 1344 | }, { | ||
| 1345 | __index = function(cls, name) | ||
| 1346 | local val = rawget(_base_0, name) | ||
| 1347 | if val == nil then | ||
| 1348 | local parent = rawget(cls, "__parent") | ||
| 1349 | if parent then | ||
| 1350 | return parent[name] | ||
| 1351 | end | ||
| 1352 | else | ||
| 1353 | return val | ||
| 1354 | end | ||
| 1355 | end, | ||
| 1356 | __call = function(cls, ...) | ||
| 1357 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1358 | cls.__init(_self_0, ...) | ||
| 1359 | return _self_0 | ||
| 1360 | end | ||
| 1361 | }) | ||
| 1362 | _base_0.__class = _class_0 | ||
| 1363 | local self = _class_0; | ||
| 1364 | self.doit = function(self) | ||
| 1365 | return _class_0.__parent.doit(self) | ||
| 1366 | end | ||
| 1367 | if _parent_0.__inherited then | ||
| 1368 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1369 | end | ||
| 1370 | One = _class_0 | ||
| 1371 | end | ||
| 1372 | assert.same("instance", One():doit()) | ||
| 1373 | return assert.same("class", One:doit()) | ||
| 1374 | end) | ||
| 1375 | it("should resolve many levels of super on class methods", function() | ||
| 1376 | local One | ||
| 1377 | do | ||
| 1378 | local _class_0 | ||
| 1379 | local _base_0 = { } | ||
| 1380 | if _base_0.__index == nil then | ||
| 1381 | _base_0.__index = _base_0 | ||
| 1382 | end | ||
| 1383 | _class_0 = setmetatable({ | ||
| 1384 | __init = function() end, | ||
| 1385 | __base = _base_0, | ||
| 1386 | __name = "One" | ||
| 1387 | }, { | ||
| 1388 | __index = _base_0, | ||
| 1389 | __call = function(cls, ...) | ||
| 1390 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1391 | cls.__init(_self_0, ...) | ||
| 1392 | return _self_0 | ||
| 1393 | end | ||
| 1394 | }) | ||
| 1395 | _base_0.__class = _class_0 | ||
| 1396 | local self = _class_0; | ||
| 1397 | self.a = function(self) | ||
| 1398 | return 1 | ||
| 1399 | end | ||
| 1400 | One = _class_0 | ||
| 1401 | end | ||
| 1402 | local Two | ||
| 1403 | do | ||
| 1404 | local _class_0 | ||
| 1405 | local _parent_0 = One | ||
| 1406 | local _base_0 = { } | ||
| 1407 | if _base_0.__index == nil then | ||
| 1408 | _base_0.__index = _base_0 | ||
| 1409 | end | ||
| 1410 | setmetatable(_base_0, _parent_0.__base) | ||
| 1411 | _class_0 = setmetatable({ | ||
| 1412 | __init = function(self, ...) | ||
| 1413 | return _class_0.__parent.__init(self, ...) | ||
| 1414 | end, | ||
| 1415 | __base = _base_0, | ||
| 1416 | __name = "Two", | ||
| 1417 | __parent = _parent_0 | ||
| 1418 | }, { | ||
| 1419 | __index = function(cls, name) | ||
| 1420 | local val = rawget(_base_0, name) | ||
| 1421 | if val == nil then | ||
| 1422 | local parent = rawget(cls, "__parent") | ||
| 1423 | if parent then | ||
| 1424 | return parent[name] | ||
| 1425 | end | ||
| 1426 | else | ||
| 1427 | return val | ||
| 1428 | end | ||
| 1429 | end, | ||
| 1430 | __call = function(cls, ...) | ||
| 1431 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1432 | cls.__init(_self_0, ...) | ||
| 1433 | return _self_0 | ||
| 1434 | end | ||
| 1435 | }) | ||
| 1436 | _base_0.__class = _class_0 | ||
| 1437 | if _parent_0.__inherited then | ||
| 1438 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1439 | end | ||
| 1440 | Two = _class_0 | ||
| 1441 | end | ||
| 1442 | local Three | ||
| 1443 | do | ||
| 1444 | local _class_0 | ||
| 1445 | local _parent_0 = Two | ||
| 1446 | local _base_0 = { } | ||
| 1447 | if _base_0.__index == nil then | ||
| 1448 | _base_0.__index = _base_0 | ||
| 1449 | end | ||
| 1450 | setmetatable(_base_0, _parent_0.__base) | ||
| 1451 | _class_0 = setmetatable({ | ||
| 1452 | __init = function(self, ...) | ||
| 1453 | return _class_0.__parent.__init(self, ...) | ||
| 1454 | end, | ||
| 1455 | __base = _base_0, | ||
| 1456 | __name = "Three", | ||
| 1457 | __parent = _parent_0 | ||
| 1458 | }, { | ||
| 1459 | __index = function(cls, name) | ||
| 1460 | local val = rawget(_base_0, name) | ||
| 1461 | if val == nil then | ||
| 1462 | local parent = rawget(cls, "__parent") | ||
| 1463 | if parent then | ||
| 1464 | return parent[name] | ||
| 1465 | end | ||
| 1466 | else | ||
| 1467 | return val | ||
| 1468 | end | ||
| 1469 | end, | ||
| 1470 | __call = function(cls, ...) | ||
| 1471 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1472 | cls.__init(_self_0, ...) | ||
| 1473 | return _self_0 | ||
| 1474 | end | ||
| 1475 | }) | ||
| 1476 | _base_0.__class = _class_0 | ||
| 1477 | local self = _class_0; | ||
| 1478 | self.a = function(self) | ||
| 1479 | return _class_0.__parent.a(self) + 3 | ||
| 1480 | end | ||
| 1481 | if _parent_0.__inherited then | ||
| 1482 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1483 | end | ||
| 1484 | Three = _class_0 | ||
| 1485 | end | ||
| 1486 | local Four | ||
| 1487 | do | ||
| 1488 | local _class_0 | ||
| 1489 | local _parent_0 = Three | ||
| 1490 | local _base_0 = { } | ||
| 1491 | if _base_0.__index == nil then | ||
| 1492 | _base_0.__index = _base_0 | ||
| 1493 | end | ||
| 1494 | setmetatable(_base_0, _parent_0.__base) | ||
| 1495 | _class_0 = setmetatable({ | ||
| 1496 | __init = function(self, ...) | ||
| 1497 | return _class_0.__parent.__init(self, ...) | ||
| 1498 | end, | ||
| 1499 | __base = _base_0, | ||
| 1500 | __name = "Four", | ||
| 1501 | __parent = _parent_0 | ||
| 1502 | }, { | ||
| 1503 | __index = function(cls, name) | ||
| 1504 | local val = rawget(_base_0, name) | ||
| 1505 | if val == nil then | ||
| 1506 | local parent = rawget(cls, "__parent") | ||
| 1507 | if parent then | ||
| 1508 | return parent[name] | ||
| 1509 | end | ||
| 1510 | else | ||
| 1511 | return val | ||
| 1512 | end | ||
| 1513 | end, | ||
| 1514 | __call = function(cls, ...) | ||
| 1515 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1516 | cls.__init(_self_0, ...) | ||
| 1517 | return _self_0 | ||
| 1518 | end | ||
| 1519 | }) | ||
| 1520 | _base_0.__class = _class_0 | ||
| 1521 | local self = _class_0; | ||
| 1522 | self.a = function(self) | ||
| 1523 | return _class_0.__parent.a(self) + 4 | ||
| 1524 | end | ||
| 1525 | if _parent_0.__inherited then | ||
| 1526 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1527 | end | ||
| 1528 | Four = _class_0 | ||
| 1529 | end | ||
| 1530 | return assert.same(8, Four:a()) | ||
| 1531 | end) | ||
| 1532 | return it("super should still work when method wrapped", function() | ||
| 1533 | local add_some | ||
| 1534 | add_some = function(opts) | ||
| 1535 | return function(self) | ||
| 1536 | return opts.amount + opts[1](self) | ||
| 1537 | end | ||
| 1538 | end | ||
| 1539 | local Base | ||
| 1540 | do | ||
| 1541 | local _class_0 | ||
| 1542 | local _base_0 = { | ||
| 1543 | value = function(self) | ||
| 1544 | return 1 | ||
| 1545 | end | ||
| 1546 | } | ||
| 1547 | if _base_0.__index == nil then | ||
| 1548 | _base_0.__index = _base_0 | ||
| 1549 | end | ||
| 1550 | _class_0 = setmetatable({ | ||
| 1551 | __init = function() end, | ||
| 1552 | __base = _base_0, | ||
| 1553 | __name = "Base" | ||
| 1554 | }, { | ||
| 1555 | __index = _base_0, | ||
| 1556 | __call = function(cls, ...) | ||
| 1557 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1558 | cls.__init(_self_0, ...) | ||
| 1559 | return _self_0 | ||
| 1560 | end | ||
| 1561 | }) | ||
| 1562 | _base_0.__class = _class_0 | ||
| 1563 | Base = _class_0 | ||
| 1564 | end | ||
| 1565 | local Sub | ||
| 1566 | do | ||
| 1567 | local _class_0 | ||
| 1568 | local _parent_0 = Base | ||
| 1569 | local _base_0 = { | ||
| 1570 | value = add_some({ | ||
| 1571 | amount = 12, | ||
| 1572 | function(self) | ||
| 1573 | return _class_0.__parent.__base.value(self) + 100 | ||
| 1574 | end | ||
| 1575 | }) | ||
| 1576 | } | ||
| 1577 | if _base_0.__index == nil then | ||
| 1578 | _base_0.__index = _base_0 | ||
| 1579 | end | ||
| 1580 | setmetatable(_base_0, _parent_0.__base) | ||
| 1581 | _class_0 = setmetatable({ | ||
| 1582 | __init = function(self, ...) | ||
| 1583 | return _class_0.__parent.__init(self, ...) | ||
| 1584 | end, | ||
| 1585 | __base = _base_0, | ||
| 1586 | __name = "Sub", | ||
| 1587 | __parent = _parent_0 | ||
| 1588 | }, { | ||
| 1589 | __index = function(cls, name) | ||
| 1590 | local val = rawget(_base_0, name) | ||
| 1591 | if val == nil then | ||
| 1592 | local parent = rawget(cls, "__parent") | ||
| 1593 | if parent then | ||
| 1594 | return parent[name] | ||
| 1595 | end | ||
| 1596 | else | ||
| 1597 | return val | ||
| 1598 | end | ||
| 1599 | end, | ||
| 1600 | __call = function(cls, ...) | ||
| 1601 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1602 | cls.__init(_self_0, ...) | ||
| 1603 | return _self_0 | ||
| 1604 | end | ||
| 1605 | }) | ||
| 1606 | _base_0.__class = _class_0 | ||
| 1607 | if _parent_0.__inherited then | ||
| 1608 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1609 | end | ||
| 1610 | Sub = _class_0 | ||
| 1611 | end | ||
| 1612 | local OtherSub | ||
| 1613 | do | ||
| 1614 | local _class_0 | ||
| 1615 | local _parent_0 = Base | ||
| 1616 | local _base_0 = { | ||
| 1617 | value = (function() | ||
| 1618 | if true then | ||
| 1619 | return function(self) | ||
| 1620 | return 5 + _class_0.__parent.__base.value(self) | ||
| 1621 | end | ||
| 1622 | else | ||
| 1623 | return function(self) | ||
| 1624 | return 2 + _class_0.__parent.__base.value(self) | ||
| 1625 | end | ||
| 1626 | end | ||
| 1627 | end)() | ||
| 1628 | } | ||
| 1629 | if _base_0.__index == nil then | ||
| 1630 | _base_0.__index = _base_0 | ||
| 1631 | end | ||
| 1632 | setmetatable(_base_0, _parent_0.__base) | ||
| 1633 | _class_0 = setmetatable({ | ||
| 1634 | __init = function(self, ...) | ||
| 1635 | return _class_0.__parent.__init(self, ...) | ||
| 1636 | end, | ||
| 1637 | __base = _base_0, | ||
| 1638 | __name = "OtherSub", | ||
| 1639 | __parent = _parent_0 | ||
| 1640 | }, { | ||
| 1641 | __index = function(cls, name) | ||
| 1642 | local val = rawget(_base_0, name) | ||
| 1643 | if val == nil then | ||
| 1644 | local parent = rawget(cls, "__parent") | ||
| 1645 | if parent then | ||
| 1646 | return parent[name] | ||
| 1647 | end | ||
| 1648 | else | ||
| 1649 | return val | ||
| 1650 | end | ||
| 1651 | end, | ||
| 1652 | __call = function(cls, ...) | ||
| 1653 | local _self_0 = setmetatable({ }, _base_0) | ||
| 1654 | cls.__init(_self_0, ...) | ||
| 1655 | return _self_0 | ||
| 1656 | end | ||
| 1657 | }) | ||
| 1658 | _base_0.__class = _class_0 | ||
| 1659 | if _parent_0.__inherited then | ||
| 1660 | _parent_0.__inherited(_parent_0, _class_0) | ||
| 1661 | end | ||
| 1662 | OtherSub = _class_0 | ||
| 1663 | end | ||
| 1664 | assert.same(1 + 100 + 12, Sub():value()) | ||
| 1665 | return assert.same(6, OtherSub():value()) | ||
| 1666 | end) | ||
| 1667 | end) | ||
| 1668 | end) | ||
diff --git a/spec/outputs/test/loops_spec.lua b/spec/outputs/test/loops_spec.lua new file mode 100644 index 0000000..3fc0332 --- /dev/null +++ b/spec/outputs/test/loops_spec.lua | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | return describe("loops", function() | ||
| 2 | return it("should continue", function() | ||
| 3 | local input = { | ||
| 4 | 1, | ||
| 5 | 2, | ||
| 6 | 3, | ||
| 7 | 4, | ||
| 8 | 5, | ||
| 9 | 6 | ||
| 10 | } | ||
| 11 | local output | ||
| 12 | do | ||
| 13 | local _accum_0 = { } | ||
| 14 | local _len_0 = 1 | ||
| 15 | for _index_0 = 1, #input do | ||
| 16 | local x = input[_index_0] | ||
| 17 | local _continue_0 = false | ||
| 18 | repeat | ||
| 19 | if x % 2 == 1 then | ||
| 20 | _continue_0 = true | ||
| 21 | break | ||
| 22 | end | ||
| 23 | _accum_0[_len_0] = x | ||
| 24 | _len_0 = _len_0 + 1 | ||
| 25 | _continue_0 = true | ||
| 26 | until true | ||
| 27 | if not _continue_0 then | ||
| 28 | break | ||
| 29 | end | ||
| 30 | end | ||
| 31 | output = _accum_0 | ||
| 32 | end | ||
| 33 | return assert.same(output, { | ||
| 34 | 2, | ||
| 35 | 4, | ||
| 36 | 6 | ||
| 37 | }) | ||
| 38 | end) | ||
| 39 | end) | ||
