Skip to content

Commit 7735804

Browse files
committed
more comprehension specs
1 parent dcf9532 commit 7735804

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

spec/comprehension_spec.moon

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,34 @@ describe "comprehension", ->
4242
assert.same output, {2,4,6,8}
4343

4444

45+
describe "table comprehension", ->
4546
it "should copy table", ->
4647
input = { 1,2,3, hello: "world", thing: true }
4748
output = {k,v for k,v in pairs input }
4849

4950
assert.is_true input != output
5051
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

Comments
 (0)