Skip to content
Snippets Groups Projects
Commit 2a32ff4a authored by Leonardo Balter's avatar Leonardo Balter
Browse files

fixup! Add tests for Array.prototype.copyWithin

parent 935da082
No related branches found
No related tags found
No related merge requests found
......@@ -3,14 +3,10 @@
/*---
es6id: 22.1.3.3
description: >
Arguments are coerced to integer values.
end argument is coerced to an 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).
......@@ -20,51 +16,26 @@ 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].copyWithin(1, 0, null),
[0, 1, 2, 3]
),
'false `target` and `start` values coerced to 0'
'null value coerced to 0'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(NaN, NaN),
[0, 1, 2, 3].copyWithin(1, 0, NaN),
[0, 1, 2, 3]
),
'NaN `target` and `start` values coerced to 0'
'NaN value coerced to 0'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(null, null),
[0, 1, 2, 3].copyWithin(1, 0, false),
[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'
'false value coerced to 0'
);
assert(
......@@ -72,21 +43,21 @@ assert(
[0, 1, 2, 3].copyWithin(1, 0, true),
[0, 0, 2, 3]
),
'true `end` value coerced to 1'
'true value coerced to 1'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin('1', '', '-2'),
[0, 1, 2, 3].copyWithin(1, 0, '-2'),
[0, 0, 1, 3]
),
'string values coerced to integer'
'string "-2" value coerced to integer -2'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(1.3, 0.4, -2.5),
[0, 1, 2, 3].copyWithin(1, 0, -2.5),
[0, 0, 1, 3]
),
'float values coerced to integer'
'float -2.5 value coerced to integer -2'
);
// 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
// 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
......@@ -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);
......@@ -18,8 +18,7 @@ var o1 = {};
Object.defineProperty(o1, 'length', {
get: function() {
throw new Test262Error();
},
configurable: true
}
});
assert.throws(Test262Error, function() {
[].copyWithin.call(o1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment