diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/codePointAt')
18 files changed, 427 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/browser.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/codePointAt.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/codePointAt.js new file mode 100644 index 0000000000..1838f1e274 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/codePointAt.js @@ -0,0 +1,24 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/length.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/length.js new file mode 100644 index 0000000000..99acb42698 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/length.js @@ -0,0 +1,24 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/name.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/name.js new file mode 100644 index 0000000000..db3ce58ddc --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/name.js @@ -0,0 +1,24 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/not-a-constructor.js new file mode 100644 index 0000000000..56d31f5280 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + String.prototype.codePointAt does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.codePointAt), + false, + 'isConstructor(String.prototype.codePointAt) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.codePointAt(); +}, '`new String.prototype.codePointAt()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-object-pos-to-integer.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-object-pos-to-integer.js new file mode 100644 index 0000000000..354a5d43c4 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-object-pos-to-integer.js @@ -0,0 +1,27 @@ +// 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-symbol-pos-to-integer.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-symbol-pos-to-integer.js new file mode 100644 index 0000000000..fb59c85a1f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-symbol-pos-to-integer.js @@ -0,0 +1,24 @@ +// 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-this-as-symbol.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-this-as-symbol.js new file mode 100644 index 0000000000..ff7613d472 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-this-as-symbol.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 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-this.js new file mode 100644 index 0000000000..c83735ca0f --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-abrupt-from-this.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 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-code-unit-coerced-position.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-code-unit-coerced-position.js new file mode 100644 index 0000000000..637a6d035d --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-code-unit-coerced-position.js @@ -0,0 +1,28 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-first-code-unit.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-first-code-unit.js new file mode 100644 index 0000000000..dba2e3dc85 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-first-code-unit.js @@ -0,0 +1,37 @@ +// 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-single-code-unit.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-single-code-unit.js new file mode 100644 index 0000000000..b37fe8bab0 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-single-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: > + 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-utf16-decode.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-utf16-decode.js new file mode 100644 index 0000000000..42620b6277 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/return-utf16-decode.js @@ -0,0 +1,41 @@ +// 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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/returns-undefined-on-position-equal-or-more-than-size.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/returns-undefined-on-position-equal-or-more-than-size.js new file mode 100644 index 0000000000..57cf03d817 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/returns-undefined-on-position-equal-or-more-than-size.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: > + 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/returns-undefined-on-position-less-than-zero.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/returns-undefined-on-position-less-than-zero.js new file mode 100644 index 0000000000..087909a08e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/returns-undefined-on-position-less-than-zero.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: > + 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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/shell.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/shell.js diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/this-is-null-throws.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/this-is-null-throws.js new file mode 100644 index 0000000000..d6a23b7b6a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/this-is-null-throws.js @@ -0,0 +1,18 @@ +// 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/codePointAt/this-is-undefined-throws.js b/js/src/tests/test262/built-ins/String/prototype/codePointAt/this-is-undefined-throws.js new file mode 100644 index 0000000000..edc798df09 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/codePointAt/this-is-undefined-throws.js @@ -0,0 +1,18 @@ +// 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); +}); + +reportCompare(0, 0); |