aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs
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/inputs
parentf61a4a1d9a1b979b8a0c2e8a9c194a284f42220f (diff)
downloadyuescript-652a8839f885b73fff57942a9db8b26e9cb5233b.tar.gz
yuescript-652a8839f885b73fff57942a9db8b26e9cb5233b.tar.bz2
yuescript-652a8839f885b73fff57942a9db8b26e9cb5233b.zip
fixing issues from #152.
Diffstat (limited to 'spec/inputs')
-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
6 files changed, 70 insertions, 42 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 表