diff options
author | Li Jin <dragon-fly@qq.com> | 2023-06-07 09:42:50 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-06-07 09:42:50 +0800 |
commit | 2a3e50752ade96c3b5d6b1103937bef0f6b31157 (patch) | |
tree | f7ae2654ac96009a9e5dbe9667e480cc920a2868 /spec | |
parent | 738154d37dd4ec20b09acd0f9f81601d0dc069ba (diff) | |
download | yuescript-2a3e50752ade96c3b5d6b1103937bef0f6b31157.tar.gz yuescript-2a3e50752ade96c3b5d6b1103937bef0f6b31157.tar.bz2 yuescript-2a3e50752ade96c3b5d6b1103937bef0f6b31157.zip |
add new syntax of in-expression.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/inputs/in_expression.yue | 26 | ||||
-rw-r--r-- | spec/outputs/in_expression.lua | 36 |
2 files changed, 62 insertions, 0 deletions
diff --git a/spec/inputs/in_expression.yue b/spec/inputs/in_expression.yue new file mode 100644 index 0000000..2756fe8 --- /dev/null +++ b/spec/inputs/in_expression.yue | |||
@@ -0,0 +1,26 @@ | |||
1 | -a^2 in {1, 2, 3} |> f | ||
2 | |||
3 | a, b = x(...) not in [1, 3], 2 | ||
4 | |||
5 | d = (tb.x.y ...) not in [1, 3] | ||
6 | |||
7 | if a in {1} and b in {2, 3, 4} or c in [1, 10] | ||
8 | print a, b, c | ||
9 | |||
10 | switch val | ||
11 | when 1, 2, 3 | ||
12 | print "1, 2, 3" | ||
13 | |||
14 | when not in (0, 100] | ||
15 | print "not (0 < val <= 100)" | ||
16 | |||
17 | when in [200, 300) | ||
18 | print "200 <= val < 300)" | ||
19 | |||
20 | when not in {333, 444, 555} | ||
21 | print "not 333, 444 or 555" | ||
22 | |||
23 | do return y not in (a, b) | ||
24 | |||
25 | nil | ||
26 | |||
diff --git a/spec/outputs/in_expression.lua b/spec/outputs/in_expression.lua new file mode 100644 index 0000000..061431f --- /dev/null +++ b/spec/outputs/in_expression.lua | |||
@@ -0,0 +1,36 @@ | |||
1 | f((function() | ||
2 | local _val_0 = -a ^ 2 | ||
3 | return 1 == _val_0 or 2 == _val_0 or 3 == _val_0 | ||
4 | end)()) | ||
5 | local a, b = (function(...) | ||
6 | local _val_0 = x(...) | ||
7 | return not (1 <= _val_0 and _val_0 <= 3) | ||
8 | end)(...), 2 | ||
9 | local d | ||
10 | do | ||
11 | local _val_0 = (tb.x.y(...)) | ||
12 | d = not (1 <= _val_0 and _val_0 <= 3) | ||
13 | end | ||
14 | if (1 == a) and (2 == b or 3 == b or 4 == b) or (function() | ||
15 | local _val_0 = c | ||
16 | return 1 <= _val_0 and _val_0 <= 10 | ||
17 | end)() then | ||
18 | print(a, b, c) | ||
19 | end | ||
20 | do | ||
21 | local _exp_0 = val | ||
22 | if 1 == _exp_0 or 2 == _exp_0 or 3 == _exp_0 then | ||
23 | print("1, 2, 3") | ||
24 | elseif not (0 < _exp_0 and _exp_0 <= 100) then | ||
25 | print("not (0 < val <= 100)") | ||
26 | elseif (200 <= _exp_0 and _exp_0 < 300) then | ||
27 | print("200 <= val < 300)") | ||
28 | elseif not (333 == _exp_0 or 444 == _exp_0 or 555 == _exp_0) then | ||
29 | print("not 333, 444 or 555") | ||
30 | end | ||
31 | end | ||
32 | do | ||
33 | local _val_0 = y | ||
34 | return not (a < _val_0 and _val_0 < b) | ||
35 | end | ||
36 | return nil | ||