We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dcf9532 commit 7735804Copy full SHA for 7735804
spec/comprehension_spec.moon
@@ -42,9 +42,34 @@ describe "comprehension", ->
42
assert.same output, {2,4,6,8}
43
44
45
+describe "table comprehension", ->
46
it "should copy table", ->
47
input = { 1,2,3, hello: "world", thing: true }
48
output = {k,v for k,v in pairs input }
49
50
assert.is_true input != output
51
assert.same input, output
52
+
53
+ it "should support when", ->
54
+ input = {
55
+ color: "red"
56
+ name: "fast"
57
+ width: 123
58
+ }
59
60
+ output = { k,v for k,v in pairs input when k != "color" }
61
62
+ assert.same output, { name: "fast", width: 123 }
63
64
+ it "should do unpack", ->
65
+ input = {4,9,16,25}
66
+ output = {i, math.sqrt i for i in *input}
67
68
+ assert.same output, { [4]: 2, [9]: 3, [16]: 4, [25]: 5 }
69
70
+ it "should use multiple return values", ->
71
+ input = { {"hello", "world"}, {"foo", "bar"} }
72
+ output = { unpack tuple for tuple in *input }
73
74
+ assert.same output, { foo: "bar", hello: "world" }
75
0 commit comments