From 2a32ff4a6667cc2d08881497e96073e00903f1ea Mon Sep 17 00:00:00 2001
From: Leonardo Balter <leonardo.balter@gmail.com>
Date: Fri, 31 Jul 2015 16:44:28 -0400
Subject: [PATCH] fixup! Add tests for Array.prototype.copyWithin

---
 .../copyWithin/coerced-values-end.js          | 63 +++++++++++++
 .../copyWithin/coerced-values-start.js        | 80 ++++++++++++++++
 .../copyWithin/coerced-values-target.js       | 80 ++++++++++++++++
 .../prototype/copyWithin/coerced-values.js    | 92 -------------------
 .../Array/prototype/copyWithin/fill-holes.js  | 17 ++--
 .../return-abrupt-from-this-length.js         |  3 +-
 6 files changed, 234 insertions(+), 101 deletions(-)
 create mode 100644 test/built-ins/Array/prototype/copyWithin/coerced-values-end.js
 create mode 100644 test/built-ins/Array/prototype/copyWithin/coerced-values-start.js
 create mode 100644 test/built-ins/Array/prototype/copyWithin/coerced-values-target.js
 delete mode 100644 test/built-ins/Array/prototype/copyWithin/coerced-values.js

diff --git a/test/built-ins/Array/prototype/copyWithin/coerced-values-end.js b/test/built-ins/Array/prototype/copyWithin/coerced-values-end.js
new file mode 100644
index 0000000000..1580980b00
--- /dev/null
+++ b/test/built-ins/Array/prototype/copyWithin/coerced-values-end.js
@@ -0,0 +1,63 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 22.1.3.3
+description: >
+  end argument is coerced to an integer values.
+info: >
+  22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+  ...
+  11. If end is undefined, let relativeEnd be len; else let relativeEnd be
+  ToInteger(end).
+  ...
+includes: [compareArray.js]
+---*/
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, 0, null),
+    [0, 1, 2, 3]
+  ),
+  'null value coerced to 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, 0, NaN),
+    [0, 1, 2, 3]
+  ),
+  'NaN value coerced to 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, 0, false),
+    [0, 1, 2, 3]
+  ),
+  'false value coerced to 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, 0, true),
+    [0, 0, 2, 3]
+  ),
+  'true value coerced to 1'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, 0, '-2'),
+    [0, 0, 1, 3]
+  ),
+  'string "-2" value coerced to integer -2'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, 0, -2.5),
+    [0, 0, 1, 3]
+  ),
+  'float -2.5 value coerced to integer -2'
+);
diff --git a/test/built-ins/Array/prototype/copyWithin/coerced-values-start.js b/test/built-ins/Array/prototype/copyWithin/coerced-values-start.js
new file mode 100644
index 0000000000..37d7644f2b
--- /dev/null
+++ b/test/built-ins/Array/prototype/copyWithin/coerced-values-start.js
@@ -0,0 +1,80 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 22.1.3.3
+description: >
+  start argument is coerced to an integer value.
+info: >
+  22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+  ...
+  8. Let relativeStart be ToInteger(start).
+  ...
+includes: [compareArray.js]
+---*/
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, undefined),
+    [0, 0, 1, 2]
+  ),
+  'undefined value coerced to 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, false),
+    [0, 0, 1, 2]
+  ),
+  'false value coerced to 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, NaN),
+    [0, 0, 1, 2]
+  ),
+  'NaN value coerced to 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, null),
+    [0, 0, 1, 2]
+  ),
+  'null value coerced to 0'
+);
+
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(0, true),
+    [1, 2, 3, 3]
+  ),
+  'true value coerced to 1'
+);
+
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(0, '1'),
+    [1, 2, 3, 3]
+  ),
+  'string "1" value coerced to 1'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1, 0.5),
+    [0, 0, 1, 2]
+  ),
+  '0.5 float value coerced to integer 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(0, 1.5),
+    [1, 2, 3, 3]
+  ),
+  '1.5 float value coerced to integer 1'
+);
\ No newline at end of file
diff --git a/test/built-ins/Array/prototype/copyWithin/coerced-values-target.js b/test/built-ins/Array/prototype/copyWithin/coerced-values-target.js
new file mode 100644
index 0000000000..3743bc1034
--- /dev/null
+++ b/test/built-ins/Array/prototype/copyWithin/coerced-values-target.js
@@ -0,0 +1,80 @@
+// Copyright (C) 2015 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+es6id: 22.1.3.3
+description: >
+  target argument is coerced to an integer value.
+info: >
+  22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
+
+  ...
+  5. Let relativeTarget be ToInteger(target).
+  ...
+includes: [compareArray.js]
+---*/
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(undefined, 1),
+    [1, 2, 3, 3]
+  ),
+  'undefined value coerced to 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(false, 1),
+    [1, 2, 3, 3]
+  ),
+  'false value coerced to 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(NaN, 1),
+    [1, 2, 3, 3]
+  ),
+  'NaN value coerced to 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(null, 1),
+    [1, 2, 3, 3]
+  ),
+  'null value coerced to 0'
+);
+
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(true, 0),
+    [0, 0, 1, 2]
+  ),
+  'true value coerced to 1'
+);
+
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin('1', 0),
+    [0, 0, 1, 2]
+  ),
+  'string "1" value coerced to 1'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(0.5, 1),
+    [1, 2, 3, 3]
+  ),
+  '0.5 float value coerced to integer 0'
+);
+
+assert(
+  compareArray(
+    [0, 1, 2, 3].copyWithin(1.5, 0),
+    [0, 0, 1, 2]
+  ),
+  '1.5 float value coerced to integer 1'
+);
\ No newline at end of file
diff --git a/test/built-ins/Array/prototype/copyWithin/coerced-values.js b/test/built-ins/Array/prototype/copyWithin/coerced-values.js
deleted file mode 100644
index 4f5720bbad..0000000000
--- a/test/built-ins/Array/prototype/copyWithin/coerced-values.js
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (C) 2015 the V8 project authors. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-/*---
-es6id: 22.1.3.3
-description: >
-  Arguments are coerced to integer values.
-info: >
-  22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
-
-  ...
-  5. Let relativeTarget be ToInteger(target).
-  ...
-  8. Let relativeStart be ToInteger(start).
-  ...
-  11. If end is undefined, let relativeEnd be len; else let relativeEnd be
-  ToInteger(end).
-  ...
-includes: [compareArray.js]
----*/
-
-assert(
-  compareArray(
-    [0, 1, 2, 3].copyWithin(undefined, undefined),
-    [0, 1, 2, 3]
-  ),
-  'undefined `target` and `start` values coerced to 0'
-);
-
-assert(
-  compareArray(
-    [0, 1, 2, 3].copyWithin(false, false),
-    [0, 1, 2, 3]
-  ),
-  'false `target` and `start` values coerced to 0'
-);
-
-assert(
-  compareArray(
-    [0, 1, 2, 3].copyWithin(NaN, NaN),
-    [0, 1, 2, 3]
-  ),
-  'NaN `target` and `start` values coerced to 0'
-);
-
-assert(
-  compareArray(
-    [0, 1, 2, 3].copyWithin(null, null),
-    [0, 1, 2, 3]
-  ),
-  'null `target` and `start` values coerced to 0'
-);
-
-
-assert(
-  compareArray(
-    [0, 1, 2, 3].copyWithin(true, 0),
-    [0, 0, 1, 2]
-  ),
-  'true `target` value coerced to 1'
-);
-
-assert(
-  compareArray(
-    [0, 1, 2, 3].copyWithin(0, true),
-    [1, 2, 3, 3]
-  ),
-  'true `start` value coerced to 1'
-);
-
-assert(
-  compareArray(
-    [0, 1, 2, 3].copyWithin(1, 0, true),
-    [0, 0, 2, 3]
-  ),
-  'true `end` value coerced to 1'
-);
-
-assert(
-  compareArray(
-    [0, 1, 2, 3].copyWithin('1', '', '-2'),
-    [0, 0, 1, 3]
-  ),
-  'string values coerced to integer'
-);
-
-assert(
-  compareArray(
-    [0, 1, 2, 3].copyWithin(1.3, 0.4, -2.5),
-    [0, 0, 1, 3]
-  ),
-  'float values coerced to integer'
-);
diff --git a/test/built-ins/Array/prototype/copyWithin/fill-holes.js b/test/built-ins/Array/prototype/copyWithin/fill-holes.js
index d1b25a2391..a54e655f46 100644
--- a/test/built-ins/Array/prototype/copyWithin/fill-holes.js
+++ b/test/built-ins/Array/prototype/copyWithin/fill-holes.js
@@ -4,12 +4,15 @@
 es6id: 22.1.3.3
 description: >
   Loop from each property, even empty holes.
-includes: [compareArray.js]
 ---*/
 
-assert(
-  compareArray(
-    [0, 1, , , 1].copyWithin(0, 1, 4),
-    [1, , , , 1]
-  )
-);
+var arr = [0, 1, , , 1];
+
+arr.copyWithin(0, 1, 4);
+
+assert.sameValue(arr.length, 5);
+assert.sameValue(arr[0], 1);
+assert.sameValue(arr[4], 1);
+assert.sameValue(arr.hasOwnProperty(1), false);
+assert.sameValue(arr.hasOwnProperty(2), false);
+assert.sameValue(arr.hasOwnProperty(3), false);
diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js
index 20f5d7d446..7c8da2671c 100644
--- a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js
+++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js
@@ -18,8 +18,7 @@ var o1 = {};
 Object.defineProperty(o1, 'length', {
   get: function() {
     throw new Test262Error();
-  },
-  configurable: true
+  }
 });
 assert.throws(Test262Error, function() {
   [].copyWithin.call(o1);
-- 
GitLab