diff options
author | Li Jin <dragon-fly@qq.com> | 2023-07-20 18:25:10 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-07-20 18:25:10 +0800 |
commit | fcb480618f162817572947cfed96b1ba0d6c5a44 (patch) | |
tree | a7fb68bc263730a665d49648b01771742bb8dc24 /spec | |
parent | 2faf55a8217690988bc2cab7cc65541dc2215dc1 (diff) | |
download | yuescript-0.17.8.tar.gz yuescript-0.17.8.tar.bz2 yuescript-0.17.8.zip |
fix wrong codes generation for in-expression.v0.17.8
Diffstat (limited to '')
-rw-r--r-- | spec/inputs/in_expression.yue | 9 | ||||
-rw-r--r-- | spec/outputs/in_expression.lua | 74 |
2 files changed, 69 insertions, 14 deletions
diff --git a/spec/inputs/in_expression.yue b/spec/inputs/in_expression.yue index 4080016..6e923e1 100644 --- a/spec/inputs/in_expression.yue +++ b/spec/inputs/in_expression.yue | |||
@@ -39,7 +39,14 @@ do | |||
39 | not_exist = item not in list | 39 | not_exist = item not in list |
40 | check item in list | 40 | check item in list |
41 | check item in {1, 2, 3} | 41 | check item in {1, 2, 3} |
42 | check item in {[1]: 1, [2]: 2, [3]: 3} | 42 | check item(...) in {[1]: 1, [2]: 2, [3]: 3} |
43 | |||
44 | do | ||
45 | check -> x in tb | ||
46 | check -> x not in tb | ||
47 | local x, tb | ||
48 | check -> return x in tb | ||
49 | check -> x not in tb | ||
43 | 50 | ||
44 | nil | 51 | nil |
45 | 52 | ||
diff --git a/spec/outputs/in_expression.lua b/spec/outputs/in_expression.lua index ccc5fd0..ddba69a 100644 --- a/spec/outputs/in_expression.lua +++ b/spec/outputs/in_expression.lua | |||
@@ -66,15 +66,19 @@ do | |||
66 | end | 66 | end |
67 | do | 67 | do |
68 | local item = get() | 68 | local item = get() |
69 | local exist = (function() | 69 | local exist |
70 | do | ||
70 | local _check_0 = list | 71 | local _check_0 = list |
72 | local _find_0 = false | ||
71 | for _index_0 = 1, #_check_0 do | 73 | for _index_0 = 1, #_check_0 do |
72 | if _check_0[_index_0] == item then | 74 | local _item_0 = _check_0[_index_0] |
73 | return true | 75 | if _item_0 == item then |
76 | _find_0 = true | ||
77 | break | ||
74 | end | 78 | end |
75 | end | 79 | end |
76 | return false | 80 | exist = _find_0 |
77 | end)() | 81 | end |
78 | check((function() | 82 | check((function() |
79 | local _check_0 = list | 83 | local _check_0 = list |
80 | for _index_0 = 1, #_check_0 do | 84 | for _index_0 = 1, #_check_0 do |
@@ -92,14 +96,18 @@ do | |||
92 | 2, | 96 | 2, |
93 | 3 | 97 | 3 |
94 | } | 98 | } |
95 | local not_exist = not (#list > 0 and (function() | 99 | local not_exist |
100 | do | ||
101 | local _find_0 = false | ||
96 | for _index_0 = 1, #list do | 102 | for _index_0 = 1, #list do |
97 | if list[_index_0] == item then | 103 | local _item_0 = list[_index_0] |
98 | return true | 104 | if _item_0 == item then |
105 | _find_0 = true | ||
106 | break | ||
99 | end | 107 | end |
100 | end | 108 | end |
101 | return false | 109 | not_exist = not _find_0 |
102 | end)()) | 110 | end |
103 | check((#list > 0 and (function() | 111 | check((#list > 0 and (function() |
104 | for _index_0 = 1, #list do | 112 | for _index_0 = 1, #list do |
105 | if list[_index_0] == item then | 113 | if list[_index_0] == item then |
@@ -109,18 +117,58 @@ do | |||
109 | return false | 117 | return false |
110 | end)())) | 118 | end)())) |
111 | check((1 == item or 2 == item or 3 == item)) | 119 | check((1 == item or 2 == item or 3 == item)) |
112 | check((function() | 120 | check((function(...) |
113 | local _check_0 = { | 121 | local _check_0 = { |
114 | [1] = 1, | 122 | [1] = 1, |
115 | [2] = 2, | 123 | [2] = 2, |
116 | [3] = 3 | 124 | [3] = 3 |
117 | } | 125 | } |
126 | local _val_0 = item(...) | ||
118 | for _index_0 = 1, #_check_0 do | 127 | for _index_0 = 1, #_check_0 do |
119 | if _check_0[_index_0] == item then | 128 | if _check_0[_index_0] == _val_0 then |
120 | return true | 129 | return true |
121 | end | 130 | end |
122 | end | 131 | end |
123 | return false | 132 | return false |
124 | end)()) | 133 | end)(...)) |
134 | end | ||
135 | do | ||
136 | check(function() | ||
137 | local _check_0 = tb | ||
138 | local _val_0 = x | ||
139 | for _index_0 = 1, #_check_0 do | ||
140 | if _check_0[_index_0] == _val_0 then | ||
141 | return true | ||
142 | end | ||
143 | end | ||
144 | return false | ||
145 | end) | ||
146 | check(function() | ||
147 | local _check_0 = tb | ||
148 | local _val_0 = x | ||
149 | for _index_0 = 1, #_check_0 do | ||
150 | if _check_0[_index_0] == _val_0 then | ||
151 | return false | ||
152 | end | ||
153 | end | ||
154 | return true | ||
155 | end) | ||
156 | local x, tb | ||
157 | check(function() | ||
158 | for _index_0 = 1, #tb do | ||
159 | if tb[_index_0] == x then | ||
160 | return true | ||
161 | end | ||
162 | end | ||
163 | return false | ||
164 | end) | ||
165 | check(function() | ||
166 | for _index_0 = 1, #tb do | ||
167 | if tb[_index_0] == x then | ||
168 | return false | ||
169 | end | ||
170 | end | ||
171 | return true | ||
172 | end) | ||
125 | end | 173 | end |
126 | return nil | 174 | return nil |