1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/generators.coffee
2013-12-19 18:08:25 -08:00

44 lines
735 B
CoffeeScript

# Generators
# -----------------
#
# * Generator Definition
test "generator as argument", ->
ok ->* 1
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
test "bound generator", ->
obj =
bound: ->
do =>*
this
unbound: ->
do ->*
this
nested: ->
do =>*
do =>*
do =>*
this
eq obj, obj.bound().next().value
ok obj isnt obj.unbound().next().value
eq obj, obj.nested().next().value.next().value.next().value