From 7d4e693d20aeb118bdfa59ce93c5b9533768866c Mon Sep 17 00:00:00 2001 From: Gerald Lewis Date: Fri, 9 Sep 2011 18:59:35 -0400 Subject: [PATCH] #1643: Updated tests --- test/assignment.coffee | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/test/assignment.coffee b/test/assignment.coffee index e3b90850..d0d3693e 100644 --- a/test/assignment.coffee +++ b/test/assignment.coffee @@ -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