Index: test/cctest/test-parsing.cc |
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
index 6132d4109d2bc1c966962d9154649c8dfd57bc6d..0204a3f927950a34086f4930b585f2a26c79d467 100644 |
--- a/test/cctest/test-parsing.cc |
+++ b/test/cctest/test-parsing.cc |
@@ -6546,6 +6546,154 @@ TEST(DestructuringNegativeTests) { |
} |
+TEST(DestructuringAssignmentPositiveTests) { |
+ i::FLAG_harmony_destructuring = true; |
+ i::FLAG_harmony_computed_property_names = true; |
+ |
+ const char* context_data[][2] = { |
+ {"'use strict'; let x, y, z; (", " = {});"}, |
+ {"var x, y, z; (", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
+ {"var x, y, z; for (x in ", " = {});"}, |
+ {"var x, y, z; for (x of ", " = {});"}, |
+ {NULL, NULL}}; |
+ |
+ // clang-format off |
+ const char* data[] = { |
+ "x", |
+ "{ x : y }", |
Dmitry Lomov (no reviews)
2015/06/19 08:57:30
Add more tests of the form:
{ x : y.z } = ...
{
caitp (gmail)
2015/06/19 14:23:21
I think there are cases for each of those, but I'v
|
+ "{ x : y = 1 }", |
+ "{ x }", |
+ "{ x, y, z }", |
+ "{ x = 1, y: z, z: y }", |
+ "{x = 42, y = 15}", |
+ "[x]", |
+ "[x = 1]", |
+ "[x,y,z]", |
+ "[x, y = 42, z]", |
+ "{ x : x, y : y }", |
+ "{ x : x = 1, y : y }", |
+ "{ x : x, y : y = 42 }", |
+ "[]", |
+ "{}", |
+ "[{x:x, y:y}, [,x,z,]]", |
+ "[{x:x = 1, y:y = 2}, [z = 3, z = 4, z = 5]]", |
+ "[x,,y]", |
+ "[(x),,(y)]", |
+ "[(x)]", |
+ "{42 : x}", |
+ "{42 : x = 42}", |
+ "{42e-2 : x}", |
+ "{42e-2 : x = 42}", |
+ "{'hi' : x}", |
+ "{'hi' : x = 42}", |
+ "{var: x}", |
+ "{var: x = 42}", |
+ "{var: (x) = 42}", |
+ "{[x] : z}", |
+ "{[1+1] : z}", |
+ "{[1+1] : (z)}", |
+ "{[foo()] : z}", |
+ "{[foo()] : (z)}", |
+ "{[foo()] : foo().bar}", |
+ "{[foo()] : foo()['bar']}", |
+ "{[foo()] : this.bar}", |
+ "{[foo()] : this['bar']}", |
+ "{[foo()] : 'foo'.bar}", |
+ "{[foo()] : 'foo'['bar']}", |
+ "[...x]", |
+ "[x,y,...z]", |
+ "[x,,...z]", |
+ "{ x: y } = z", |
+ "[x, y] = z", |
+ "{ x: y } = { z }", |
+ "[x, y] = { z }", |
+ "{ x: y } = [ z ]", |
+ "[x, y] = [ z ]", |
+ "[((x, y) => z).x]", |
+ "{x: ((y, z) => z).x}", |
+ "[((x, y) => z)['x']]", |
+ "{x: ((y, z) => z)['x']}", |
+ NULL}; |
+ // clang-format on |
+ static const ParserFlag always_flags[] = { |
+ kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames, |
+ kAllowHarmonyDestructuring, kAllowHarmonyArrowFunctions}; |
+ RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
+} |
+ |
+ |
+TEST(DestructuringAssignmentNegativeTests) { |
+ i::FLAG_harmony_destructuring = true; |
+ i::FLAG_harmony_computed_property_names = true; |
+ |
+ const char* context_data[][2] = { |
+ {"'use strict'; let x, y, z; (", " = {});"}, |
+ {"var x, y, z; (", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
+ {"var x, y, z; for (x in ", " = {});"}, |
+ {"var x, y, z; for (x of ", " = {});"}, |
+ {NULL, NULL}}; |
+ |
+ // clang-format off |
+ const char* data[] = { |
+ "{ x : ++y }", |
+ "{ x : y * 2 }", |
+ "{ ...x }", |
+ "{ get x() {} }", |
+ "{ set x() {} }", |
+ "{ x: y() }", |
+ "{ this }", |
+ "{ x: this }", |
+ "{ x: this = 1 }", |
+ "{ super }", |
+ "{ x: super }", |
+ "{ x: super = 1 }", |
+ "{ new.target }", |
+ "{ x: new.target }", |
+ "{ x: new.target = 1 }", |
+ "[x--]", |
+ "[--x = 1]", |
+ "[x()]", |
+ "[this]", |
+ "[this = 1]", |
+ "[new.target]", |
+ "[new.target = 1]", |
+ "[super]", |
+ "[super = 1]", |
+ "[function f() {}]", |
+ "[50]", |
+ "[(50)]", |
+ "[(function() {})]", |
+ "[(foo())]", |
+ "{ x: 50 }", |
+ "{ x: (50) }", |
+ "['str']", |
+ "{ x: 'str' }", |
+ "{ x: ('str') }", |
+ "{ x: (foo()) }", |
+ "{ x: (function() {}) }", |
+ "{ x: y } = 'str'", |
+ "[x, y] = 'str'", |
+ "[(x,y) => z]", |
+ "{x: (y) => z}", |
+ "[x, ...y, z]", |
+ "[...x,]", |
+ "[x, y, ...z = 1]", |
+ "[...z = 1]", |
+ NULL}; |
+ // clang-format on |
+ static const ParserFlag always_flags[] = { |
+ kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames, |
+ kAllowHarmonyDestructuring, kAllowHarmonyArrowFunctions}; |
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
+} |
+ |
+ |
TEST(DestructuringDisallowPatternsInForVarIn) { |
i::FLAG_harmony_destructuring = true; |
static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; |