summaryrefslogtreecommitdiff
path: root/src/dstr-assignment
diff options
context:
space:
mode:
authorCaio Lima <ticaiolima@gmail.com>2017-02-20 01:22:02 +0000
committerLeonardo Balter <leonardo.balter@gmail.com>2017-03-06 16:24:35 -0500
commit0200c633964b47f11d9eee732eacef7a965af743 (patch)
treec460386c78ef91c2e7d71ff576b0f794adcf7a60 /src/dstr-assignment
parentda3898d707490af8c3eea2b115279efd7d2d6061 (diff)
downloadqtdeclarative-testsuites-0200c633964b47f11d9eee732eacef7a965af743.tar.gz
Implementing test cases for object rest deconstruction
Closes #867 Ref #865
Diffstat (limited to 'src/dstr-assignment')
-rw-r--r--src/dstr-assignment/obj-rest-descriptors.case33
-rw-r--r--src/dstr-assignment/obj-rest-empty-obj.case22
-rw-r--r--src/dstr-assignment/obj-rest-getter-abrupt-get-error.case22
-rw-r--r--src/dstr-assignment/obj-rest-getter.case26
-rw-r--r--src/dstr-assignment/obj-rest-nested-obj-nested-rest.case35
-rw-r--r--src/dstr-assignment/obj-rest-nested-obj.case25
-rw-r--r--src/dstr-assignment/obj-rest-not-last-element-invalid.case21
-rw-r--r--src/dstr-assignment/obj-rest-number.case22
-rw-r--r--src/dstr-assignment/obj-rest-obj-own-property.case25
-rw-r--r--src/dstr-assignment/obj-rest-put-const.case20
-rw-r--r--src/dstr-assignment/obj-rest-skip-non-enumerable.case32
-rw-r--r--src/dstr-assignment/obj-rest-str-val.case23
-rw-r--r--src/dstr-assignment/obj-rest-symbol-val.case22
-rw-r--r--src/dstr-assignment/obj-rest-to-property-with-setter.case30
-rw-r--r--src/dstr-assignment/obj-rest-to-property.case26
-rw-r--r--src/dstr-assignment/obj-rest-val-null.case20
-rw-r--r--src/dstr-assignment/obj-rest-val-undefined.case20
-rw-r--r--src/dstr-assignment/obj-rest-valid-object.case32
18 files changed, 456 insertions, 0 deletions
diff --git a/src/dstr-assignment/obj-rest-descriptors.case b/src/dstr-assignment/obj-rest-descriptors.case
new file mode 100644
index 000000000..a6d645d21
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-descriptors.case
@@ -0,0 +1,33 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ Object created from rest deconstruction doesn't copy source
+ object property descriptors.
+template: default
+esid: pending
+includes: [propertyHelper.js]
+---*/
+
+//- setup
+var rest;
+var obj = {};
+Object.defineProperty(obj, "a", { value: 3, configurable: false, enumerable: true });
+Object.defineProperty(obj, "b", { value: 4, writable: false, enumerable: true });
+//- elems
+{...rest}
+//- vals
+obj
+//- body
+assert.sameValue(rest.a, 3);
+assert.sameValue(rest.b, 4);
+
+verifyEnumerable(rest, "a");
+verifyWritable(rest, "a");
+verifyConfigurable(rest, "a");
+
+verifyEnumerable(rest, "b");
+verifyWritable(rest, "b");
+verifyConfigurable(rest, "b");
+
diff --git a/src/dstr-assignment/obj-rest-empty-obj.case b/src/dstr-assignment/obj-rest-empty-obj.case
new file mode 100644
index 000000000..96953623a
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-empty-obj.case
@@ -0,0 +1,22 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ RestBindingInitialization creates a new object even if lhs is an empty object
+template: default
+esid: pending
+---*/
+
+//- setup
+var rest;
+
+//- elems
+{...rest}
+//- vals
+{}
+//- body
+assert.notSameValue(rest, undefined);
+assert.notSameValue(rest, null);
+assert.sameValue(typeof rest, "object");
+
diff --git a/src/dstr-assignment/obj-rest-getter-abrupt-get-error.case b/src/dstr-assignment/obj-rest-getter-abrupt-get-error.case
new file mode 100644
index 000000000..dc3e1f3ba
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-getter-abrupt-get-error.case
@@ -0,0 +1,22 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ Rest deconstruction doesn't happen if getter return is abrupt
+template: error
+esid: pending
+---*/
+
+//- setup
+var x;
+var count = 0;
+//- elems
+{...x}
+//- vals
+{ get v() { count++; throw new Test262Error(); } }
+//- error
+Test262Error
+//- teardown
+assert.sameValue(count, 1);
+
diff --git a/src/dstr-assignment/obj-rest-getter.case b/src/dstr-assignment/obj-rest-getter.case
new file mode 100644
index 000000000..5d6264e30
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-getter.case
@@ -0,0 +1,26 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ Getter is called when obj is being deconstructed to a rest Object
+template: default
+esid: pending
+includes: [propertyHelper.js]
+---*/
+
+//- setup
+var x;
+var count = 0;
+//- elems
+{...x}
+//- vals
+{ get v() { count++; return 2; } }
+//- body
+assert.sameValue(x.v, 2);
+assert.sameValue(count, 1);
+
+verifyEnumerable(x, "v");
+verifyWritable(x, "v");
+verifyConfigurable(x, "v");
+
diff --git a/src/dstr-assignment/obj-rest-nested-obj-nested-rest.case b/src/dstr-assignment/obj-rest-nested-obj-nested-rest.case
new file mode 100644
index 000000000..5971ad243
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-nested-obj-nested-rest.case
@@ -0,0 +1,35 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ When DestructuringAssignmentTarget is an object literal, it should be parsed
+ parsed as a DestructuringAssignmentPattern and evaluated as a destructuring
+ assignment and object rest desconstruction is allowed in that case.
+template: default
+esid: pending
+includes: [propertyHelper.js]
+---*/
+
+//- setup
+var a, b, c, rest;
+//- elems
+{a, b, ...{c, ...rest}}
+//- vals
+{a: 1, b: 2, c: 3, d: 4, e: 5}
+//- body
+assert.sameValue(a, 1);
+assert.sameValue(b, 2);
+assert.sameValue(c, 3);
+
+assert.sameValue(rest.d, 4);
+assert.sameValue(rest.e, 5);
+
+verifyEnumerable(rest, "d");
+verifyWritable(rest, "d");
+verifyConfigurable(rest, "d");
+
+verifyEnumerable(rest, "e");
+verifyWritable(rest, "e");
+verifyConfigurable(rest, "e");
+
diff --git a/src/dstr-assignment/obj-rest-nested-obj.case b/src/dstr-assignment/obj-rest-nested-obj.case
new file mode 100644
index 000000000..9352e2241
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-nested-obj.case
@@ -0,0 +1,25 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ When DestructuringAssignmentTarget is an object literal, it should be parsed
+ parsed as a DestructuringAssignmentPattern and evaluated as a destructuring
+ assignment.
+template: default
+esid: pending
+---*/
+
+//- setup
+var a, b, c, d, e;
+//- elems
+{a, b, ...{c, e}}
+//- vals
+{a: 1, b: 2, c: 3, d: 4, e: 5}
+//- body
+assert.sameValue(a, 1);
+assert.sameValue(b, 2);
+assert.sameValue(c, 3);
+assert.sameValue(e, 5);
+assert.sameValue(d, undefined);
+
diff --git a/src/dstr-assignment/obj-rest-not-last-element-invalid.case b/src/dstr-assignment/obj-rest-not-last-element-invalid.case
new file mode 100644
index 000000000..2124baac0
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-not-last-element-invalid.case
@@ -0,0 +1,21 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ Object rest element needs to be the last AssignmenProperty
+ in ObjectAssignmentPattern.
+template: syntax
+esid: pending
+negative:
+ phase: early
+ type: SyntaxError
+---*/
+
+//- setup
+var rest, b;
+//- elems
+{...rest, b}
+//- vals
+{}
+
diff --git a/src/dstr-assignment/obj-rest-number.case b/src/dstr-assignment/obj-rest-number.case
new file mode 100644
index 000000000..d54ef3b3f
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-number.case
@@ -0,0 +1,22 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ RestBindingInitialization creates a new object even if lhs is a Number
+template: default
+esid: pending
+---*/
+
+//- setup
+var rest;
+
+//- elems
+{...rest}
+//- vals
+51
+//- body
+assert.notSameValue(rest, undefined);
+assert.notSameValue(rest, null);
+assert(rest instanceof Object);
+
diff --git a/src/dstr-assignment/obj-rest-obj-own-property.case b/src/dstr-assignment/obj-rest-obj-own-property.case
new file mode 100644
index 000000000..cfe355060
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-obj-own-property.case
@@ -0,0 +1,25 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ Rest object contains just soruce object's own properties
+template: default
+esid: pending
+includes: [propertyHelper.js]
+---*/
+
+//- setup
+var o = Object.create({ x: 1, y: 2 });
+o.z = 3;
+
+var x, y, z;
+//- elems
+{ x, ...{y , z} }
+//- vals
+o
+//- body
+assert.sameValue(x, 1);
+assert.sameValue(y, undefined);
+assert.sameValue(z, 3);
+
diff --git a/src/dstr-assignment/obj-rest-put-const.case b/src/dstr-assignment/obj-rest-put-const.case
new file mode 100644
index 000000000..0793b375b
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-put-const.case
@@ -0,0 +1,20 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ The object rest deconstruction assignment target should obey `const` semantics.
+template: error
+esid: pending
+features: [const]
+---*/
+
+//- setup
+const rest = null;
+//- error
+TypeError
+//- elems
+{...rest}
+//- vals
+{}
+
diff --git a/src/dstr-assignment/obj-rest-skip-non-enumerable.case b/src/dstr-assignment/obj-rest-skip-non-enumerable.case
new file mode 100644
index 000000000..9d661f396
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-skip-non-enumerable.case
@@ -0,0 +1,32 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ Rest object doesn't contain non-enumerable properties
+template: default
+esid: pending
+includes: [propertyHelper.js]
+---*/
+
+//- setup
+var rest;
+var obj = {a: 3, b: 4};
+Object.defineProperty(obj, "x", { value: 4, enumerable: false });
+//- elems
+{...rest}
+//- vals
+obj
+//- body
+assert.sameValue(rest.a, 3);
+assert.sameValue(rest.b, 4);
+assert.sameValue(Object.getOwnPropertyDescriptor(rest, "x"), undefined);
+
+verifyEnumerable(rest, "a");
+verifyWritable(rest, "a");
+verifyConfigurable(rest, "a");
+
+verifyEnumerable(rest, "b");
+verifyWritable(rest, "b");
+verifyConfigurable(rest, "b");
+
diff --git a/src/dstr-assignment/obj-rest-str-val.case b/src/dstr-assignment/obj-rest-str-val.case
new file mode 100644
index 000000000..04667aa4b
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-str-val.case
@@ -0,0 +1,23 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ RestBindingInitialization creats an object with indexes as property name
+template: default
+esid: pending
+---*/
+
+//- setup
+var rest;
+
+//- elems
+{...rest}
+//- vals
+"foo"
+//- body
+assert.sameValue(rest["0"], "f");
+assert.sameValue(rest["1"], "o");
+assert.sameValue(rest["2"], "o");
+assert(rest instanceof Object);
+
diff --git a/src/dstr-assignment/obj-rest-symbol-val.case b/src/dstr-assignment/obj-rest-symbol-val.case
new file mode 100644
index 000000000..2a4e991f3
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-symbol-val.case
@@ -0,0 +1,22 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ RestBindingInitialization creates a new object if lhs is a Symbol
+template: default
+esid: pending
+---*/
+
+//- setup
+var rest;
+
+//- elems
+{...rest}
+//- vals
+Symbol("foo")
+//- body
+assert.notSameValue(rest, undefined);
+assert.notSameValue(rest, null);
+assert(rest instanceof Object);
+
diff --git a/src/dstr-assignment/obj-rest-to-property-with-setter.case b/src/dstr-assignment/obj-rest-to-property-with-setter.case
new file mode 100644
index 000000000..61be6767c
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-to-property-with-setter.case
@@ -0,0 +1,30 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ When DestructuringAssignmentTarget is an object property setter, its value should be
+ binded as rest object.
+template: default
+esid: pending
+---*/
+
+//- setup
+var settedValue;
+var executedGetter = false;
+var src = {
+ get y() { executedGetter = true; },
+ set y(v) {
+ settedValue = v;
+ }
+}
+src.y = undefined;
+//- elems
+{...src.y}
+//- vals
+{ x: 1, y: 2}
+//- body
+assert.sameValue(settedValue.x, 1);
+assert.sameValue(settedValue.y, 2);
+assert(!executedGetter, "The property should not be accessed");
+
diff --git a/src/dstr-assignment/obj-rest-to-property.case b/src/dstr-assignment/obj-rest-to-property.case
new file mode 100644
index 000000000..78aac9ea1
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-to-property.case
@@ -0,0 +1,26 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ When DestructuringAssignmentTarget is an object property, its value should be binded
+ as rest object.
+template: default
+esid: pending
+includes: [propertyHelper.js]
+---*/
+
+//- setup
+var src = {};
+//- elems
+{...src.y}
+//- vals
+{ x: 1, y: 2}
+//- body
+assert.sameValue(src.y.x, 1);
+assert.sameValue(src.y.y, 2);
+
+verifyEnumerable(src, "y");
+verifyWritable(src, "y");
+verifyConfigurable(src, "y");
+
diff --git a/src/dstr-assignment/obj-rest-val-null.case b/src/dstr-assignment/obj-rest-val-null.case
new file mode 100644
index 000000000..a09343aaa
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-val-null.case
@@ -0,0 +1,20 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ TypeError is thrown when rhs is null because of 7.1.13 ToObject ( argument )
+ used by CopyDataProperties
+template: error
+esid: pending
+---*/
+
+//- error
+TypeError
+//- setup
+var rest;
+//- elems
+{...rest}
+//- vals
+null
+
diff --git a/src/dstr-assignment/obj-rest-val-undefined.case b/src/dstr-assignment/obj-rest-val-undefined.case
new file mode 100644
index 000000000..5c6c570fa
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-val-undefined.case
@@ -0,0 +1,20 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ TypeError is thrown when rhs is ```undefined``` because of 7.1.13 ToObject ( argument )
+ used by CopyDataProperties
+template: error
+esid: pending
+---*/
+
+//- error
+TypeError
+//- setup
+var rest;
+//- elems
+{...rest}
+//- vals
+undefined
+
diff --git a/src/dstr-assignment/obj-rest-valid-object.case b/src/dstr-assignment/obj-rest-valid-object.case
new file mode 100644
index 000000000..732d13162
--- /dev/null
+++ b/src/dstr-assignment/obj-rest-valid-object.case
@@ -0,0 +1,32 @@
+// Copyright (C) 2017 Caio Lima. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+desc: >
+ Rest object contains just unextracted data
+template: default
+esid: pending
+includes: [propertyHelper.js]
+---*/
+
+//- setup
+var rest, a, b;
+
+//- elems
+{a, b, ...rest}
+//- vals
+{x: 1, y: 2, a: 5, b: 3}
+//- body
+assert.sameValue(rest.x, 1);
+assert.sameValue(rest.y, 2);
+assert.sameValue(rest.a, undefined);
+assert.sameValue(rest.b, undefined);
+
+verifyEnumerable(rest, "x");
+verifyWritable(rest, "x");
+verifyConfigurable(rest, "x");
+
+verifyEnumerable(rest, "y");
+verifyWritable(rest, "y");
+verifyConfigurable(rest, "y");
+