diff --git a/test/built-ins/String/prototype/codePointAt/codePointAt.js b/test/built-ins/String/prototype/codePointAt/codePointAt.js new file mode 100644 index 0000000000000000000000000000000000000000..62324d612e406819c177bffa04e0caa8ad78d937 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/codePointAt.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Property type and descriptor. +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof String.prototype.codePointAt, + 'function', + '`typeof String.prototype.codePointAt` is `function`' +); + +verifyNotEnumerable(String.prototype, 'codePointAt'); +verifyWritable(String.prototype, 'codePointAt'); +verifyConfigurable(String.prototype, 'codePointAt'); diff --git a/test/built-ins/String/prototype/codePointAt/length.js b/test/built-ins/String/prototype/codePointAt/length.js new file mode 100644 index 0000000000000000000000000000000000000000..6dab7b836c710885e71b5f856aadf28c90a4dd4c --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/length.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + String.prototype.codePointAt.length value and descriptor. +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.prototype.codePointAt.length, 1, + 'The value of `String.prototype.codePointAt.length` is `1`' +); + +verifyNotEnumerable(String.prototype.codePointAt, 'length'); +verifyNotWritable(String.prototype.codePointAt, 'length'); +verifyConfigurable(String.prototype.codePointAt, 'length'); diff --git a/test/built-ins/String/prototype/codePointAt/name.js b/test/built-ins/String/prototype/codePointAt/name.js new file mode 100644 index 0000000000000000000000000000000000000000..e42c2bb518cbef766ade53329dd70756714789e5 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + String.prototype.codePointAt.name value and descriptor. +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.prototype.codePointAt.name, 'codePointAt', + 'The value of `String.prototype.codePointAt.name` is `"codePointAt"`' +); + +verifyNotEnumerable(String.prototype.codePointAt, 'name'); +verifyNotWritable(String.prototype.codePointAt, 'name'); +verifyConfigurable(String.prototype.codePointAt, 'name'); diff --git a/test/built-ins/String/prototype/codePointAt/return-abrupt-from-object-pos-to-integer.js b/test/built-ins/String/prototype/codePointAt/return-abrupt-from-object-pos-to-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..a2fc781e73e74cbe82c6bc4608b308da33dd5461 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/return-abrupt-from-object-pos-to-integer.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Returns abrupt from ToInteger(pos) +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). + 4. Let position be ToInteger(pos). + 5. ReturnIfAbrupt(position). +---*/ + +var o = { + valueOf: function() { + throw new Test262Error(); + } +} + +assert.throws(Test262Error, function() { + 'abc'.codePointAt(o); +}); diff --git a/test/built-ins/String/prototype/codePointAt/return-abrupt-from-symbol-pos-to-integer.js b/test/built-ins/String/prototype/codePointAt/return-abrupt-from-symbol-pos-to-integer.js new file mode 100644 index 0000000000000000000000000000000000000000..5bbdfa528521c93e9e9d44cb84bd7a6df2b55ef0 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/return-abrupt-from-symbol-pos-to-integer.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Returns abrupt from ToInteger(pos) +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). + 4. Let position be ToInteger(pos). + 5. ReturnIfAbrupt(position). +features: [Symbol] +---*/ + +var s = Symbol(1); + +assert.throws(TypeError, function() { + 'abc'.codePointAt(s); +}); diff --git a/test/built-ins/String/prototype/codePointAt/return-abrupt-from-this-as-symbol.js b/test/built-ins/String/prototype/codePointAt/return-abrupt-from-this-as-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..c8c27d960f051a8052683423b7cc992fb42a0366 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/return-abrupt-from-this-as-symbol.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Returns abrupt from ToString(this) where this is a Symbol +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). +features: [Symbol] +---*/ + +var s = Symbol(); + +assert.throws(TypeError, function() { + String.prototype.codePointAt.call(s, 1); +}); diff --git a/test/built-ins/String/prototype/codePointAt/return-abrupt-from-this.js b/test/built-ins/String/prototype/codePointAt/return-abrupt-from-this.js new file mode 100644 index 0000000000000000000000000000000000000000..8088314b9af36447b650a54fe84e2c325802b48a --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/return-abrupt-from-this.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Returns abrupt from ToString(this) +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). +---*/ + +var o = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.codePointAt.call(o, 1); +}); diff --git a/test/built-ins/String/prototype/codePointAt/return-code-unit-coerced-position.js b/test/built-ins/String/prototype/codePointAt/return-code-unit-coerced-position.js new file mode 100644 index 0000000000000000000000000000000000000000..ed8c34380612a4cc68dd35d53b4ef49c2576f429 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/return-code-unit-coerced-position.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Return value on coerced values on ToInteger(position). +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + ... + 4. Let position be ToInteger(pos). + ... + +---*/ + +assert.sameValue('\uD800\uDC00'.codePointAt(''), 65536); +assert.sameValue('\uD800\uDC00'.codePointAt('0'), 65536); +assert.sameValue('\uD800\uDC00'.codePointAt(NaN), 65536); +assert.sameValue('\uD800\uDC00'.codePointAt(false), 65536); +assert.sameValue('\uD800\uDC00'.codePointAt(null), 65536); +assert.sameValue('\uD800\uDC00'.codePointAt(undefined), 65536); +assert.sameValue('\uD800\uDC00'.codePointAt([]), 65536); + +assert.sameValue('\uD800\uDC00'.codePointAt('1'), 56320); +assert.sameValue('\uD800\uDC00'.codePointAt(true), 56320); +assert.sameValue('\uD800\uDC00'.codePointAt([1]), 56320); diff --git a/test/built-ins/String/prototype/codePointAt/return-first-code-unit.js b/test/built-ins/String/prototype/codePointAt/return-first-code-unit.js new file mode 100644 index 0000000000000000000000000000000000000000..0546658e7acecd34cdc8153178d68e3e4da5cec0 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/return-first-code-unit.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Returns code point of LeadSurrogate if not followed by a valid TrailSurrogate. +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + ... + 8. Let first be the code unit value of the element at index position in the + String S. + 9. If first < 0xD800 or first > 0xDBFF or position+1 = size, return first. + 10. Let second be the code unit value of the element at index position+1 in + the String S. + 11. If second < 0xDC00 or second > 0xDFFF, return first. +---*/ + +assert.sameValue('\uD800\uDBFF'.codePointAt(0), 0xD800); +assert.sameValue('\uD800\uE000'.codePointAt(0), 0xD800); + +assert.sameValue('\uDAAA\uDBFF'.codePointAt(0), 0xDAAA); +assert.sameValue('\uDAAA\uE000'.codePointAt(0), 0xDAAA); + +assert.sameValue('\uDBFF\uDBFF'.codePointAt(0), 0xDBFF); +assert.sameValue('\uDBFF\uE000'.codePointAt(0), 0xDBFF); + +assert.sameValue('\uD800\u0000'.codePointAt(0), 0xD800); +assert.sameValue('\uD800\uFFFF'.codePointAt(0), 0xD800); + +assert.sameValue('\uDAAA\u0000'.codePointAt(0), 0xDAAA); +assert.sameValue('\uDAAA\uFFFF'.codePointAt(0), 0xDAAA); + +assert.sameValue('\uDBFF\uDBFF'.codePointAt(0), 0xDBFF); +assert.sameValue('\uDBFF\uFFFF'.codePointAt(0), 0xDBFF); diff --git a/test/built-ins/String/prototype/codePointAt/return-single-code-unit.js b/test/built-ins/String/prototype/codePointAt/return-single-code-unit.js new file mode 100644 index 0000000000000000000000000000000000000000..6f4ae90b00b93628f53294d42192c50b1967928a --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/return-single-code-unit.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Return single code unit value of the element at index position. +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). + 4. Let position be ToInteger(pos). + 5. ReturnIfAbrupt(position). + 6. Let size be the number of elements in S. + 7. If position < 0 or position ≥ size, return undefined. + 8. Let first be the code unit value of the element at index position in the + String S. + 9. If first < 0xD800 or first > 0xDBFF or position+1 = size, return first. +---*/ + +assert.sameValue('abc'.codePointAt(0), 97); +assert.sameValue('abc'.codePointAt(1), 98); +assert.sameValue('abc'.codePointAt(2), 99); + +assert.sameValue('\uAAAA\uBBBB'.codePointAt(0), 0xAAAA); +assert.sameValue('\uD7FF\uAAAA'.codePointAt(0), 0xD7FF); +assert.sameValue('\uDC00\uAAAA'.codePointAt(0), 0xDC00); +assert.sameValue('\uAAAA\uBBBB'.codePointAt(0), 0xAAAA); + +assert.sameValue('123\uD800'.codePointAt(3), 0xD800); +assert.sameValue('123\uDAAA'.codePointAt(3), 0xDAAA); +assert.sameValue('123\uDBFF'.codePointAt(3), 0xDBFF); diff --git a/test/built-ins/String/prototype/codePointAt/return-utf16-decode.js b/test/built-ins/String/prototype/codePointAt/return-utf16-decode.js new file mode 100644 index 0000000000000000000000000000000000000000..873216b88e9f1e22780ce93ccd626a455597c445 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/return-utf16-decode.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Return UTF16 Decode value of the lead and trail elements at index position. +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + ... + 8. Let first be the code unit value of the element at index position in the + String S. + 9. If first < 0xD800 or first > 0xDBFF or position+1 = size, return first. + 10. Let second be the code unit value of the element at index position+1 in + the String S. + 11. If second < 0xDC00 or second > 0xDFFF, return first. + 12. Return UTF16Decode(first, second). + + 10.1.2 Static Semantics: UTF16Decode( lead, trail ) + + Two code units, lead and trail, that form a UTF-16 surrogate pair are + converted to a code point by performing the following steps: + + 1. Assert: 0xD800 ≤ lead ≤ 0xDBFF and 0xDC00 ≤ trail ≤ 0xDFFF. + 2. Let cp be (lead – 0xD800) × 1024 + (trail – 0xDC00) + 0x10000. + 3. Return the code point cp. +---*/ + +assert.sameValue('\uD800\uDC00'.codePointAt(0), 65536, 'U+10000'); +assert.sameValue('\uD800\uDDD0'.codePointAt(0), 66000, 'U+101D0'); +assert.sameValue('\uD800\uDFFF'.codePointAt(0), 66559, 'U+103FF'); + +assert.sameValue('\uDAAA\uDC00'.codePointAt(0), 763904, 'U+BA800'); +assert.sameValue('\uDAAA\uDDD0'.codePointAt(0), 764368, 'U+BA9D0'); +assert.sameValue('\uDAAA\uDFFF'.codePointAt(0), 764927, 'U+BABFF'); + +assert.sameValue('\uDBFF\uDC00'.codePointAt(0), 1113088, 'U+10FC00'); +assert.sameValue('\uDBFF\uDDD0'.codePointAt(0), 1113552, 'U+10FDD0'); +assert.sameValue('\uDBFF\uDFFF'.codePointAt(0), 1114111, 'U+10FFFF'); diff --git a/test/built-ins/String/prototype/codePointAt/returns-undefined-on-position-equal-or-more-than-size.js b/test/built-ins/String/prototype/codePointAt/returns-undefined-on-position-equal-or-more-than-size.js new file mode 100644 index 0000000000000000000000000000000000000000..216bf7029cea7a3c0c24f242f6ade2d4e18b72ba --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/returns-undefined-on-position-equal-or-more-than-size.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + If pos >= size, return undefined +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). + 4. Let position be ToInteger(pos). + 5. ReturnIfAbrupt(position). + 6. Let size be the number of elements in S. + 7. If position < 0 or position ≥ size, return undefined. +---*/ + +assert.sameValue('abc'.codePointAt(3), undefined); +assert.sameValue('abc'.codePointAt(4), undefined); +assert.sameValue('abc'.codePointAt(Infinity), undefined); diff --git a/test/built-ins/String/prototype/codePointAt/returns-undefined-on-position-less-than-zero.js b/test/built-ins/String/prototype/codePointAt/returns-undefined-on-position-less-than-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..f20eb5544a38257368f806abce704815f5f69515 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/returns-undefined-on-position-less-than-zero.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + If pos < size, return undefined +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). + 4. Let position be ToInteger(pos). + 5. ReturnIfAbrupt(position). + 6. Let size be the number of elements in S. + 7. If position < 0 or position ≥ size, return undefined. +---*/ + +assert.sameValue('abc'.codePointAt(-1), undefined); +assert.sameValue('abc'.codePointAt(-Infinity), undefined); diff --git a/test/built-ins/String/prototype/codePointAt/this-is-null-throws.js b/test/built-ins/String/prototype/codePointAt/this-is-null-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..c092187c7570c687dfdf80873073ec4ac53220c6 --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/this-is-null-throws.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Throws TypeError when `this` is null +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). +---*/ + +assert.throws(TypeError, function() { + String.prototype.codePointAt.call(null, 1); +}); diff --git a/test/built-ins/String/prototype/codePointAt/this-is-undefined-throws.js b/test/built-ins/String/prototype/codePointAt/this-is-undefined-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..961717a9c24ebbc8921ca924c2ffc35725498dda --- /dev/null +++ b/test/built-ins/String/prototype/codePointAt/this-is-undefined-throws.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 21.1.3.3 +description: > + Throws TypeError when `this` is undefined +info: > + 21.1.3.3 String.prototype.codePointAt ( pos ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). +---*/ + +assert.throws(TypeError, function() { + String.prototype.codePointAt.call(undefined, 1); +});