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

#1643: Updated tests

This commit is contained in:
Gerald Lewis 2011-09-09 18:59:35 -04:00
parent 03372c9b29
commit 7d4e693d20

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", -> test "#1643: splatted accesses in destructuring assignments should not be declared as variables", ->
nonce = {} 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 for access in accesses
for i,j in [1,2,3] #position can matter
code = code =
""" """
nonce = {}; @o = o = new (class C then a:{}); f = -> o nonce = {}; nonce2 = {}; nonce3 = {};
[#{access}...] = [nonce] @o = o = new (class C then a:{}); f = -> o
unless #{access}[0] is nonce then throw 'error' [#{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 eq nonce, unless (try CoffeeScript.run code, bare: true catch e then true) then nonce