From be0964c8ffcacea6ac03e23d7ec5358572b2bdb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=AD=90caitp=E2=AD=90?= <caitp@users.noreply.github.com> Date: Mon, 13 Feb 2017 16:51:45 -0500 Subject: [PATCH] Add tests for %TypedArray%.prototype.copyWithin() with target/start/end=Infinity (#849) ToInteger can result in the values +Infinity and -Infinity. --- .../copyWithin/negative-out-of-bounds-end.js | 40 +++++++++++++++++++ .../negative-out-of-bounds-start.js | 32 +++++++++++++++ .../negative-out-of-bounds-target.js | 16 ++++++++ .../non-negative-out-of-bounds-end.js | 16 ++++++++ ...negative-out-of-bounds-target-and-start.js | 24 +++++++++++ 5 files changed, 128 insertions(+) diff --git a/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js b/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js index 29a901f9e1..b50e116031 100644 --- a/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js +++ b/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-end.js @@ -37,6 +37,14 @@ testWithTypedArrayConstructors(function(TA) { '[0, 1, 2, 3].copyWithin(0, 1, -10) -> [0, 1, 2, 3]' ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, 1, -Infinity), + [1, 2, 3, 4, 5] + ) + '[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) -> [1, 2, 3, 4, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3]).copyWithin(0, -2, -10), @@ -45,6 +53,14 @@ testWithTypedArrayConstructors(function(TA) { '[0, 1, 2, 3].copyWithin(0, -2, -10) -> [0, 1, 2, 3]' ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, -2, -Infinity), + [1, 2, 3, 4, 5] + ) + '[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) -> [1, 2, 3, 4, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3]).copyWithin(0, -9, -10), @@ -53,6 +69,14 @@ testWithTypedArrayConstructors(function(TA) { '[0, 1, 2, 3].copyWithin(0, -9, -10) -> [0, 1, 2, 3]' ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, -9, -Infinity), + [1, 2, 3, 4, 5] + ) + '[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) -> [1, 2, 3, 4, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3]).copyWithin(-3, -2, -10), @@ -61,6 +85,14 @@ testWithTypedArrayConstructors(function(TA) { '[0, 1, 2, 3].copyWithin(-3, -2, -10) -> [0, 1, 2, 3]' ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-3, -2, -Infinity), + [1, 2, 3, 4, 5] + ) + '[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) -> [1, 2, 3, 4, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3]).copyWithin(-7, -8, -9), @@ -68,4 +100,12 @@ testWithTypedArrayConstructors(function(TA) { ), '[0, 1, 2, 3].copyWithin(-7, -8, -9) -> [0, 1, 2, 3]' ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-7, -8, -Infinity), + [1, 2, 3, 4, 5] + ) + '[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) -> [1, 2, 3, 4, 5]' + ); }); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js b/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js index 4c1a258ef5..af9341165f 100644 --- a/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js +++ b/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-start.js @@ -35,6 +35,14 @@ testWithTypedArrayConstructors(function(TA) { '[0, 1, 2, 3]).copyWithin(0, -10) -> [0, 1, 2, 3]' ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, -Infinity), + [0, 1, 2, 3] + ), + '[1, 2, 3, 4, 5]).copyWithin(0, -Infinity) -> [1, 2, 3, 4, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3, 4]).copyWithin(2, -10), @@ -43,6 +51,14 @@ testWithTypedArrayConstructors(function(TA) { '[0, 1, 2, 3, 4]).copyWithin(2, -2) -> [0, 1, 0, 1, 2]' ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(2, -Infinity), + [1, 2, 1, 2, 3] + ), + '[1, 2, 3, 4, 5]).copyWithin(2, -Infinity) -> [1, 2, 1, 2, 3]' + ); + assert( compareArray( new TA([0, 1, 2, 3, 4]).copyWithin(10, -10), @@ -51,6 +67,14 @@ testWithTypedArrayConstructors(function(TA) { '[0, 1, 2, 3, 4]).copyWithin(10, -10) -> [0, 1, 2, 3, 4]' ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(10, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5]).copyWithin(10, -Infinity) -> [1, 2, 3, 4, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3]).copyWithin(-9, -10), @@ -58,4 +82,12 @@ testWithTypedArrayConstructors(function(TA) { ), '[0, 1, 2, 3].copyWithin(-9, -10) -> [0, 1, 2, 3]' ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-9, -Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(-9, -Infinity) -> [1, 2, 3, 4, 5]' + ); }); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js b/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js index bb27644bfd..ed074fd896 100644 --- a/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js +++ b/test/built-ins/TypedArray/prototype/copyWithin/negative-out-of-bounds-target.js @@ -35,6 +35,14 @@ testWithTypedArrayConstructors(function(TA) { '[0, 1, 2, 3].copyWithin(-10, 0) -> [0, 1, 2, 3]' ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-Infinity, 0), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 0) -> [1, 2, 3, 4, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3, 4]).copyWithin(-10, 2), @@ -42,4 +50,12 @@ testWithTypedArrayConstructors(function(TA) { ), '[0, 1, 2, 3, 4].copyWithin(-10, 2) -> [2, 3, 4, 3, 4]' ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(-Infinity, 2), + [3, 4, 5, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 2) -> [3, 4, 5, 4, 5]' + ); }); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js b/test/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js index f5f1b77bbc..e681e282d0 100644 --- a/test/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js +++ b/test/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-end.js @@ -28,6 +28,14 @@ testWithTypedArrayConstructors(function(TA) { '[0, 1, 2, 3].copyWithin(0, 1, 6) -> [1, 2, 3, 3]' ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, 1, Infinity), + [2, 3, 4, 5, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(0, 1, Infinity) -> [2, 3, 4, 5, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3, 4, 5]).copyWithin(1, 3, 6), @@ -35,4 +43,12 @@ testWithTypedArrayConstructors(function(TA) { ), '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6) -> [0, 3, 4, 5, 4, 5]' ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(1, 3, Infinity), + [1, 4, 5, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(1, 3, Infinity) -> [1, 4, 5, 4, 5]' + ); }); diff --git a/test/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js b/test/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js index 6fc8351a5d..c0e022ccd2 100644 --- a/test/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js +++ b/test/built-ins/TypedArray/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js @@ -27,6 +27,14 @@ testWithTypedArrayConstructors(function(TA) { ) ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(Infinity, 0), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(Infinity, 0) -> [1, 2, 3, 4, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3, 4, 5]).copyWithin(0, 6), @@ -34,6 +42,14 @@ testWithTypedArrayConstructors(function(TA) { ) ); + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(0, Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(0, Infinity) -> [1, 2, 3, 4, 5]' + ); + assert( compareArray( new TA([0, 1, 2, 3, 4, 5]).copyWithin(6, 6), @@ -47,4 +63,12 @@ testWithTypedArrayConstructors(function(TA) { [0, 1, 2, 3, 4, 5] ) ); + + assert( + compareArray( + new TA([1, 2, 3, 4, 5]).copyWithin(Infinity, Infinity), + [1, 2, 3, 4, 5] + ), + '[1, 2, 3, 4, 5].copyWithin(Infinity, Infinity) -> [1, 2, 3, 4, 5]' + ); }); -- GitLab