aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-10-22 00:55:02 +0800
committerLi Jin <dragon-fly@qq.com>2023-10-22 00:55:02 +0800
commit652a8839f885b73fff57942a9db8b26e9cb5233b (patch)
tree0b24bb5610823a831ec0addbba37cb6200203b27 /spec
parentf61a4a1d9a1b979b8a0c2e8a9c194a284f42220f (diff)
downloadyuescript-652a8839f885b73fff57942a9db8b26e9cb5233b.tar.gz
yuescript-652a8839f885b73fff57942a9db8b26e9cb5233b.tar.bz2
yuescript-652a8839f885b73fff57942a9db8b26e9cb5233b.zip
fixing issues from #152.
Diffstat (limited to 'spec')
-rw-r--r--spec/inputs/cond.yue11
-rw-r--r--spec/inputs/in_expression.yue25
-rw-r--r--spec/inputs/lists.yue24
-rw-r--r--spec/inputs/tables.yue20
-rw-r--r--spec/inputs/unicode/cond.yue11
-rw-r--r--spec/inputs/unicode/in_expression.yue21
-rw-r--r--spec/outputs/cond.lua17
-rw-r--r--spec/outputs/in_expression.lua31
-rw-r--r--spec/outputs/lists.lua65
-rw-r--r--spec/outputs/tables.lua83
-rw-r--r--spec/outputs/unicode/cond.lua17
-rw-r--r--spec/outputs/unicode/in_expression.lua31
12 files changed, 257 insertions, 99 deletions
diff --git a/spec/inputs/cond.yue b/spec/inputs/cond.yue
index 638b5c3..df7d78e 100644
--- a/spec/inputs/cond.yue
+++ b/spec/inputs/cond.yue
@@ -226,6 +226,17 @@ do
226 else 226 else
227 2 227 2
228 228
229do
230 condChain = 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5
231
232 v = (x)->
233 print x
234 x
235
236 evaluation = v(1) < v(2) <= v(3)
237
238 evaluation = v(1) > v(2) <= v(3)
239
229nil 240nil
230 241
231 242
diff --git a/spec/inputs/in_expression.yue b/spec/inputs/in_expression.yue
index 6e923e1..6faff4e 100644
--- a/spec/inputs/in_expression.yue
+++ b/spec/inputs/in_expression.yue
@@ -1,28 +1,13 @@
1-a^2 in {1, 2, 3} |> f 1-a^2 in {1, 2, 3} |> f
2 2-a^2 in [1, 2, 3] |> f
3a, b = x(...) not in [1, 3], 2
4
5d = (tb.x.y ...) not in [1, 3]
6 3
7has = "foo" in { "bar", "foo" } 4has = "foo" in { "bar", "foo" }
8 5
9if a in {1} and b in {2, 3, 4} or c in [1, 10] 6if a in {1} and b in {2, 3, 4}
10 print a, b, c 7 print a, b, c
11 8
12switch val 9if a in [1,] and b in [2, 3, 4]
13 when 1, 2, 3 10 print a, b, c
14 print "1, 2, 3"
15
16 when not in (0, 100]
17 print "not (0 < val <= 100)"
18
19 when in [200, 300)
20 print "200 <= val < 300)"
21
22 when not in {333, 444, 555}
23 print "not 333, 444 or 555"
24
25do return y not in (a, b)
26 11
27do 12do
28 exist = item in list 13 exist = item in list
@@ -36,9 +21,11 @@ do
36do 21do
37 item = get! 22 item = get!
38 list = {1, 2, 3} 23 list = {1, 2, 3}
24 list = [1, 2, 3]
39 not_exist = item not in list 25 not_exist = item not in list
40 check item in list 26 check item in list
41 check item in {1, 2, 3} 27 check item in {1, 2, 3}
28 check item in [1, 2, 3]
42 check item(...) in {[1]: 1, [2]: 2, [3]: 3} 29 check item(...) in {[1]: 1, [2]: 2, [3]: 3}
43 30
44do 31do
diff --git a/spec/inputs/lists.yue b/spec/inputs/lists.yue
index 15eb9ab..921cae0 100644
--- a/spec/inputs/lists.yue
+++ b/spec/inputs/lists.yue
@@ -67,6 +67,24 @@ normal = (hello) ->
67test = x 1,2,3,4,5 67test = x 1,2,3,4,5
68print thing for thing in *test 68print thing for thing in *test
69 69
70-> a = b for row in *rows 70_ = -> a = b for row in *rows
71 71
72 72with tb
73 f [a] -- indexing
74 f [a,] -- list with one element
75 print v for v in *f[a,] -- table slicing in for-loop
76 f [] -- empty list
77 f[] = x -- table appending to f
78 [a] = x -- assign to tb[a]
79 [a,] = x -- list destructuring for x
80 [] = x -- table appending to tb
81 c = a in [1] -- check if a in tb[1]
82 c = a in [1,] -- check if a == 1
83 c = a in {1} -- check if a == 1
84 c = a in {1,} -- check if a == 1
85
86do
87 [a, b] = hello
88 [name = "nameless", job = "jobless"] = person
89
90nil
diff --git a/spec/inputs/tables.yue b/spec/inputs/tables.yue
index 0b5af46..53a53ae 100644
--- a/spec/inputs/tables.yue
+++ b/spec/inputs/tables.yue
@@ -40,6 +40,8 @@ ya = { 1,2,3, key: 100, 343, "hello", umm: 232 }
40x = { 1,2, 40x = { 1,2,
41 4343, 343 ,343 } 41 4343, 343 ,343 }
42 42
43x = [ 1,2,
44 4343, 343 ,343 ]
43 45
44g, p = { 46g, p = {
45 1,2, nowy: "yes", 3,4, 47 1,2, nowy: "yes", 3,4,
@@ -52,6 +54,12 @@ annother = {
52 6,7,8 54 6,7,8
53} 55}
54 56
57annother = [
58 1,2,3
59 3,4,5
60 6,7,8
61]
62
55yeah = { 63yeah = {
56 [232]: 3434, "helo" 64 [232]: 3434, "helo"
57 ice: "cake" 65 ice: "cake"
@@ -255,6 +263,11 @@ tbMixA = {
255 11 263 11
256} 264}
257 265
266tbMixA = [
267 ...[i for i = 1, 10]
268 11
269]
270
258tbMixB = { 271tbMixB = {
259 ... ... -- only the first item in vararg been accessed here 272 ... ... -- only the first item in vararg been accessed here
260 ... {...} 273 ... {...}
@@ -262,6 +275,13 @@ tbMixB = {
262 1, 2, 3 275 1, 2, 3
263} 276}
264 277
278tbMixB = [
279 ... ... -- only the first item in vararg been accessed here
280 ... {...}
281 ... {......}
282 1, 2, 3
283]
284
265const template = { 285const template = {
266 foo: "Hello" 286 foo: "Hello"
267 bar: "World" 287 bar: "World"
diff --git a/spec/inputs/unicode/cond.yue b/spec/inputs/unicode/cond.yue
index 362408c..fca6d60 100644
--- a/spec/inputs/unicode/cond.yue
+++ b/spec/inputs/unicode/cond.yue
@@ -226,6 +226,17 @@ do
226 else 226 else
227 2 227 2
228 228
229do
230 链式比较 = 1 < 2 <= 2 < 3 == 3 > 2 >= 1 == 1 < 3 != 5
231
232 值 = (输入)->
233 打印 输入
234 输入
235
236 求值 = 值(1) < 值(2) <= 值(3)
237
238 求值 = 值(1) > 值(2) <= 值(3)
239
229nil 240nil
230 241
231 242
diff --git a/spec/inputs/unicode/in_expression.yue b/spec/inputs/unicode/in_expression.yue
index efaca47..e068cbf 100644
--- a/spec/inputs/unicode/in_expression.yue
+++ b/spec/inputs/unicode/in_expression.yue
@@ -1,29 +1,10 @@
1-变量a^2 in {1, 2, 3} |> 函数 1-变量a^2 in {1, 2, 3} |> 函数
2 2
3变量a, 变量b = 函数x(...) not in [1, 3], 2
4
5变量d = (对象.字段x.字段y ...) not in [1, 3]
6
7在的 = "东" in { "东", "西" } 3在的 = "东" in { "东", "西" }
8 4
9if 变量a in {1} and 变量b in {2, 3, 4} or 变量c in [1, 10] 5if 变量a in {1} and 变量b in {2, 3, 4}
10 打印 变量a, 变量b, 变量c 6 打印 变量a, 变量b, 变量c
11 7
12switch 值
13 when 1, 2, 3
14 打印 "1, 2, 3"
15
16 when not in (0, 100]
17 打印 "非 (0 < 值 <= 100)"
18
19 when in [200, 300)
20 打印 "200 <= 值 < 300)"
21
22 when not in {333, 444, 555}
23 打印 "非 333, 444 或 555"
24
25do return 变量y not in (开始, 结束)
26
27do 8do
28 存在 = 元素 in 表 9 存在 = 元素 in 表
29 检查 元素 in 表 10 检查 元素 in 表
diff --git a/spec/outputs/cond.lua b/spec/outputs/cond.lua
index 1f6aa63..651c14a 100644
--- a/spec/outputs/cond.lua
+++ b/spec/outputs/cond.lua
@@ -345,4 +345,21 @@ do
345 v = 2 345 v = 2
346 end 346 end
347end 347end
348do
349 local condChain = 1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5
350 local v
351 v = function(x)
352 print(x)
353 return x
354 end
355 local evaluation
356 do
357 local _cond_0 = v(2)
358 evaluation = v(1) < _cond_0 and _cond_0 <= v(3)
359 end
360 do
361 local _cond_0 = v(2)
362 evaluation = v(1) > _cond_0 and _cond_0 <= v(3)
363 end
364end
348return nil 365return nil
diff --git a/spec/outputs/in_expression.lua b/spec/outputs/in_expression.lua
index ddba69a..60802c9 100644
--- a/spec/outputs/in_expression.lua
+++ b/spec/outputs/in_expression.lua
@@ -2,43 +2,18 @@ f((function()
2 local _val_0 = -a ^ 2 2 local _val_0 = -a ^ 2
3 return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 3 return 1 == _val_0 or 2 == _val_0 or 3 == _val_0
4end)()) 4end)())
5local a, b = (function(...)
6 local _val_0 = x(...)
7 return not (1 <= _val_0 and _val_0 <= 3)
8end)(...), 2
9local d
10do
11 local _val_0 = (tb.x.y(...))
12 d = not (1 <= _val_0 and _val_0 <= 3)
13end
14local has 5local has
15do 6do
16 local _val_0 = "foo" 7 local _val_0 = "foo"
17 has = "bar" == _val_0 or "foo" == _val_0 8 has = "bar" == _val_0 or "foo" == _val_0
18end 9end
19if (1 == a) and (2 == b or 3 == b or 4 == b) or (function() 10if (1 == a) and (function()
20 local _val_0 = c 11 local _val_0 = b
21 return 1 <= _val_0 and _val_0 <= 10 12 return 2 == _val_0 or 3 == _val_0 or 4 == _val_0
22end)() then 13end)() then
23 print(a, b, c) 14 print(a, b, c)
24end 15end
25do 16do
26 local _exp_0 = val
27 if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 then
28 print("1, 2, 3")
29 elseif not (0 < _exp_0 and _exp_0 <= 100) then
30 print("not (0 < val <= 100)")
31 elseif (200 <= _exp_0 and _exp_0 < 300) then
32 print("200 <= val < 300)")
33 elseif not (333 == _exp_0 or 444 == _exp_0 or 555 == _exp_0) then
34 print("not 333, 444 or 555")
35 end
36end
37do
38 local _val_0 = y
39 return not (a < _val_0 and _val_0 < b)
40end
41do
42 local exist 17 local exist
43 do 18 do
44 local _check_0 = list 19 local _check_0 = list
diff --git a/spec/outputs/lists.lua b/spec/outputs/lists.lua
index 581cc23..e6f306d 100644
--- a/spec/outputs/lists.lua
+++ b/spec/outputs/lists.lua
@@ -273,10 +273,73 @@ for _index_0 = 1, #test do
273 local thing = test[_index_0] 273 local thing = test[_index_0]
274 print(thing) 274 print(thing)
275end 275end
276return function() 276_ = function()
277 local _list_0 = rows 277 local _list_0 = rows
278 for _index_0 = 1, #_list_0 do 278 for _index_0 = 1, #_list_0 do
279 local row = _list_0[_index_0] 279 local row = _list_0[_index_0]
280 a = b 280 a = b
281 end 281 end
282end 282end
283do
284 local _with_0 = tb
285 f(_with_0[a])
286 f({
287 a
288 })
289 local _list_0 = f
290 for _index_0 = a, #_list_0 do
291 local v = _list_0[_index_0]
292 print(v)
293 end
294 f({ })
295 do
296 local _obj_0 = f
297 _obj_0[#_obj_0 + 1] = x
298 end
299 _with_0[a] = x
300 a = x[1]
301 _with_0[#_with_0 + 1] = x
302 do
303 local _check_0 = _with_0[1]
304 local _find_0 = false
305 for _index_0 = 1, #_check_0 do
306 local _item_0 = _check_0[_index_0]
307 if _item_0 == a then
308 _find_0 = true
309 break
310 end
311 end
312 c = _find_0
313 end
314 c = (1 == a)
315 c = (1 == a)
316 do
317 local _check_0 = {
318 1
319 }
320 local _find_0 = false
321 for _index_0 = 1, #_check_0 do
322 local _item_0 = _check_0[_index_0]
323 if _item_0 == a then
324 _find_0 = true
325 break
326 end
327 end
328 c = _find_0
329 end
330end
331do
332 a, b = hello[1], hello[2]
333 local name, job
334 do
335 local _obj_0 = person
336 name, job = _obj_0[1], _obj_0[2]
337 if name == nil then
338 name = "nameless"
339 end
340 if job == nil then
341 job = "jobless"
342 end
343 end
344end
345return nil
diff --git a/spec/outputs/tables.lua b/spec/outputs/tables.lua
index e9df1c4..f836d58 100644
--- a/spec/outputs/tables.lua
+++ b/spec/outputs/tables.lua
@@ -52,6 +52,13 @@ local x = {
52 343, 52 343,
53 343 53 343
54} 54}
55x = {
56 1,
57 2,
58 4343,
59 343,
60 343
61}
55local g, p = { 62local g, p = {
56 1, 63 1,
57 2, 64 2,
@@ -72,6 +79,17 @@ local annother = {
72 7, 79 7,
73 8 80 8
74} 81}
82annother = {
83 1,
84 2,
85 3,
86 3,
87 4,
88 5,
89 6,
90 7,
91 8
92}
75local yeah = { 93local yeah = {
76 [232] = 3434, 94 [232] = 3434,
77 "helo", 95 "helo",
@@ -435,6 +453,27 @@ do
435 _tab_0[#_tab_0 + 1] = 11 453 _tab_0[#_tab_0 + 1] = 11
436 tbMixA = _tab_0 454 tbMixA = _tab_0
437end 455end
456do
457 local _tab_0 = { }
458 local _obj_0
459 do
460 local _accum_0 = { }
461 local _len_0 = 1
462 for i = 1, 10 do
463 _accum_0[_len_0] = i
464 _len_0 = _len_0 + 1
465 end
466 _obj_0 = _accum_0
467 end
468 local _idx_0 = #_tab_0 + 1
469 for _index_0 = 1, #_obj_0 do
470 local _value_0 = _obj_0[_index_0]
471 _tab_0[_idx_0] = _value_0
472 _idx_0 = _idx_0 + 1
473 end
474 _tab_0[#_tab_0 + 1] = 11
475 tbMixA = _tab_0
476end
438local tbMixB 477local tbMixB
439do 478do
440 local _tab_0 = { } 479 local _tab_0 = { }
@@ -489,6 +528,50 @@ do
489 _tab_0[#_tab_0 + 1] = 3 528 _tab_0[#_tab_0 + 1] = 3
490 tbMixB = _tab_0 529 tbMixB = _tab_0
491end 530end
531do
532 local _tab_0 = { }
533 local _obj_0 = ...
534 local _idx_0 = #_tab_0 + 1
535 for _index_0 = 1, #_obj_0 do
536 local _value_0 = _obj_0[_index_0]
537 _tab_0[_idx_0] = _value_0
538 _idx_0 = _idx_0 + 1
539 end
540 local _obj_1 = {
541 ...
542 }
543 local _idx_1 = #_tab_0 + 1
544 for _index_0 = 1, #_obj_1 do
545 local _value_0 = _obj_1[_index_0]
546 _tab_0[_idx_1] = _value_0
547 _idx_1 = _idx_1 + 1
548 end
549 local _obj_2
550 do
551 local _tab_1 = { }
552 local _obj_3 = ...
553 local _idx_2 = 1
554 for _key_0, _value_0 in pairs(_obj_3) do
555 if _idx_2 == _key_0 then
556 _tab_1[#_tab_1 + 1] = _value_0
557 _idx_2 = _idx_2 + 1
558 else
559 _tab_1[_key_0] = _value_0
560 end
561 end
562 _obj_2 = _tab_1
563 end
564 local _idx_2 = #_tab_0 + 1
565 for _index_0 = 1, #_obj_2 do
566 local _value_0 = _obj_2[_index_0]
567 _tab_0[_idx_2] = _value_0
568 _idx_2 = _idx_2 + 1
569 end
570 _tab_0[#_tab_0 + 1] = 1
571 _tab_0[#_tab_0 + 1] = 2
572 _tab_0[#_tab_0 + 1] = 3
573 tbMixB = _tab_0
574end
492local template <const> = { 575local template <const> = {
493 foo = "Hello", 576 foo = "Hello",
494 bar = "World", 577 bar = "World",
diff --git a/spec/outputs/unicode/cond.lua b/spec/outputs/unicode/cond.lua
index f972dea..9a4ccb9 100644
--- a/spec/outputs/unicode/cond.lua
+++ b/spec/outputs/unicode/cond.lua
@@ -351,4 +351,21 @@ do
351 _u53d8_u91cfv = 2 351 _u53d8_u91cfv = 2
352 end 352 end
353end 353end
354do
355 local _u94fe_u5f0f_u6bd4_u8f83 = 1 < 2 and 2 <= 2 and 2 < 3 and 3 == 3 and 3 > 2 and 2 >= 1 and 1 == 1 and 1 < 3 and 3 ~= 5
356 local _u503c
357 _u503c = function(_u8f93_u5165)
358 _u6253_u5370(_u8f93_u5165)
359 return _u8f93_u5165
360 end
361 local _u6c42_u503c
362 do
363 local _cond_0 = _u503c(2)
364 _u6c42_u503c = _u503c(1) < _cond_0 and _cond_0 <= _u503c(3)
365 end
366 do
367 local _cond_0 = _u503c(2)
368 _u6c42_u503c = _u503c(1) > _cond_0 and _cond_0 <= _u503c(3)
369 end
370end
354return nil 371return nil
diff --git a/spec/outputs/unicode/in_expression.lua b/spec/outputs/unicode/in_expression.lua
index 62aad05..7c584f3 100644
--- a/spec/outputs/unicode/in_expression.lua
+++ b/spec/outputs/unicode/in_expression.lua
@@ -2,43 +2,18 @@ _u51fd_u6570((function()
2 local _val_0 = -_u53d8_u91cfa ^ 2 2 local _val_0 = -_u53d8_u91cfa ^ 2
3 return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 3 return 1 == _val_0 or 2 == _val_0 or 3 == _val_0
4end)()) 4end)())
5local _u53d8_u91cfa, _u53d8_u91cfb = (function(...)
6 local _val_0 = _u51fd_u6570x(...)
7 return not (1 <= _val_0 and _val_0 <= 3)
8end)(...), 2
9local _u53d8_u91cfd
10do
11 local _val_0 = (_u5bf9_u8c61["字段x"]["字段y"](...))
12 _u53d8_u91cfd = not (1 <= _val_0 and _val_0 <= 3)
13end
14local _u5728_u7684 5local _u5728_u7684
15do 6do
16 local _val_0 = "东" 7 local _val_0 = "东"
17 _u5728_u7684 = "东" == _val_0 or "西" == _val_0 8 _u5728_u7684 = "东" == _val_0 or "西" == _val_0
18end 9end
19if (1 == _u53d8_u91cfa) and (2 == _u53d8_u91cfb or 3 == _u53d8_u91cfb or 4 == _u53d8_u91cfb) or (function() 10if (1 == _u53d8_u91cfa) and (function()
20 local _val_0 = _u53d8_u91cfc 11 local _val_0 = _u53d8_u91cfb
21 return 1 <= _val_0 and _val_0 <= 10 12 return 2 == _val_0 or 3 == _val_0 or 4 == _val_0
22end)() then 13end)() then
23 _u6253_u5370(_u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc) 14 _u6253_u5370(_u53d8_u91cfa, _u53d8_u91cfb, _u53d8_u91cfc)
24end 15end
25do 16do
26 local _exp_0 = _u503c
27 if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 then
28 _u6253_u5370("1, 2, 3")
29 elseif not (0 < _exp_0 and _exp_0 <= 100) then
30 _u6253_u5370("非 (0 < 值 <= 100)")
31 elseif (200 <= _exp_0 and _exp_0 < 300) then
32 _u6253_u5370("200 <= 值 < 300)")
33 elseif not (333 == _exp_0 or 444 == _exp_0 or 555 == _exp_0) then
34 _u6253_u5370("非 333, 444 或 555")
35 end
36end
37do
38 local _val_0 = _u53d8_u91cfy
39 return not (_u5f00_u59cb < _val_0 and _val_0 < _u7ed3_u675f)
40end
41do
42 local _u5b58_u5728 17 local _u5b58_u5728
43 do 18 do
44 local _check_0 = _u8868 19 local _check_0 = _u8868