2013-11-29 23:58:26 -05:00
|
|
|
# Generators
|
|
|
|
# -----------------
|
|
|
|
|
|
|
|
# * Generator Definition
|
|
|
|
|
|
|
|
# ensure that these tests are only run if generators are available
|
|
|
|
generatorsAreAvailable = ->
|
2013-11-30 14:45:19 -05:00
|
|
|
for execArg in process.execArgv when execArg in ['--harmony', '--harmony-generators']
|
|
|
|
return yes
|
|
|
|
no
|
2013-11-29 23:58:26 -05:00
|
|
|
|
|
|
|
if generatorsAreAvailable()
|
|
|
|
|
|
|
|
# Using the keyword yield should not cause a syntax error.
|
|
|
|
-> yield 0
|
|
|
|
|
|
|
|
test "Generator Definition", ->
|
|
|
|
x = ->
|
|
|
|
yield 0
|
|
|
|
yield 1
|
|
|
|
yield 2
|
|
|
|
y = x()
|
|
|
|
z = y.next()
|
|
|
|
eq z.value, 0
|
|
|
|
eq z.done, false
|
|
|
|
z = y.next()
|
|
|
|
eq z.value, 1
|
|
|
|
eq z.done, false
|
|
|
|
z = y.next()
|
|
|
|
eq z.value, 2
|
|
|
|
eq z.done, false
|
|
|
|
z = y.next()
|
|
|
|
eq z.value, undefined
|
|
|
|
eq z.done, true
|