1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/test_if.coffee

93 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2010-07-25 01:23:37 -04:00
a = b = d = true
c = false
2009-12-24 03:12:07 -05:00
2010-07-25 01:23:37 -04:00
result = if a
2009-12-24 03:12:07 -05:00
if b
2009-12-28 23:08:02 -05:00
if c then false else
2009-12-24 03:12:07 -05:00
if d
2009-12-28 23:08:02 -05:00
true
2009-12-24 03:12:07 -05:00
ok result
2010-07-25 01:23:37 -04:00
first = if false then false else second = if false then false else true
ok first
ok second
2010-02-13 02:00:39 -05:00
2010-07-25 01:23:37 -04:00
result = if false
2010-02-13 02:00:39 -05:00
false
else if NaN
false
else
true
ok result
2010-04-27 19:35:15 -04:00
# Testing unless.
2010-07-25 01:23:37 -04:00
result = unless true
2010-04-27 19:35:15 -04:00
10
else
11
ok result is 11
# Nested inline if statements.
2010-07-25 01:23:37 -04:00
echo = (x) -> x
result = if true then echo((if false then 'xxx' else 'y') + 'a')
ok result is 'ya'
2010-06-26 17:21:30 -04:00
# Testing inline funcs with inline if-elses.
2010-07-25 01:23:37 -04:00
func = -> if 1 < 0.5 then 1 else -1
2010-06-26 17:21:30 -04:00
ok func() is -1
# Testing empty or commented if statements ... should compile:
2010-07-25 01:23:37 -04:00
result = if false
else if false
else
ok result is undefined
2010-07-25 01:23:37 -04:00
result = if false
# comment
else if true
# comment
else
ok result is undefined
# Return an if with no else.
2010-07-25 01:23:37 -04:00
func = ->
return if false then callback()
ok func() is null
func = ->
return unless false then 100 else -100
ok func() is 100
ident = (x) -> x
result = ident if false then 300 else 100
ok result is 100
# If-to-ternary with instanceof requires parentheses (no comment).
if {} instanceof Object
ok yes
else
ok no
2010-07-26 07:40:18 -04:00
try
{} + {}
ok yes
catch e
ok no