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