refactored test_break.coffee

This commit is contained in:
Michael Ficarra
2010-12-04 01:44:08 -05:00
parent cf45da33f6
commit eba73f6844
2 changed files with 23 additions and 28 deletions

23
test/break.coffee Normal file
View 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
)()

View File

@@ -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