added a test for generators

This commit is contained in:
Andreas Lubbe
2013-11-29 20:58:26 -08:00
parent 9941050120
commit f11ca9888f

35
test/generators.coffee Normal file
View File

@@ -0,0 +1,35 @@
# Generators
# -----------------
# * Generator Definition
# ensure that these tests are only run if generators are available
generatorsAreAvailable = ->
for execArg in process.execArgv
if execArg.match 'harmony'
return 1
return 0
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