mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 21:45:04 +02:00
Add tests for TypedArrays join
This commit is contained in:
parent
e6f4b20834
commit
19c09e95d9
@ -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");
|
||||||
|
});
|
134
test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js
vendored
Normal file
134
test/built-ins/TypedArray/prototype/join/custom-separator-result-from-tostring-on-each-value.js
vendored
Normal file
@ -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);
|
||||||
|
});
|
28
test/built-ins/TypedArray/prototype/join/empty-instance-empty-string.js
vendored
Normal file
28
test/built-ins/TypedArray/prototype/join/empty-instance-empty-string.js
vendored
Normal file
@ -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"), "");
|
||||||
|
});
|
44
test/built-ins/TypedArray/prototype/join/get-length-uses-internal-arraylength.js
vendored
Normal file
44
test/built-ins/TypedArray/prototype/join/get-length-uses-internal-arraylength.js
vendored
Normal file
@ -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");
|
||||||
|
});
|
36
test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-simple-value.js
vendored
Normal file
36
test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-simple-value.js
vendored
Normal file
@ -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");
|
||||||
|
});
|
43
test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js
vendored
Normal file
43
test/built-ins/TypedArray/prototype/join/result-from-tostring-on-each-value.js
vendored
Normal file
@ -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);
|
||||||
|
});
|
32
test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator-symbol.js
vendored
Normal file
32
test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator-symbol.js
vendored
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
});
|
35
test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator.js
vendored
Normal file
35
test/built-ins/TypedArray/prototype/join/return-abrupt-from-separator.js
vendored
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user