summaryrefslogtreecommitdiff
path: root/test/built-ins/TypedArray
diff options
context:
space:
mode:
authorLeonardo Balter <leonardo.balter@gmail.com>2016-04-27 12:08:09 -0400
committerMike Pennisi <mike@mikepennisi.com>2016-05-05 16:59:25 -0400
commit19c09e95d98cb450f34f7fd220bf0d7983f3e2df (patch)
tree2b104e749a117dba362c24d3ed53779d602d1d2a /test/built-ins/TypedArray
parente6f4b2083439dc1b1917a95be30400de2639250d (diff)
downloadqtdeclarative-testsuites-19c09e95d98cb450f34f7fd220bf0d7983f3e2df.tar.gz
Add tests for TypedArrays join
Diffstat (limited to 'test/built-ins/TypedArray')
-rw-r--r--test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-simple-value.js77
-rw-r--r--test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js134
-rw-r--r--test/built-ins/TypedArray/prototype/join/empty-instance-empty-string.js28
-rw-r--r--test/built-ins/TypedArray/prototype/join/get-length-uses-internal-arraylength.js44
-rw-r--r--test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-simple-value.js36
-rw-r--r--test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js43
-rw-r--r--test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator-symbol.js32
-rw-r--r--test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator.js35
8 files changed, 429 insertions, 0 deletions
diff --git a/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-simple-value.js b/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-simple-value.js
new file mode 100644
index 000000000..b0792e4d3
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-simple-value.js
@@ -0,0 +1,77 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.join
+description: >
+ Concatenates the result of toString for each value with custom separator
+info: >
+ 22.2.3.15 %TypedArray%.prototype.join ( separator )
+
+ %TypedArray%.prototype.join is a distinct function that implements the same
+ algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this
+ object's [[ArrayLength]] internal slot is accessed in place of performing a
+ [[Get]] of "length".
+
+ 22.1.3.13 Array.prototype.join (separator)
+
+ ...
+ 7. If element0 is undefined or null, let R be the empty String; otherwise, let
+ R be ? ToString(element0).
+ 8. Let k be 1.
+ 9. Repeat, while k < len
+ a. Let S be the String value produced by concatenating R and sep.
+ b. Let element be ? Get(O, ! ToString(k)).
+ c. If element is undefined or null, let next be the empty String; otherwise,
+ let next be ? ToString(element).
+ d. Let R be a String value produced by concatenating S and next.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([1, 0, 2, 3, 42, 127]);
+
+ var result;
+
+ result = sample.join(",");
+ assert.sameValue(result, "1,0,2,3,42,127");
+
+ result = sample.join(undefined);
+ assert.sameValue(result, "1,0,2,3,42,127");
+
+ result = sample.join(null);
+ assert.sameValue(result, "1null0null2null3null42null127");
+
+ result = sample.join(",,");
+ assert.sameValue(result, "1,,0,,2,,3,,42,,127");
+
+ result = sample.join(0);
+ assert.sameValue(result, "10002030420127");
+
+ result = sample.join("");
+ assert.sameValue(result, "102342127");
+
+ result = sample.join(" a b c ");
+ assert.sameValue(result, "1 a b c 0 a b c 2 a b c 3 a b c 42 a b c 127");
+
+ result = sample.join({});
+ assert.sameValue(result, "1[object Object]0[object Object]2[object Object]3[object Object]42[object Object]127");
+
+ result = sample.join(true);
+ assert.sameValue(result, "1true0true2true3true42true127");
+
+ result = sample.join({ toString: function() { return "foo"; }});
+ assert.sameValue(result, "1foo0foo2foo3foo42foo127");
+
+ result = sample.join({ toString: undefined, valueOf: function() { return "bar"; }});
+ assert.sameValue(result, "1bar0bar2bar3bar42bar127");
+
+ result = sample.join(false);
+ assert.sameValue(result, "1false0false2false3false42false127");
+
+ result = sample.join(-1);
+ assert.sameValue(result, "1-10-12-13-142-1127");
+
+ result = sample.join(-0);
+ assert.sameValue(result, "10002030420127");
+});
diff --git a/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js b/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js
new file mode 100644
index 000000000..b4223fcba
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js
@@ -0,0 +1,134 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.join
+description: >
+ Concatenates the result of toString for each value with custom separator
+info: >
+ 22.2.3.15 %TypedArray%.prototype.join ( separator )
+
+ %TypedArray%.prototype.join is a distinct function that implements the same
+ algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this
+ object's [[ArrayLength]] internal slot is accessed in place of performing a
+ [[Get]] of "length".
+
+ 22.1.3.13 Array.prototype.join (separator)
+
+ ...
+ 7. If element0 is undefined or null, let R be the empty String; otherwise, let
+ R be ? ToString(element0).
+ 8. Let k be 1.
+ 9. Repeat, while k < len
+ a. Let S be the String value produced by concatenating R and sep.
+ b. Let element be ? Get(O, ! ToString(k)).
+ c. If element is undefined or null, let next be the empty String; otherwise,
+ let next be ? ToString(element).
+ d. Let R be a String value produced by concatenating S and next.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+var arr = [-2, Infinity, NaN, -Infinity, 0.6, 9007199254740992];
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(arr);
+ var result, separator, expected;
+
+ separator = ",";
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected);
+
+ separator = undefined;
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = null;
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = ",,";
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = 0;
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = "";
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = " a b c ";
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = {};
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = { toString: function() { return "foo"; }};
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = { toString: undefined, valueOf: function() { return "bar"; }};
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = true;
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = false;
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = 1;
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+
+ separator = 0;
+ expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join(separator);
+ result = sample.join(separator);
+ assert.sameValue(result, expected, "using: " + separator);
+});
diff --git a/test/built-ins/TypedArray/prototype/join/empty-instance-empty-string.js b/test/built-ins/TypedArray/prototype/join/empty-instance-empty-string.js
new file mode 100644
index 000000000..45ad40425
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/join/empty-instance-empty-string.js
@@ -0,0 +1,28 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.join
+description: Return the empty String if length is 0
+info: >
+ 22.2.3.15 %TypedArray%.prototype.join ( separator )
+
+ %TypedArray%.prototype.join is a distinct function that implements the same
+ algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this
+ object's [[ArrayLength]] internal slot is accessed in place of performing a
+ [[Get]] of "length".
+
+ 22.1.3.13 Array.prototype.join (separator)
+
+ ...
+ 4. Let sep be ? ToString(separator).
+ 5. If len is zero, return the empty String.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+
+ assert.sameValue(sample.join(), "");
+ assert.sameValue(sample.join("test262"), "");
+});
diff --git a/test/built-ins/TypedArray/prototype/join/get-length-uses-internal-arraylength.js b/test/built-ins/TypedArray/prototype/join/get-length-uses-internal-arraylength.js
new file mode 100644
index 000000000..2bb04041d
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/join/get-length-uses-internal-arraylength.js
@@ -0,0 +1,44 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.join
+description: Get "length" uses internal ArrayLength
+info: >
+ 22.2.3.15 %TypedArray%.prototype.join ( separator )
+
+ %TypedArray%.prototype.join is a distinct function that implements the same
+ algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this
+ object's [[ArrayLength]] internal slot is accessed in place of performing a
+ [[Get]] of "length".
+
+ 22.1.3.13 Array.prototype.join (separator)
+
+ 1. Let O be ? ToObject(this value).
+ 2. Let len be ? ToLength(? Get(O, "length")).
+ ...
+ 5. If len is zero, return the empty String.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+var getCalls = 0;
+var desc = {
+ get: function getLen() {
+ getCalls++;
+ return 0;
+ }
+};
+
+Object.defineProperty(TypedArray.prototype, "length", desc);
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([42, 43]);
+
+ Object.defineProperty(TA.prototype, "length", desc);
+ Object.defineProperty(sample, "length", desc);
+
+ var result = sample.join();
+
+ assert.sameValue(getCalls, 0, "ignores length properties");
+ assert.notSameValue(result, "", "result is not affected but custom length 0");
+});
diff --git a/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-simple-value.js b/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-simple-value.js
new file mode 100644
index 000000000..a30798278
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-simple-value.js
@@ -0,0 +1,36 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.join
+description: Concatenates the result of toString for each simple value
+info: >
+ 22.2.3.15 %TypedArray%.prototype.join ( separator )
+
+ %TypedArray%.prototype.join is a distinct function that implements the same
+ algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this
+ object's [[ArrayLength]] internal slot is accessed in place of performing a
+ [[Get]] of "length".
+
+ 22.1.3.13 Array.prototype.join (separator)
+
+ ...
+ 7. If element0 is undefined or null, let R be the empty String; otherwise, let
+ R be ? ToString(element0).
+ 8. Let k be 1.
+ 9. Repeat, while k < len
+ a. Let S be the String value produced by concatenating R and sep.
+ b. Let element be ? Get(O, ! ToString(k)).
+ c. If element is undefined or null, let next be the empty String; otherwise,
+ let next be ? ToString(element).
+ d. Let R be a String value produced by concatenating S and next.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA([1, 0, 2, 3, 42, 127]);
+
+ var result = sample.join();
+
+ assert.sameValue(result, "1,0,2,3,42,127");
+});
diff --git a/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js b/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js
new file mode 100644
index 000000000..6baecc9a7
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js
@@ -0,0 +1,43 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.join
+description: Concatenates the result of toString for each value
+info: >
+ 22.2.3.15 %TypedArray%.prototype.join ( separator )
+
+ %TypedArray%.prototype.join is a distinct function that implements the same
+ algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this
+ object's [[ArrayLength]] internal slot is accessed in place of performing a
+ [[Get]] of "length".
+
+ 22.1.3.13 Array.prototype.join (separator)
+
+ ...
+ 7. If element0 is undefined or null, let R be the empty String; otherwise, let
+ R be ? ToString(element0).
+ 8. Let k be 1.
+ 9. Repeat, while k < len
+ a. Let S be the String value produced by concatenating R and sep.
+ b. Let element be ? Get(O, ! ToString(k)).
+ c. If element is undefined or null, let next be the empty String; otherwise,
+ let next be ? ToString(element).
+ d. Let R be a String value produced by concatenating S and next.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+var arr = [-2, Infinity, NaN, -Infinity, 0.6, 9007199254740992];
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA(arr);
+
+ // Use converted values using Array methods as helpers
+ var expected = arr.map(function(_, i) {
+ return sample[i].toString();
+ }).join();
+
+ var result = sample.join();
+
+ assert.sameValue(result, expected);
+});
diff --git a/test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator-symbol.js b/test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator-symbol.js
new file mode 100644
index 000000000..1d99c799e
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator-symbol.js
@@ -0,0 +1,32 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.join
+description: Return abrupt from ToString(Symbol separator)
+info: >
+ 22.2.3.15 %TypedArray%.prototype.join ( separator )
+
+ %TypedArray%.prototype.join is a distinct function that implements the same
+ algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this
+ object's [[ArrayLength]] internal slot is accessed in place of performing a
+ [[Get]] of "length".
+
+ 22.1.3.13 Array.prototype.join (separator)
+
+ ...
+ 4. Let sep be ? ToString(separator).
+ 5. If len is zero, return the empty String.
+ ...
+includes: [testTypedArray.js]
+features: [Symbol]
+---*/
+
+var s = Symbol("");
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+
+ assert.throws(TypeError, function() {
+ sample.join(s);
+ });
+});
diff --git a/test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator.js b/test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator.js
new file mode 100644
index 000000000..38a0ac8df
--- /dev/null
+++ b/test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator.js
@@ -0,0 +1,35 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.join
+description: Return abrupt from ToString(separator)
+info: >
+ 22.2.3.15 %TypedArray%.prototype.join ( separator )
+
+ %TypedArray%.prototype.join is a distinct function that implements the same
+ algorithm as Array.prototype.join as defined in 22.1.3.13 except that the this
+ object's [[ArrayLength]] internal slot is accessed in place of performing a
+ [[Get]] of "length".
+
+ 22.1.3.13 Array.prototype.join (separator)
+
+ ...
+ 4. Let sep be ? ToString(separator).
+ 5. If len is zero, return the empty String.
+ ...
+includes: [testTypedArray.js]
+---*/
+
+var obj = {
+ toString: function() {
+ throw new Test262Error();
+ }
+};
+
+testWithTypedArrayConstructors(function(TA) {
+ var sample = new TA();
+
+ assert.throws(Test262Error, function() {
+ sample.join(obj);
+ });
+});