mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
refactored test_break.coffee
This commit is contained in:
23
test/break.coffee
Normal file
23
test/break.coffee
Normal file
@@ -0,0 +1,23 @@
|
||||
########
|
||||
## Break
|
||||
########
|
||||
|
||||
# break at the top level
|
||||
(->
|
||||
for i in [1,2,3]
|
||||
result = i
|
||||
if i == 2
|
||||
break
|
||||
eq result, 2
|
||||
)()
|
||||
|
||||
# break *not* at the top level
|
||||
(->
|
||||
someFunc = () ->
|
||||
i = 0
|
||||
while ++i < 3
|
||||
result = i
|
||||
break if i > 1
|
||||
result
|
||||
eq someFunc(), 2
|
||||
)()
|
||||
@@ -1,28 +0,0 @@
|
||||
# Test with break at the top level.
|
||||
array = [1,2,3]
|
||||
callWithLambda = (l) -> null
|
||||
for i in array
|
||||
result = callWithLambda(->)
|
||||
if i == 2
|
||||
console.log "i = 2"
|
||||
else
|
||||
break
|
||||
|
||||
ok result is null
|
||||
|
||||
|
||||
# Test with break *not* at the top level.
|
||||
someFunc = (input) ->
|
||||
takesLambda = (l) -> null
|
||||
for i in [1,2]
|
||||
result = takesLambda(->)
|
||||
if input == 1
|
||||
return 1
|
||||
else
|
||||
break
|
||||
|
||||
return 2
|
||||
|
||||
ok someFunc(1) is 1
|
||||
ok someFunc(2) is 2
|
||||
|
||||
Reference in New Issue
Block a user