diff options
| author | Li Jin <dragon-fly@qq.com> | 2026-01-27 00:30:56 +0000 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2026-01-27 00:30:56 +0000 |
| commit | 7c2a92b82e9808d3c5ea29b47d1c59d663fe984a (patch) | |
| tree | ceba95c48bd8d5d9fff3d1206483ddf073c0e03d /spec/inputs/test/close_attribute_spec.yue | |
| parent | e70e63a9737ed3a9e72f1329901075498190e6b4 (diff) | |
| download | yuescript-compiler-improvements.tar.gz yuescript-compiler-improvements.tar.bz2 yuescript-compiler-improvements.zip | |
Add compiler improvements and comprehensive test suitecompiler-improvements
- Fixed path option handling to avoid semicolon concatenation issues
- Added exception handling for std::length_error and general exceptions
- Added comprehensive test specifications for advanced language features
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'spec/inputs/test/close_attribute_spec.yue')
| -rw-r--r-- | spec/inputs/test/close_attribute_spec.yue | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/spec/inputs/test/close_attribute_spec.yue b/spec/inputs/test/close_attribute_spec.yue new file mode 100644 index 0000000..2354df7 --- /dev/null +++ b/spec/inputs/test/close_attribute_spec.yue | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | describe "close attribute", -> | ||
| 2 | it "should declare close variable", -> | ||
| 3 | closed = false | ||
| 4 | do | ||
| 5 | close _ = <close>: -> closed = true | ||
| 6 | assert.is_true closed | ||
| 7 | |||
| 8 | it "should work with metatable syntax", -> | ||
| 9 | called = false | ||
| 10 | do | ||
| 11 | close _ = <close>: -> called = true | ||
| 12 | assert.is_true called | ||
| 13 | |||
| 14 | it "should handle multiple close scopes", -> | ||
| 15 | order = [] | ||
| 16 | do | ||
| 17 | close first = <close>: -> table.insert order, "first" | ||
| 18 | close second = <close>: -> table.insert order, "second" | ||
| 19 | assert.same order, {"second", "first"} | ||
| 20 | |||
| 21 | it "should work with resources", -> | ||
| 22 | resource_opened = false | ||
| 23 | resource_closed = false | ||
| 24 | |||
| 25 | do | ||
| 26 | resource_opened = true | ||
| 27 | close _ = <close>: -> resource_closed = true | ||
| 28 | |||
| 29 | assert.is_true resource_opened | ||
| 30 | assert.is_true resource_closed | ||
| 31 | |||
| 32 | it "should support close in function", -> | ||
| 33 | closed = false | ||
| 34 | fn = -> | ||
| 35 | close _ = <close>: -> closed = true | ||
| 36 | return "result" | ||
| 37 | |||
| 38 | result = fn! | ||
| 39 | assert.same result, "result" | ||
| 40 | assert.is_true closed | ||
| 41 | |||
| 42 | it "should work with fat arrow", -> | ||
| 43 | closed = false | ||
| 44 | obj = | ||
| 45 | value: 10 | ||
| 46 | close_method: <close>: => | ||
| 47 | closed = true | ||
| 48 | |||
| 49 | do | ||
| 50 | close _ = obj | ||
| 51 | |||
| 52 | assert.is_true closed | ||
| 53 | |||
| 54 | it "should handle nested close scopes", -> | ||
| 55 | outer_closed = false | ||
| 56 | inner_closed = false | ||
| 57 | |||
| 58 | do | ||
| 59 | close outer = <close>: -> outer_closed = true | ||
| 60 | do | ||
| 61 | close inner = <close>: -> inner_closed = true | ||
| 62 | |||
| 63 | assert.is_true inner_closed | ||
| 64 | assert.is_true outer_closed | ||
| 65 | |||
| 66 | it "should work with conditional close", -> | ||
| 67 | closed = false | ||
| 68 | should_close = true | ||
| 69 | |||
| 70 | if should_close | ||
| 71 | close _ = <close>: -> closed = true | ||
| 72 | |||
| 73 | assert.is_true closed | ||
| 74 | |||
| 75 | it "should support close in loop", -> | ||
| 76 | closed_count = 0 | ||
| 77 | for i = 1, 3 | ||
| 78 | do | ||
| 79 | close _ = <close>: -> closed_count += 1 | ||
| 80 | |||
| 81 | assert.same closed_count, 3 | ||
| 82 | |||
| 83 | it "should work with table destructuring", -> | ||
| 84 | closed = false | ||
| 85 | tb = {close: <close>: -> closed = true} | ||
| 86 | do | ||
| 87 | {:close} = tb | ||
| 88 | assert.is_true closed | ||
| 89 | |||
| 90 | it "should handle close with return value", -> | ||
| 91 | closed = false | ||
| 92 | fn = -> | ||
| 93 | close _ = <close>: -> closed = true | ||
| 94 | return 42 | ||
| 95 | |||
| 96 | result = fn! | ||
| 97 | assert.same result, 42 | ||
| 98 | assert.is_true closed | ||
| 99 | |||
| 100 | it "should work with error handling", -> | ||
| 101 | closed = false | ||
| 102 | error_thrown = false | ||
| 103 | |||
| 104 | do | ||
| 105 | close _ = <close>: -> closed = true | ||
| 106 | error_thrown = true | ||
| 107 | |||
| 108 | assert.is_true closed | ||
| 109 | assert.is_true error_thrown | ||
| 110 | |||
| 111 | it "should support close in varargs function", -> | ||
| 112 | closed = false | ||
| 113 | fn = (...) -> | ||
| 114 | close _ = <close>: -> closed = true | ||
| 115 | {...} | ||
| 116 | |||
| 117 | result = fn 1, 2, 3 | ||
| 118 | assert.same result, {1, 2, 3} | ||
| 119 | assert.is_true closed | ||
| 120 | |||
| 121 | it "should work with multiple variables", -> | ||
| 122 | first_closed = false | ||
| 123 | second_closed = false | ||
| 124 | |||
| 125 | do | ||
| 126 | close first = <close>: -> first_closed = true | ||
| 127 | close second = <close>: -> second_closed = true | ||
| 128 | |||
| 129 | assert.is_true first_closed | ||
| 130 | assert.is_true second_closed | ||
| 131 | |||
| 132 | it "should handle close in try block", -> | ||
| 133 | closed = false | ||
| 134 | success = false | ||
| 135 | |||
| 136 | success = try | ||
| 137 | close _ = <close>: -> closed = true | ||
| 138 | true | ||
| 139 | catch err | ||
| 140 | false | ||
| 141 | |||
| 142 | assert.is_true success | ||
| 143 | assert.is_true closed | ||
