diff options
| author | Li Jin <dragon-fly@qq.com> | 2025-11-21 12:21:04 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2025-11-21 12:21:04 +0800 |
| commit | 43dde2fff316051d03968e8efd313f19b53112fc (patch) | |
| tree | ae3f99ce6edcd397b75002003048518ee33bae5b /spec | |
| parent | b462de9d09d4708490161c7c16858bce2c9cb9b6 (diff) | |
| download | yuescript-main.tar.gz yuescript-main.tar.bz2 yuescript-main.zip | |
* Added error check for mixed use of tabs and spaces.
* Supported SimpleTable destructuring for ForEach syntax.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/inputs/destructure.yue | 10 | ||||
| -rw-r--r-- | spec/inputs/funcs.yue | 4 | ||||
| -rw-r--r-- | spec/inputs/string.yue | 4 | ||||
| -rw-r--r-- | spec/inputs/unicode/funcs.yue | 2 | ||||
| -rw-r--r-- | spec/inputs/unicode/vararg.yue | 4 | ||||
| -rw-r--r-- | spec/inputs/vararg.yue | 4 | ||||
| -rw-r--r-- | spec/inputs/with.yue | 4 | ||||
| -rw-r--r-- | spec/outputs/destructure.lua | 20 | ||||
| -rw-r--r-- | spec/outputs/string.lua | 2 |
9 files changed, 42 insertions, 12 deletions
diff --git a/spec/inputs/destructure.yue b/spec/inputs/destructure.yue index b6250d0..179056c 100644 --- a/spec/inputs/destructure.yue +++ b/spec/inputs/destructure.yue | |||
| @@ -278,5 +278,15 @@ do | |||
| 278 | do | 278 | do |
| 279 | {a, :abc, b, :def, ...sub, d, e} = tb | 279 | {a, :abc, b, :def, ...sub, d, e} = tb |
| 280 | 280 | ||
| 281 | do | ||
| 282 | for {:a, :b} in *items | ||
| 283 | print a, b | ||
| 284 | |||
| 285 | for :a, :b in *items | ||
| 286 | print a, b | ||
| 287 | |||
| 288 | for :body in pairs data | ||
| 289 | print body if body | ||
| 290 | |||
| 281 | nil | 291 | nil |
| 282 | 292 | ||
diff --git a/spec/inputs/funcs.yue b/spec/inputs/funcs.yue index 6b1669b..d19c2d1 100644 --- a/spec/inputs/funcs.yue +++ b/spec/inputs/funcs.yue | |||
| @@ -98,7 +98,7 @@ f( | |||
| 98 | 98 | ||
| 99 | x = (a, | 99 | x = (a, |
| 100 | b) -> | 100 | b) -> |
| 101 | print "what" | 101 | print "what" |
| 102 | 102 | ||
| 103 | 103 | ||
| 104 | y = (a="hi", | 104 | y = (a="hi", |
| @@ -211,7 +211,7 @@ do | |||
| 211 | print "kv:", k, v | 211 | print "kv:", k, v |
| 212 | print "rest count:", select "#", ... | 212 | print "rest count:", select "#", ... |
| 213 | macro gen = (fname) -> | | 213 | macro gen = (fname) -> | |
| 214 | #{fname} = ({:a, :b = 0}) -> print a, b | 214 | #{fname} = ({:a, :b = 0}) -> print a, b |
| 215 | $gen foo | 215 | $gen foo |
| 216 | t1 = (:a, x) -> print a, x | 216 | t1 = (:a, x) -> print a, x |
| 217 | t2 = (:a) -> print a | 217 | t2 = (:a) -> print a |
diff --git a/spec/inputs/string.yue b/spec/inputs/string.yue index 1f0fba8..611205d 100644 --- a/spec/inputs/string.yue +++ b/spec/inputs/string.yue | |||
| @@ -100,8 +100,8 @@ do | |||
| 100 | next: 123 | 100 | next: 123 |
| 101 | str = | | 101 | str = | |
| 102 | list: | 102 | list: |
| 103 | - "one" | 103 | - "one" |
| 104 | - "two" | 104 | - "two" |
| 105 | str = | | 105 | str = | |
| 106 | -- comment | 106 | -- comment |
| 107 | content text | 107 | content text |
diff --git a/spec/inputs/unicode/funcs.yue b/spec/inputs/unicode/funcs.yue index c563356..cb35500 100644 --- a/spec/inputs/unicode/funcs.yue +++ b/spec/inputs/unicode/funcs.yue | |||
| @@ -98,7 +98,7 @@ _无效变量 = -> 真名 if 某物 | |||
| 98 | 98 | ||
| 99 | 变量x = (参数a, | 99 | 变量x = (参数a, |
| 100 | 参数b) -> | 100 | 参数b) -> |
| 101 | 打印 "什么" | 101 | 打印 "什么" |
| 102 | 102 | ||
| 103 | 103 | ||
| 104 | 变量y = (参数a="hi", | 104 | 变量y = (参数a="hi", |
diff --git a/spec/inputs/unicode/vararg.yue b/spec/inputs/unicode/vararg.yue index e59e114..b508fbb 100644 --- a/spec/inputs/unicode/vararg.yue +++ b/spec/inputs/unicode/vararg.yue | |||
| @@ -55,12 +55,12 @@ | |||
| 55 | _ = -> | 55 | _ = -> |
| 56 | 列表 = {1, 2, 3, 4, 5} | 56 | 列表 = {1, 2, 3, 4, 5} |
| 57 | 函数名 = (确定) -> | 57 | 函数名 = (确定) -> |
| 58 | 确定, table.unpack 列表 | 58 | 确定, table.unpack 列表 |
| 59 | 确定, ... = 函数名 true | 59 | 确定, ... = 函数名 true |
| 60 | 打印 确定, ... | 60 | 打印 确定, ... |
| 61 | 61 | ||
| 62 | 多参数函数 = -> | 62 | 多参数函数 = -> |
| 63 | 10, nil, 20, nil, 30 | 63 | 10, nil, 20, nil, 30 |
| 64 | 64 | ||
| 65 | ... = 多参数函数! | 65 | ... = 多参数函数! |
| 66 | 打印 select "#", ... | 66 | 打印 select "#", ... |
diff --git a/spec/inputs/vararg.yue b/spec/inputs/vararg.yue index 941cd97..6100250 100644 --- a/spec/inputs/vararg.yue +++ b/spec/inputs/vararg.yue | |||
| @@ -55,12 +55,12 @@ join = (...) -> | |||
| 55 | _ = -> | 55 | _ = -> |
| 56 | list = {1, 2, 3, 4, 5} | 56 | list = {1, 2, 3, 4, 5} |
| 57 | fn = (ok) -> | 57 | fn = (ok) -> |
| 58 | ok, table.unpack list | 58 | ok, table.unpack list |
| 59 | ok, ... = fn true | 59 | ok, ... = fn true |
| 60 | print ok, ... | 60 | print ok, ... |
| 61 | 61 | ||
| 62 | fn_many_args = -> | 62 | fn_many_args = -> |
| 63 | 10, nil, 20, nil, 30 | 63 | 10, nil, 20, nil, 30 |
| 64 | 64 | ||
| 65 | ... = fn_many_args! | 65 | ... = fn_many_args! |
| 66 | print select "#", ... | 66 | print select "#", ... |
diff --git a/spec/inputs/with.yue b/spec/inputs/with.yue index 2256833..19ed2a7 100644 --- a/spec/inputs/with.yue +++ b/spec/inputs/with.yue | |||
| @@ -167,7 +167,7 @@ do | |||
| 167 | 167 | ||
| 168 | do | 168 | do |
| 169 | a = for i = 1, 100 | 169 | a = for i = 1, 100 |
| 170 | with? x := tb[i] | 170 | with? x := tb[i] |
| 171 | break x if .id := 1 | 171 | break x if .id := 1 |
| 172 | 172 | ||
| 173 | nil | 173 | nil |
diff --git a/spec/outputs/destructure.lua b/spec/outputs/destructure.lua index ba216b5..4e19aca 100644 --- a/spec/outputs/destructure.lua +++ b/spec/outputs/destructure.lua | |||
| @@ -711,4 +711,24 @@ do | |||
| 711 | return _accum_0 | 711 | return _accum_0 |
| 712 | end)(), _obj_0[#_obj_0 - 1], _obj_0[#_obj_0] | 712 | end)(), _obj_0[#_obj_0 - 1], _obj_0[#_obj_0] |
| 713 | end | 713 | end |
| 714 | do | ||
| 715 | local _list_0 = items | ||
| 716 | for _index_0 = 1, #_list_0 do | ||
| 717 | local _des_0 = _list_0[_index_0] | ||
| 718 | local a, b = _des_0.a, _des_0.b | ||
| 719 | print(a, b) | ||
| 720 | end | ||
| 721 | local _list_1 = items | ||
| 722 | for _index_0 = 1, #_list_1 do | ||
| 723 | local _des_0 = _list_1[_index_0] | ||
| 724 | local a, b = _des_0.a, _des_0.b | ||
| 725 | print(a, b) | ||
| 726 | end | ||
| 727 | for _des_0 in pairs(data) do | ||
| 728 | local body = _des_0.body | ||
| 729 | if body then | ||
| 730 | print(body) | ||
| 731 | end | ||
| 732 | end | ||
| 733 | end | ||
| 714 | return nil | 734 | return nil |
diff --git a/spec/outputs/string.lua b/spec/outputs/string.lua index b536e6d..bdfd676 100644 --- a/spec/outputs/string.lua +++ b/spec/outputs/string.lua | |||
| @@ -52,7 +52,7 @@ do | |||
| 52 | str = "user: " .. tostring(name) .. "\nid: " .. tostring(id) | 52 | str = "user: " .. tostring(name) .. "\nid: " .. tostring(id) |
| 53 | str = "path: \"C:\\\\Program Files\\\\App\"\ndesc: 'single \"quote\" test'" | 53 | str = "path: \"C:\\\\Program Files\\\\App\"\ndesc: 'single \"quote\" test'" |
| 54 | str = "key: value \nnext: 123 " | 54 | str = "key: value \nnext: 123 " |
| 55 | str = "list:\n - \"one\"\n - \"two\"" | 55 | str = "list:\n\t- \"one\"\n\t- \"two\"" |
| 56 | str = "-- comment\ncontent text\n-- comment" | 56 | str = "-- comment\ncontent text\n-- comment" |
| 57 | str = tostring(1 + 2) .. '\n' .. tostring(2 + 3) .. '\n' .. tostring("a" .. "b") | 57 | str = tostring(1 + 2) .. '\n' .. tostring(2 + 3) .. '\n' .. tostring("a" .. "b") |
| 58 | local obj = { | 58 | local obj = { |
