aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/comprehension.yue
diff options
context:
space:
mode:
Diffstat (limited to 'spec/inputs/comprehension.yue')
-rw-r--r--spec/inputs/comprehension.yue52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/inputs/comprehension.yue b/spec/inputs/comprehension.yue
new file mode 100644
index 0000000..b6adb94
--- /dev/null
+++ b/spec/inputs/comprehension.yue
@@ -0,0 +1,52 @@
1
2-- see lists.moon for list comprehension tests
3
4items = {1,2,3,4,5,6}
5out = {k,k*2 for k in items}
6
7
8x = hello: "world", okay: 2323
9
10copy = {k,v for k,v in pairs x when k != "okay"}
11
12--
13
14_ = { unpack(x) for x in yes }
15_ = { unpack(x) for x in *yes }
16
17_ = { xxxx for x in yes }
18_ = { unpack [a*i for i, a in ipairs x] for x in *{{1,2}, {3,4}} }
19
20
21--
22
23n1 = [i for i=1,10]
24n2 = [i for i=1,10 when i % 2 == 1]
25
26aa = [{x,y} for x=1,10 for y=5,14]
27bb = [y for thing in y for i=1,10]
28cc = [y for i=1,10 for thing in y]
29dd = [y for i=1,10 when cool for thing in y when x > 3 when c + 3]
30
31_ = {"hello", "world" for i=1,10}
32
33--
34
35j = [a for {a,b,c} in things]
36k = [a for {a,b,c} in *things]
37i = [hello for {:hello, :world} in *things]
38
39hj = {a,c for {a,b,c} in things}
40hk = {a,c for {a,b,c} in *things}
41hi = {hello,world for {:hello, :world} in *things}
42
43ok(a,b,c) for {a,b,c} in things
44
45--
46
47_ = [item for item in *items[1 + 2,3+4]]
48_ = [item for item in *items[hello! * 4, 2 - thing[4]]]
49
50list = [item?\invoke 123 for item in items]
51
52nil