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

46 lines
753 B
CoffeeScript
Raw Normal View History

2013-11-29 23:58:26 -05:00
# Generators
# -----------------
#
2013-11-29 23:58:26 -05:00
# * Generator Definition
2013-12-19 21:08:25 -05:00
test "generator as argument", ->
ok ->* 1
2013-11-29 23:58:26 -05:00
2013-12-19 21:08:25 -05:00
test "generator definition", ->
x = ->*
yield 0
yield 1
yield 2
2013-12-23 22:32:25 -05:00
y = do ->*
yield* 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
2013-12-19 21:08:25 -05:00
eq obj, obj.bound().next().value
ok obj isnt obj.unbound().next().value
eq obj, obj.nested().next().value.next().value.next().value