diff options
Diffstat (limited to 'spec/inputs/comprehension.yue')
-rw-r--r-- | spec/inputs/comprehension.yue | 52 |
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 | |||
4 | items = {1,2,3,4,5,6} | ||
5 | out = {k,k*2 for k in items} | ||
6 | |||
7 | |||
8 | x = hello: "world", okay: 2323 | ||
9 | |||
10 | copy = {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 | |||
23 | n1 = [i for i=1,10] | ||
24 | n2 = [i for i=1,10 when i % 2 == 1] | ||
25 | |||
26 | aa = [{x,y} for x=1,10 for y=5,14] | ||
27 | bb = [y for thing in y for i=1,10] | ||
28 | cc = [y for i=1,10 for thing in y] | ||
29 | dd = [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 | |||
35 | j = [a for {a,b,c} in things] | ||
36 | k = [a for {a,b,c} in *things] | ||
37 | i = [hello for {:hello, :world} in *things] | ||
38 | |||
39 | hj = {a,c for {a,b,c} in things} | ||
40 | hk = {a,c for {a,b,c} in *things} | ||
41 | hi = {hello,world for {:hello, :world} in *things} | ||
42 | |||
43 | ok(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 | |||
50 | list = [item?\invoke 123 for item in items] | ||
51 | |||
52 | nil | ||