added/fixed/tweaked a few tests and merged test_compound_assignment into test_assignment

This commit is contained in:
satyr
2010-10-24 04:03:07 +09:00
10 changed files with 815 additions and 458 deletions

View File

@@ -70,7 +70,6 @@
'classes'
'comments'
'compilation'
'compound_assignment'
'comprehensions'
'existence'
'expressions'

View File

@@ -31,3 +31,31 @@ ok tester().example() is 'example function'
try throw CoffeeScript.tokens 'in = 1'
catch e then eq e.message, 'Reserved word "in" on line 1 can\'t be assigned'
num = 10
num -= 5
eq num, 5
num *= 10
eq num, 50
num /= 10
eq num, 5
num %= 3
eq num, 2
val = false
val ||= 'value'
val ||= 'eulav'
eq val, 'value'
val &&= 'rehto'
val &&= 'other'
eq val, 'other'
val = null
val ?= 'value'
val ?= 'eulav'
eq val, 'value'

View File

@@ -1,26 +0,0 @@
num = 10
num -= 5
eq num, 5
num *= 10
eq num, 50
num /= 10
eq num, 5
num %= 3
eq num, 2
val = false
val ||= 'value'
val ||= 'eulav'
eq val, 'value'
val &&= 'rehto'
val &&= 'other'
eq val, 'other'
val = null
val ?= 'value'
val ?= 'eulav'
eq val, 'value'

View File

@@ -26,7 +26,9 @@ ok object is extend object, array
eq object[3], 3
# Test `flatten`
eq "#{ flatten [0, [1, 2], 3, [4]] }", "#{ array }"
ay = yes
(ay and= typeof n is 'number') for n in flatten [0, [[1], 2], 3, [4]]
ok ay
# Test `del`
eq 1, del object, 1

View File

@@ -204,18 +204,15 @@ ok obj.three is 3
# Implicit objects as part of chained calls.
identity = (x) -> x.a
b = identity identity identity
pluck = (x) -> x.a
eq 100, pluck pluck pluck
a:
a:
a: 100
ok b is 100
# Inline JS
eq '\\`', `
// Inline JS
"\\\`"
`

View File

@@ -147,17 +147,17 @@ ok new String instanceof String
ok new Number not instanceof String
#737: `in` should have higher precedence than logical operators
#737: `in` should have higher precedence than logical operators.
eq 1, 1 in [1] and 1
#768: `in` should preserve evaluation order
#768: `in` should preserve evaluation order.
share = 0
a = -> share++ if share is 0
b = -> share++ if share is 1
c = -> share++ if share is 2
ok a() not in [b(),c()] and share is 3
# `in` with cache and `__indexOf` should work in commaed lists
# `in` with cache and `__indexOf` should work in commaed lists.
eq [Object() in Array()].length, 1

View File

@@ -103,7 +103,7 @@ ok age is 26
ok first is "Prince"
ok second is "Bowie"
# Pattern matching within for..loops
# Pattern matching within for..loops.
persons = {
George: { name: "Bob" },
@@ -149,9 +149,11 @@ obj =
func: (list, object) ->
[@one, @two] = list
{@a, @b} = object
{@a} = object # must not unroll this
{@a} = object
null
{} = [] = ok yes, 'empty assignment is allowed'
obj.func [1, 2], a: 'a', b: 'b'
eq obj.one, 1

View File

@@ -23,23 +23,11 @@ func = (num) ->
true
when 1, 3, 5
false
else false
ok func(2)
ok func(6)
ok !func(3)
ok !func(8)
# Should cache the switch value, if anything fancier than a literal.
num = 5
result = switch num += 5
when 5 then false
when 15 then false
when 10 then true
else false
ok result
eq func(8), undefined
# Ensure that trailing switch elses don't get rewritten.