diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-26 17:45:26 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-26 17:45:56 +0800 |
| commit | e02321107277a63e7dcb12ab163c9942ac101b87 (patch) | |
| tree | f38c6f2fbf4ee35df4938933dbc1e645733356f4 /spec/outputs/test/attrib_spec.lua | |
| parent | 5d5b657f606b5939062983b1f90c3359d542672e (diff) | |
| download | yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.gz yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.tar.bz2 yuescript-e02321107277a63e7dcb12ab163c9942ac101b87.zip | |
Updated tests.
Diffstat (limited to 'spec/outputs/test/attrib_spec.lua')
| -rw-r--r-- | spec/outputs/test/attrib_spec.lua | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/spec/outputs/test/attrib_spec.lua b/spec/outputs/test/attrib_spec.lua new file mode 100644 index 0000000..d459bbb --- /dev/null +++ b/spec/outputs/test/attrib_spec.lua | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | return describe("attrib", function() | ||
| 2 | it("should support const attribute", function() | ||
| 3 | do | ||
| 4 | local x <const> = 10 | ||
| 5 | return assert.same(x, 10) | ||
| 6 | end | ||
| 7 | end) | ||
| 8 | it("should support const with multiple variables", function() | ||
| 9 | do | ||
| 10 | local a <const>, b <const>, c <const> = 1, 2, 3 | ||
| 11 | assert.same(a, 1) | ||
| 12 | assert.same(b, 2) | ||
| 13 | return assert.same(c, 3) | ||
| 14 | end | ||
| 15 | end) | ||
| 16 | it("should support close attribute", function() | ||
| 17 | do | ||
| 18 | local x <close> = setmetatable({ }, { | ||
| 19 | __close = function() end | ||
| 20 | }) | ||
| 21 | return assert.same("table", type(x)) | ||
| 22 | end | ||
| 23 | end) | ||
| 24 | it("should work with destructuring", function() | ||
| 25 | do | ||
| 26 | local a, b | ||
| 27 | do | ||
| 28 | local _obj_0 = { | ||
| 29 | a = 1, | ||
| 30 | b = 2 | ||
| 31 | } | ||
| 32 | a, b = _obj_0.a, _obj_0.b | ||
| 33 | end | ||
| 34 | assert.same(a, 1) | ||
| 35 | return assert.same(b, 2) | ||
| 36 | end | ||
| 37 | end) | ||
| 38 | it("should work in conditional", function() | ||
| 39 | do | ||
| 40 | local flag = true | ||
| 41 | local x | ||
| 42 | if flag then | ||
| 43 | x = 5 | ||
| 44 | end | ||
| 45 | return assert.same(x, 5) | ||
| 46 | end | ||
| 47 | end) | ||
| 48 | it("should work with switch", function() | ||
| 49 | do | ||
| 50 | local y | ||
| 51 | do | ||
| 52 | local _exp_0 = 2 | ||
| 53 | if 2 == _exp_0 then | ||
| 54 | y = 100 | ||
| 55 | else | ||
| 56 | y = 0 | ||
| 57 | end | ||
| 58 | end | ||
| 59 | return assert.same(y, 100) | ||
| 60 | end | ||
| 61 | end) | ||
| 62 | it("should work with table literals", function() | ||
| 63 | do | ||
| 64 | local a, b | ||
| 65 | do | ||
| 66 | local _obj_0 = { | ||
| 67 | 1, | ||
| 68 | 2 | ||
| 69 | } | ||
| 70 | a, b = _obj_0[1], _obj_0[2] | ||
| 71 | end | ||
| 72 | assert.same(a, 1) | ||
| 73 | return assert.same(b, 2) | ||
| 74 | end | ||
| 75 | end) | ||
| 76 | return it("should support close in expressions", function() | ||
| 77 | do | ||
| 78 | local result | ||
| 79 | if true then | ||
| 80 | result = setmetatable({ | ||
| 81 | value = 42, | ||
| 82 | }, { | ||
| 83 | __close = function() end | ||
| 84 | }) | ||
| 85 | else | ||
| 86 | result = setmetatable({ | ||
| 87 | value = 0, | ||
| 88 | }, { | ||
| 89 | __close = function() end | ||
| 90 | }) | ||
| 91 | end | ||
| 92 | local _close_0 <close> = result | ||
| 93 | return assert.same(result.value, 42) | ||
| 94 | end | ||
| 95 | end) | ||
| 96 | end) | ||
