#1643: Updated tests

This commit is contained in:
Gerald Lewis 2011-09-09 18:59:35 -04:00
parent 03372c9b29
commit 7d4e693d20
1 changed files with 21 additions and 10 deletions

View File

@ -309,14 +309,25 @@ test "#1591, #1101: splatted expressions in destructuring assignment must be ass
test "#1643: splatted accesses in destructuring assignments should not be declared as variables", ->
nonce = {}
accesses = ['o.a', 'C::a', 'C::', 'o["a"]', '(o.a)', 'f().a', '(o.a).a', '@o.a', 'o?.a', 'f?().a']
accesses = ['o.a', 'o["a"]', '(o.a)', '(o.a).a', '@o.a', 'C::a', 'C::', 'f().a', 'o?.a', 'o?.a.b', 'f?().a']
for access in accesses
code =
"""
nonce = {}; @o = o = new (class C then a:{}); f = -> o
[#{access}...] = [nonce]
unless #{access}[0] is nonce then throw 'error'
"""
eq nonce, unless (try CoffeeScript.run code, bare: true catch e then true) then nonce
for i,j in [1,2,3] #position can matter
code =
"""
nonce = {}; nonce2 = {}; nonce3 = {};
@o = o = new (class C then a:{}); f = -> o
[#{new Array(i).join('x,')}#{access}...] = [#{new Array(i).join('0,')}nonce, nonce2, nonce3]
unless #{access}[0] is nonce and #{access}[1] is nonce2 and #{access}[2] is nonce3 then throw new Error('[...]')
"""
eq nonce, unless (try CoffeeScript.run code, bare: true catch e then true) then nonce
# subpatterns like `[[a]...]` and `[{a}...]`
subpatterns = ['[sub, sub2, sub3]', '{0: sub, 1: sub2, 2: sub3}']
for subpattern in subpatterns
for i,j in [1,2,3]
code =
"""
nonce = {}; nonce2 = {}; nonce3 = {};
[#{new Array(i).join('x,')}#{subpattern}...] = [#{new Array(i).join('0,')}nonce, nonce2, nonce3]
unless sub is nonce and sub2 is nonce2 and sub3 is nonce3 then throw new Error('[sub...]')
"""
eq nonce, unless (try CoffeeScript.run code, bare: true catch e then true) then nonce