2009-12-24 04:33:59 -05:00
|
|
|
num: 10
|
|
|
|
|
|
|
|
result: switch num
|
2009-12-28 23:08:02 -05:00
|
|
|
when 5 then false
|
|
|
|
when 'a'
|
|
|
|
true
|
|
|
|
true
|
|
|
|
false
|
|
|
|
when 10 then true
|
2010-01-09 13:25:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
# Mid-switch comment with whitespace
|
|
|
|
# and multi line
|
2009-12-28 23:08:02 -05:00
|
|
|
when 11 then false
|
|
|
|
else false
|
2010-01-09 13:25:44 -05:00
|
|
|
|
2010-02-16 19:45:25 -05:00
|
|
|
ok result
|
2010-01-13 19:56:35 -05:00
|
|
|
|
2010-02-12 16:23:52 -05:00
|
|
|
|
2010-01-26 10:52:05 -05:00
|
|
|
func: (num) ->
|
2010-01-13 19:56:35 -05:00
|
|
|
switch num
|
|
|
|
when 2, 4, 6
|
|
|
|
true
|
|
|
|
when 1, 3, 5
|
|
|
|
false
|
|
|
|
else false
|
|
|
|
|
2010-02-16 19:45:25 -05:00
|
|
|
ok func(2)
|
|
|
|
ok func(6)
|
|
|
|
ok !func(3)
|
|
|
|
ok !func(8)
|
2010-02-17 21:23:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
# Should cache the switch value, if anything fancier than a literal.
|
|
|
|
num: 5
|
2010-03-21 23:33:24 -04:00
|
|
|
result: switch num: + 5
|
2010-02-17 21:23:59 -05:00
|
|
|
when 5 then false
|
|
|
|
when 15 then false
|
|
|
|
when 10 then true
|
|
|
|
else false
|
|
|
|
|
|
|
|
ok result
|
|
|
|
|
2010-02-22 19:22:09 -05:00
|
|
|
|
|
|
|
# Ensure that trailing switch elses don't get rewritten.
|
|
|
|
result: false
|
|
|
|
switch "word"
|
|
|
|
when "one thing"
|
2010-06-12 19:05:13 -04:00
|
|
|
doSomething()
|
2010-02-22 19:22:09 -05:00
|
|
|
else
|
|
|
|
result: true unless false
|
|
|
|
|
|
|
|
ok result
|
2010-02-22 20:17:54 -05:00
|
|
|
|
|
|
|
result: false
|
|
|
|
switch "word"
|
|
|
|
when "one thing"
|
2010-06-12 19:05:13 -04:00
|
|
|
doSomething()
|
2010-02-22 20:17:54 -05:00
|
|
|
when "other thing"
|
2010-06-12 19:05:13 -04:00
|
|
|
doSomething()
|
2010-02-22 20:17:54 -05:00
|
|
|
else
|
|
|
|
result: true unless false
|
|
|
|
|
|
|
|
ok result
|
2010-05-10 22:57:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Should be able to handle switches sans-condition.
|
|
|
|
result: switch
|
2010-05-11 09:32:16 -04:00
|
|
|
when null then 1
|
|
|
|
when 'truthful string' then 2
|
2010-05-10 22:57:51 -04:00
|
|
|
else 3
|
|
|
|
|
2010-05-11 09:32:16 -04:00
|
|
|
ok result is 2
|
2010-05-31 15:13:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
# Should be able to use "@properties" within the switch clause.
|
|
|
|
obj: {
|
|
|
|
num: 101
|
|
|
|
func: ->
|
|
|
|
switch @num
|
|
|
|
when 101 then '101!'
|
|
|
|
else 'other'
|
|
|
|
}
|
|
|
|
|
|
|
|
ok obj.func() is '101!'
|