diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/at')
13 files changed, 302 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/at/browser.js b/js/src/tests/test262/built-ins/String/prototype/at/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/at/index-argument-tointeger.js b/js/src/tests/test262/built-ins/String/prototype/at/index-argument-tointeger.js new file mode 100644 index 0000000000..1265d2412b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/index-argument-tointeger.js @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.at +description: > + Property type and descriptor. +info: | + String.prototype.at( index ) + + Let relativeIndex be ? ToInteger(index). + +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +let valueOfCallCount = 0; +let index = { + valueOf() { + valueOfCallCount++; + return 1; + } +}; + +let s = "01"; + +assert.sameValue(s.at(index), '1', 's.at({valueOf() {valueOfCallCount++; return 1;}}) must return 1'); +assert.sameValue(valueOfCallCount, 1, 'The value of `valueOfCallCount` is 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/index-non-numeric-argument-tointeger-invalid.js b/js/src/tests/test262/built-ins/String/prototype/at/index-non-numeric-argument-tointeger-invalid.js new file mode 100644 index 0000000000..64a31c0120 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/index-non-numeric-argument-tointeger-invalid.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.at +description: > + Property type and descriptor. +info: | + String.prototype.at( index ) + + Let relativeIndex be ? ToInteger(index). + +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +let s = "01"; + +assert.throws(TypeError, () => { + s.at(Symbol()); +}, '`s.at(Symbol())` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/index-non-numeric-argument-tointeger.js b/js/src/tests/test262/built-ins/String/prototype/at/index-non-numeric-argument-tointeger.js new file mode 100644 index 0000000000..c7e56a2a94 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/index-non-numeric-argument-tointeger.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.at +description: > + Property type and descriptor. +info: | + String.prototype.at( index ) + + Let relativeIndex be ? ToInteger(index). + +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +let s = "01"; + +assert.sameValue(s.at(false), '0', 's.at(false) must return 0'); +assert.sameValue(s.at(null), '0', 's.at(null) must return 0'); +assert.sameValue(s.at(undefined), '0', 's.at(undefined) must return 0'); +assert.sameValue(s.at(""), '0', 's.at("") must return 0'); +assert.sameValue(s.at(function() {}), '0', 's.at(function() {}) must return 0'); +assert.sameValue(s.at([]), '0', 's.at([]) must return 0'); + +assert.sameValue(s.at(true), '1', 's.at(true) must return 1'); +assert.sameValue(s.at("1"), '1', 's.at("1") must return 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/length.js b/js/src/tests/test262/built-ins/String/prototype/at/length.js new file mode 100644 index 0000000000..d552c459bd --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/length.js @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.at +description: > + String.prototype.at.length value and descriptor. +info: | + String.prototype.at( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +assert.sameValue( + String.prototype.at.length, 1, + 'The value of String.prototype.at.length is 1' +); + +verifyNotEnumerable(String.prototype.at, 'length'); +verifyNotWritable(String.prototype.at, 'length'); +verifyConfigurable(String.prototype.at, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/name.js b/js/src/tests/test262/built-ins/String/prototype/at/name.js new file mode 100644 index 0000000000..46b8a44410 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.at +description: > + String.prototype.at.name value and descriptor. +info: | + String.prototype.at( index ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +assert.sameValue( + String.prototype.at.name, 'at', + 'The value of String.prototype.at.name is "at"' +); + +verifyProperty(String.prototype.at, 'name', { + enumerable: false, + writable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/prop-desc.js b/js/src/tests/test262/built-ins/String/prototype/at/prop-desc.js new file mode 100644 index 0000000000..2cc96c993b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/prop-desc.js @@ -0,0 +1,28 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.at +description: > + Property type and descriptor. +info: | + String.prototype.at( index ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +assert.sameValue( + typeof String.prototype.at, + 'function', + 'The value of `typeof String.prototype.at` is "function"' +); + +verifyProperty(String.prototype, 'at', { + enumerable: false, + writable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/String/prototype/at/return-abrupt-from-this.js new file mode 100644 index 0000000000..0dc4011fce --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/return-abrupt-from-this.js @@ -0,0 +1,24 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.at +description: > + Return abrupt from RequireObjectCoercible(this value). +info: | + String.prototype.at( index ) + + Let O be ? RequireObjectCoercible(this value). + +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +assert.throws(TypeError, () => { + String.prototype.at.call(undefined); +}, '`String.prototype.at.call(undefined)` throws TypeError'); + +assert.throws(TypeError, () => { + String.prototype.at.call(null); +}, '`String.prototype.at.call(null)` throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/returns-code-unit.js b/js/src/tests/test262/built-ins/String/prototype/at/returns-code-unit.js new file mode 100644 index 0000000000..08b1e049e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/returns-code-unit.js @@ -0,0 +1,32 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-String.prototype.at +description: > + The method should return an Iterator instance. +info: | + String.prototype.at ( ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfStringLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +let s = "12\uD80034"; + +assert.sameValue(s.at(0), "1", 's.at(0) must return "1"'); +assert.sameValue(s.at(1), "2", 's.at(1) must return "2"'); +assert.sameValue(s.at(2), "\uD800", 's.at(2) must return "\\uD800"'); +assert.sameValue(s.at(3), "3", 's.at(3) must return "3"'); +assert.sameValue(s.at(4), "4", 's.at(4) must return "4"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/returns-item-relative-index.js b/js/src/tests/test262/built-ins/String/prototype/at/returns-item-relative-index.js new file mode 100644 index 0000000000..9c3360f266 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/returns-item-relative-index.js @@ -0,0 +1,31 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-String.prototype.at +description: > + Returns the item value at the specified relative index +info: | + String.prototype.at ( ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfStringLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +let s = "12345"; + +assert.sameValue(s.at(0), "1", 's.at(0) must return "1"'); +assert.sameValue(s.at(-1), "5", 's.at(-1) must return "5"'); +assert.sameValue(s.at(-3), "3", 's.at(-3) must return "3"'); +assert.sameValue(s.at(-4), "2", 's.at(-4) must return "2"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/returns-item.js b/js/src/tests/test262/built-ins/String/prototype/at/returns-item.js new file mode 100644 index 0000000000..c71ce2d605 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/returns-item.js @@ -0,0 +1,32 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-String.prototype.at +description: > + Returns the item value at the specified index +info: | + String.prototype.at ( ) + + Let O be ? ToObject(this value). + Let len be ? LengthOfStringLike(O). + Let relativeIndex be ? ToInteger(index). + If relativeIndex ≥ 0, then + Let k be relativeIndex. + Else, + Let k be len + relativeIndex. + If k < 0 or k ≥ len, then return undefined. + Return ? Get(O, ! ToString(k)). + +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +let s = "12345"; + +assert.sameValue(s.at(0), "1", 's.at(0) must return "1"'); +assert.sameValue(s.at(1), "2", 's.at(1) must return "2"'); +assert.sameValue(s.at(2), "3", 's.at(2) must return "3"'); +assert.sameValue(s.at(3), "4", 's.at(3) must return "4"'); +assert.sameValue(s.at(4), "5", 's.at(4) must return "5"'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/returns-undefined-for-out-of-range-index.js b/js/src/tests/test262/built-ins/String/prototype/at/returns-undefined-for-out-of-range-index.js new file mode 100644 index 0000000000..4be2a96b67 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/returns-undefined-for-out-of-range-index.js @@ -0,0 +1,22 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-string.prototype.at +description: > + Creates an iterator from a custom object. +info: | + String.prototype.at( index ) + + If k < 0 or k ≥ len, then return undefined. +features: [String.prototype.at] +---*/ +assert.sameValue(typeof String.prototype.at, 'function'); + +let s = ""; + +assert.sameValue(s.at(-2), undefined, 's.at(-2) must return undefined'); // wrap around the end +assert.sameValue(s.at(0), undefined, 's.at(0) must return undefined'); +assert.sameValue(s.at(1), undefined, 's.at(1) must return undefined'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/at/shell.js b/js/src/tests/test262/built-ins/String/prototype/at/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/at/shell.js |