1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/test_returns.coffee

33 lines
540 B
CoffeeScript
Raw Normal View History

# Expression conversion under explicit returns.
2010-07-25 01:23:37 -04:00
first = ->
return 'do' for x in [1,2,3]
2010-07-25 01:23:37 -04:00
second = ->
return ['re' for x in [1,2,3]]
2010-07-25 01:23:37 -04:00
third = ->
return ('mi' for x in [1,2,3])
ok first().join(' ') is 'do do do'
ok second()[0].join(' ') is 're re re'
ok third().join(' ') is 'mi mi mi'
# Testing returns with multiple branches.
2010-07-25 01:23:37 -04:00
func = ->
if false
for a in b
return c if d
else
"word"
ok func() is 'word'
# And with switches.
2010-07-25 01:23:37 -04:00
func = ->
switch 'a'
when 'a' then 42
else return 23
ok func() is 42