Created
January 15, 2018 04:54
-
-
Save GeoffreyBooth/c0e0d539c13ae181ee719627151d3402 to your computer and use it in GitHub Desktop.
CoffeeScript tests affected by PR #4854
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "Ensure that the closure wrapper preserves local variables.", -> | |
obj = {} | |
for method in ['one', 'two', 'three'] then do (method) -> | |
obj[method] = -> | |
"I'm " + method | |
ok obj.one() is "I'm one" | |
ok obj.two() is "I'm two" | |
ok obj.three() is "I'm three" | |
test "Even a convoluted one.", -> | |
funcs = [] | |
for i in [1..3] | |
do (i) -> | |
x = i * 2 | |
((z)-> | |
funcs.push -> z + ' ' + i | |
)(x) | |
ok (func() for func in funcs).join(', ') is '2 1, 4 2, 6 3' | |
funcs = [] | |
results = for i in [1..3] | |
do (i) -> | |
z = (x * 3 for x in [1..i]) | |
((a, b, c) -> [a, b, c].join(' ')).apply this, z | |
ok results.join(', ') is '3 , 3 6 , 3 6 9' | |
test "Scoped loop pattern matching.", -> | |
a = [[0], [1]] | |
funcs = [] | |
for [v] in a | |
do (v) -> | |
funcs.push -> v | |
eq funcs[0](), 0 | |
eq funcs[1](), 1 | |
test "Issue #948. Capturing loop variables.", -> | |
funcs = [] | |
list = -> | |
[1, 2, 3] | |
for y in list() | |
do (y) -> | |
z = y | |
funcs.push -> "y is #{y} and z is #{z}" | |
eq funcs[1](), "y is 2 and z is 2" | |
test "Comprehensions over function literals.", -> | |
a = 0 | |
for f in [-> a = 1] | |
do (f) -> | |
do f | |
eq a, 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment