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
|
|
|
|
2010-02-16 19:45:25 -05:00
|
|
|
ok result
|
2010-01-25 20:52:33 -05:00
|
|
|
|
|
|
|
|
2010-07-25 01:23:37 -04:00
|
|
|
first = if false then false else second = if false then false else true
|
2010-01-25 20:52:33 -05:00
|
|
|
|
2010-02-16 19:45:25 -05:00
|
|
|
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
|
|
|
|
|
2010-03-10 16:18:17 -05:00
|
|
|
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
|
2010-06-12 19:38:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
# 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')
|
2010-06-12 19:38:14 -04:00
|
|
|
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
|
2010-06-27 13:19:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Testing empty or commented if statements ... should compile:
|
2010-07-25 01:23:37 -04:00
|
|
|
result = if false
|
2010-06-27 13:19:23 -04:00
|
|
|
else if false
|
|
|
|
else
|
|
|
|
|
|
|
|
ok result is undefined
|
|
|
|
|
2010-07-25 01:23:37 -04:00
|
|
|
result = if false
|
2010-06-27 13:19:23 -04:00
|
|
|
# comment
|
|
|
|
else if true
|
|
|
|
# comment
|
|
|
|
else
|
|
|
|
|
|
|
|
ok result is undefined
|
2010-07-06 23:04:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Return an if with no else.
|
2010-07-25 01:23:37 -04:00
|
|
|
func = ->
|
2010-07-06 23:04:35 -04:00
|
|
|
return (if false then callback())
|
|
|
|
|
|
|
|
ok func() is null
|
2010-07-23 23:44:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
# If-to-ternary with instanceof requires parentheses (no comment).
|
|
|
|
if {} instanceof Object
|
|
|
|
ok yes
|
|
|
|
else
|
|
|
|
ok no
|