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/outputs/test/in_expression_spec.lua | |
| 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/outputs/test/in_expression_spec.lua')
| -rw-r--r-- | spec/outputs/test/in_expression_spec.lua | 489 |
1 files changed, 489 insertions, 0 deletions
diff --git a/spec/outputs/test/in_expression_spec.lua b/spec/outputs/test/in_expression_spec.lua new file mode 100644 index 0000000..fc118c2 --- /dev/null +++ b/spec/outputs/test/in_expression_spec.lua | |||
| @@ -0,0 +1,489 @@ | |||
| 1 | local _anon_func_0 = function(items) | ||
| 2 | local _val_0 = 3 | ||
| 3 | for _index_0 = 1, #items do | ||
| 4 | if items[_index_0] == _val_0 then | ||
| 5 | return true | ||
| 6 | end | ||
| 7 | end | ||
| 8 | return false | ||
| 9 | end | ||
| 10 | local _anon_func_1 = function(items) | ||
| 11 | local _val_0 = 10 | ||
| 12 | for _index_0 = 1, #items do | ||
| 13 | if items[_index_0] == _val_0 then | ||
| 14 | return true | ||
| 15 | end | ||
| 16 | end | ||
| 17 | return false | ||
| 18 | end | ||
| 19 | local _anon_func_2 = function(chars) | ||
| 20 | local _val_0 = "b" | ||
| 21 | for _index_0 = 1, #chars do | ||
| 22 | if chars[_index_0] == _val_0 then | ||
| 23 | return true | ||
| 24 | end | ||
| 25 | end | ||
| 26 | return false | ||
| 27 | end | ||
| 28 | local _anon_func_3 = function(chars) | ||
| 29 | local _val_0 = "z" | ||
| 30 | for _index_0 = 1, #chars do | ||
| 31 | if chars[_index_0] == _val_0 then | ||
| 32 | return true | ||
| 33 | end | ||
| 34 | end | ||
| 35 | return false | ||
| 36 | end | ||
| 37 | local _anon_func_4 = function(obj) | ||
| 38 | local _val_0 = "x" | ||
| 39 | for _index_0 = 1, #obj do | ||
| 40 | if obj[_index_0] == _val_0 then | ||
| 41 | return true | ||
| 42 | end | ||
| 43 | end | ||
| 44 | return false | ||
| 45 | end | ||
| 46 | local _anon_func_5 = function(obj) | ||
| 47 | local _val_0 = "y" | ||
| 48 | for _index_0 = 1, #obj do | ||
| 49 | if obj[_index_0] == _val_0 then | ||
| 50 | return true | ||
| 51 | end | ||
| 52 | end | ||
| 53 | return false | ||
| 54 | end | ||
| 55 | local _anon_func_6 = function(obj) | ||
| 56 | local _val_0 = "w" | ||
| 57 | for _index_0 = 1, #obj do | ||
| 58 | if obj[_index_0] == _val_0 then | ||
| 59 | return true | ||
| 60 | end | ||
| 61 | end | ||
| 62 | return false | ||
| 63 | end | ||
| 64 | local _anon_func_7 = function(items) | ||
| 65 | local _val_0 = 1 | ||
| 66 | for _index_0 = 1, #items do | ||
| 67 | if items[_index_0] == _val_0 then | ||
| 68 | return true | ||
| 69 | end | ||
| 70 | end | ||
| 71 | return false | ||
| 72 | end | ||
| 73 | local _anon_func_8 = function(items) | ||
| 74 | local _val_0 = "two" | ||
| 75 | for _index_0 = 1, #items do | ||
| 76 | if items[_index_0] == _val_0 then | ||
| 77 | return true | ||
| 78 | end | ||
| 79 | end | ||
| 80 | return false | ||
| 81 | end | ||
| 82 | local _anon_func_9 = function(items) | ||
| 83 | local _val_0 = true | ||
| 84 | for _index_0 = 1, #items do | ||
| 85 | if items[_index_0] == _val_0 then | ||
| 86 | return true | ||
| 87 | end | ||
| 88 | end | ||
| 89 | return false | ||
| 90 | end | ||
| 91 | local _anon_func_10 = function(items) | ||
| 92 | local _val_0 = false | ||
| 93 | for _index_0 = 1, #items do | ||
| 94 | if items[_index_0] == _val_0 then | ||
| 95 | return true | ||
| 96 | end | ||
| 97 | end | ||
| 98 | return false | ||
| 99 | end | ||
| 100 | local _anon_func_11 = function(empty) | ||
| 101 | local _val_0 = 1 | ||
| 102 | for _index_0 = 1, #empty do | ||
| 103 | if empty[_index_0] == _val_0 then | ||
| 104 | return true | ||
| 105 | end | ||
| 106 | end | ||
| 107 | return false | ||
| 108 | end | ||
| 109 | local _anon_func_12 = function(empty) | ||
| 110 | local _val_0 = "test" | ||
| 111 | for _index_0 = 1, #empty do | ||
| 112 | if empty[_index_0] == _val_0 then | ||
| 113 | return true | ||
| 114 | end | ||
| 115 | end | ||
| 116 | return false | ||
| 117 | end | ||
| 118 | local _anon_func_13 = function(items) | ||
| 119 | local _val_0 = 2 | ||
| 120 | for _index_0 = 1, #items do | ||
| 121 | if items[_index_0] == _val_0 then | ||
| 122 | return true | ||
| 123 | end | ||
| 124 | end | ||
| 125 | return false | ||
| 126 | end | ||
| 127 | local _anon_func_14 = function(items) | ||
| 128 | local _val_0 = 4 | ||
| 129 | for _index_0 = 1, #items do | ||
| 130 | if items[_index_0] == _val_0 then | ||
| 131 | return true | ||
| 132 | end | ||
| 133 | end | ||
| 134 | return false | ||
| 135 | end | ||
| 136 | local _anon_func_15 = function(items) | ||
| 137 | local _val_0 = 2 | ||
| 138 | for _index_0 = 1, #items do | ||
| 139 | if items[_index_0] == _val_0 then | ||
| 140 | return true | ||
| 141 | end | ||
| 142 | end | ||
| 143 | return false | ||
| 144 | end | ||
| 145 | local _anon_func_16 = function(nested) | ||
| 146 | local _val_0 = { | ||
| 147 | 1, | ||
| 148 | 2 | ||
| 149 | } | ||
| 150 | for _index_0 = 1, #nested do | ||
| 151 | if nested[_index_0] == _val_0 then | ||
| 152 | return true | ||
| 153 | end | ||
| 154 | end | ||
| 155 | return false | ||
| 156 | end | ||
| 157 | local _anon_func_17 = function(nested) | ||
| 158 | local _val_0 = { | ||
| 159 | 1, | ||
| 160 | 3 | ||
| 161 | } | ||
| 162 | for _index_0 = 1, #nested do | ||
| 163 | if nested[_index_0] == _val_0 then | ||
| 164 | return true | ||
| 165 | end | ||
| 166 | end | ||
| 167 | return false | ||
| 168 | end | ||
| 169 | local _anon_func_18 = function(bools) | ||
| 170 | local _val_0 = true | ||
| 171 | for _index_0 = 1, #bools do | ||
| 172 | if bools[_index_0] == _val_0 then | ||
| 173 | return true | ||
| 174 | end | ||
| 175 | end | ||
| 176 | return false | ||
| 177 | end | ||
| 178 | local _anon_func_19 = function(bools) | ||
| 179 | local _val_0 = false | ||
| 180 | for _index_0 = 1, #bools do | ||
| 181 | if bools[_index_0] == _val_0 then | ||
| 182 | return true | ||
| 183 | end | ||
| 184 | end | ||
| 185 | return false | ||
| 186 | end | ||
| 187 | local _anon_func_20 = function(i, items) | ||
| 188 | for _index_0 = 1, #items do | ||
| 189 | if items[_index_0] == i then | ||
| 190 | return true | ||
| 191 | end | ||
| 192 | end | ||
| 193 | return false | ||
| 194 | end | ||
| 195 | local _anon_func_21 = function(key1, tb) | ||
| 196 | for _index_0 = 1, #tb do | ||
| 197 | if tb[_index_0] == key1 then | ||
| 198 | return true | ||
| 199 | end | ||
| 200 | end | ||
| 201 | return false | ||
| 202 | end | ||
| 203 | local _anon_func_22 = function(key2, tb) | ||
| 204 | for _index_0 = 1, #tb do | ||
| 205 | if tb[_index_0] == key2 then | ||
| 206 | return true | ||
| 207 | end | ||
| 208 | end | ||
| 209 | return false | ||
| 210 | end | ||
| 211 | local _anon_func_23 = function(get_items) | ||
| 212 | local _check_0 = get_items() | ||
| 213 | local _val_0 = 2 | ||
| 214 | for _index_0 = 1, #_check_0 do | ||
| 215 | if _check_0[_index_0] == _val_0 then | ||
| 216 | return true | ||
| 217 | end | ||
| 218 | end | ||
| 219 | return false | ||
| 220 | end | ||
| 221 | local _anon_func_24 = function(get_items) | ||
| 222 | local _check_0 = get_items() | ||
| 223 | local _val_0 = 5 | ||
| 224 | for _index_0 = 1, #_check_0 do | ||
| 225 | if _check_0[_index_0] == _val_0 then | ||
| 226 | return true | ||
| 227 | end | ||
| 228 | end | ||
| 229 | return false | ||
| 230 | end | ||
| 231 | local _anon_func_25 = function(items) | ||
| 232 | local _val_0 = nil | ||
| 233 | for _index_0 = 1, #items do | ||
| 234 | if items[_index_0] == _val_0 then | ||
| 235 | return true | ||
| 236 | end | ||
| 237 | end | ||
| 238 | return false | ||
| 239 | end | ||
| 240 | local _anon_func_26 = function(items) | ||
| 241 | local _val_0 = 1 | ||
| 242 | for _index_0 = 1, #items do | ||
| 243 | if items[_index_0] == _val_0 then | ||
| 244 | return true | ||
| 245 | end | ||
| 246 | end | ||
| 247 | return false | ||
| 248 | end | ||
| 249 | local _anon_func_27 = function(obj) | ||
| 250 | local _val_0 = "name" | ||
| 251 | for _index_0 = 1, #obj do | ||
| 252 | if obj[_index_0] == _val_0 then | ||
| 253 | return true | ||
| 254 | end | ||
| 255 | end | ||
| 256 | return false | ||
| 257 | end | ||
| 258 | local _anon_func_28 = function(obj) | ||
| 259 | local _val_0 = "value" | ||
| 260 | for _index_0 = 1, #obj do | ||
| 261 | if obj[_index_0] == _val_0 then | ||
| 262 | return true | ||
| 263 | end | ||
| 264 | end | ||
| 265 | return false | ||
| 266 | end | ||
| 267 | local _anon_func_29 = function(obj) | ||
| 268 | local _val_0 = "missing" | ||
| 269 | for _index_0 = 1, #obj do | ||
| 270 | if obj[_index_0] == _val_0 then | ||
| 271 | return true | ||
| 272 | end | ||
| 273 | end | ||
| 274 | return false | ||
| 275 | end | ||
| 276 | local _anon_func_30 = function(items) | ||
| 277 | local _val_0 = 2 | ||
| 278 | for _index_0 = 1, #items do | ||
| 279 | if items[_index_0] == _val_0 then | ||
| 280 | return true | ||
| 281 | end | ||
| 282 | end | ||
| 283 | return false | ||
| 284 | end | ||
| 285 | local _anon_func_31 = function(allowed, item) | ||
| 286 | for _index_0 = 1, #allowed do | ||
| 287 | if allowed[_index_0] == item then | ||
| 288 | return true | ||
| 289 | end | ||
| 290 | end | ||
| 291 | return false | ||
| 292 | end | ||
| 293 | return describe("in expression", function() | ||
| 294 | it("should check value in table", function() | ||
| 295 | local items = { | ||
| 296 | 1, | ||
| 297 | 2, | ||
| 298 | 3, | ||
| 299 | 4, | ||
| 300 | 5 | ||
| 301 | } | ||
| 302 | assert.is_true(_anon_func_0(items)) | ||
| 303 | return assert.is_false(_anon_func_1(items)) | ||
| 304 | end) | ||
| 305 | it("should work with strings", function() | ||
| 306 | local chars = { | ||
| 307 | "a", | ||
| 308 | "b", | ||
| 309 | "c" | ||
| 310 | } | ||
| 311 | assert.is_true(_anon_func_2(chars)) | ||
| 312 | return assert.is_false(_anon_func_3(chars)) | ||
| 313 | end) | ||
| 314 | it("should check keys in table", function() | ||
| 315 | local obj = { | ||
| 316 | x = 1, | ||
| 317 | y = 2, | ||
| 318 | z = 3 | ||
| 319 | } | ||
| 320 | assert.is_true(_anon_func_4(obj)) | ||
| 321 | assert.is_true(_anon_func_5(obj)) | ||
| 322 | return assert.is_false(_anon_func_6(obj)) | ||
| 323 | end) | ||
| 324 | it("should work with mixed types", function() | ||
| 325 | local items = { | ||
| 326 | 1, | ||
| 327 | "two", | ||
| 328 | true, | ||
| 329 | nil | ||
| 330 | } | ||
| 331 | assert.is_true(_anon_func_7(items)) | ||
| 332 | assert.is_true(_anon_func_8(items)) | ||
| 333 | assert.is_true(_anon_func_9(items)) | ||
| 334 | return assert.is_false(_anon_func_10(items)) | ||
| 335 | end) | ||
| 336 | it("should handle empty table", function() | ||
| 337 | local empty = { } | ||
| 338 | assert.is_false(_anon_func_11(empty)) | ||
| 339 | return assert.is_false(_anon_func_12(empty)) | ||
| 340 | end) | ||
| 341 | it("should work in conditional", function() | ||
| 342 | local items = { | ||
| 343 | 1, | ||
| 344 | 2, | ||
| 345 | 3 | ||
| 346 | } | ||
| 347 | local result | ||
| 348 | if _anon_func_13(items) then | ||
| 349 | result = "found" | ||
| 350 | else | ||
| 351 | result = "not found" | ||
| 352 | end | ||
| 353 | return assert.same(result, "found") | ||
| 354 | end) | ||
| 355 | it("should support negation", function() | ||
| 356 | local items = { | ||
| 357 | 1, | ||
| 358 | 2, | ||
| 359 | 3 | ||
| 360 | } | ||
| 361 | assert.is_true(not (_anon_func_14(items))) | ||
| 362 | return assert.is_false(not (_anon_func_15(items))) | ||
| 363 | end) | ||
| 364 | it("should work with nested tables", function() | ||
| 365 | local nested = { | ||
| 366 | { | ||
| 367 | 1, | ||
| 368 | 2 | ||
| 369 | }, | ||
| 370 | { | ||
| 371 | 3, | ||
| 372 | 4 | ||
| 373 | }, | ||
| 374 | { | ||
| 375 | 5, | ||
| 376 | 6 | ||
| 377 | } | ||
| 378 | } | ||
| 379 | assert.is_true(_anon_func_16(nested)) | ||
| 380 | return assert.is_false(_anon_func_17(nested)) | ||
| 381 | end) | ||
| 382 | it("should handle boolean values", function() | ||
| 383 | local bools = { | ||
| 384 | true, | ||
| 385 | false | ||
| 386 | } | ||
| 387 | assert.is_true(_anon_func_18(bools)) | ||
| 388 | return assert.is_true(_anon_func_19(bools)) | ||
| 389 | end) | ||
| 390 | it("should work in loop", function() | ||
| 391 | local items = { | ||
| 392 | 1, | ||
| 393 | 2, | ||
| 394 | 3, | ||
| 395 | 4, | ||
| 396 | 5 | ||
| 397 | } | ||
| 398 | local count = 0 | ||
| 399 | for i = 1, 10 do | ||
| 400 | if (#items > 0 and _anon_func_20(i, items)) then | ||
| 401 | count = count + 1 | ||
| 402 | end | ||
| 403 | end | ||
| 404 | return assert.same(count, 5) | ||
| 405 | end) | ||
| 406 | it("should support table as value", function() | ||
| 407 | local key1 = { | ||
| 408 | a = 1 | ||
| 409 | } | ||
| 410 | local key2 = { | ||
| 411 | b = 2 | ||
| 412 | } | ||
| 413 | local tb = { | ||
| 414 | [key1] = "first", | ||
| 415 | [key2] = "second" | ||
| 416 | } | ||
| 417 | assert.is_true((#tb > 0 and _anon_func_21(key1, tb))) | ||
| 418 | return assert.is_true((#tb > 0 and _anon_func_22(key2, tb))) | ||
| 419 | end) | ||
| 420 | it("should work with function results", function() | ||
| 421 | local get_items | ||
| 422 | get_items = function() | ||
| 423 | return { | ||
| 424 | 1, | ||
| 425 | 2, | ||
| 426 | 3 | ||
| 427 | } | ||
| 428 | end | ||
| 429 | assert.is_true(_anon_func_23(get_items)) | ||
| 430 | return assert.is_false(_anon_func_24(get_items)) | ||
| 431 | end) | ||
| 432 | it("should handle nil in table", function() | ||
| 433 | local items = { | ||
| 434 | 1, | ||
| 435 | nil, | ||
| 436 | 3 | ||
| 437 | } | ||
| 438 | assert.is_true(_anon_func_25(items)) | ||
| 439 | return assert.is_true(_anon_func_26(items)) | ||
| 440 | end) | ||
| 441 | it("should work with string keys", function() | ||
| 442 | local obj = { | ||
| 443 | name = "test", | ||
| 444 | value = 42 | ||
| 445 | } | ||
| 446 | assert.is_true(_anon_func_27(obj)) | ||
| 447 | assert.is_true(_anon_func_28(obj)) | ||
| 448 | return assert.is_false(_anon_func_29(obj)) | ||
| 449 | end) | ||
| 450 | it("should support complex expressions", function() | ||
| 451 | local items = { | ||
| 452 | 1, | ||
| 453 | 2, | ||
| 454 | 3 | ||
| 455 | } | ||
| 456 | local result = (_anon_func_30(items)) and "yes" or "no" | ||
| 457 | return assert.same(result, "yes") | ||
| 458 | end) | ||
| 459 | return it("should work in comprehension", function() | ||
| 460 | local source = { | ||
| 461 | 1, | ||
| 462 | 2, | ||
| 463 | 3, | ||
| 464 | 4, | ||
| 465 | 5 | ||
| 466 | } | ||
| 467 | local allowed = { | ||
| 468 | 2, | ||
| 469 | 4 | ||
| 470 | } | ||
| 471 | local result | ||
| 472 | do | ||
| 473 | local _accum_0 = { } | ||
| 474 | local _len_0 = 1 | ||
| 475 | for _index_0 = 1, #source do | ||
| 476 | local item = source[_index_0] | ||
| 477 | if (#allowed > 0 and _anon_func_31(allowed, item)) then | ||
| 478 | _accum_0[_len_0] = item | ||
| 479 | _len_0 = _len_0 + 1 | ||
| 480 | end | ||
| 481 | end | ||
| 482 | result = _accum_0 | ||
| 483 | end | ||
| 484 | return assert.same(result, { | ||
| 485 | 2, | ||
| 486 | 4 | ||
| 487 | }) | ||
| 488 | end) | ||
| 489 | end) | ||
