diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/padStart')
15 files changed, 273 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/browser.js b/js/src/tests/test262/built-ins/String/prototype/padStart/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/exception-fill-string-symbol.js b/js/src/tests/test262/built-ins/String/prototype/padStart/exception-fill-string-symbol.js new file mode 100644 index 0000000000..95d085bd77 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/exception-fill-string-symbol.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: String#padStart should fail if given a Symbol fillString. +author: Jordan Harband +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + 'abc'.padStart(10, Symbol()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/exception-not-object-coercible.js b/js/src/tests/test262/built-ins/String/prototype/padStart/exception-not-object-coercible.js new file mode 100644 index 0000000000..c690928c09 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/exception-not-object-coercible.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: > + String#padStart should fail if given a null or undefined value, + or an object not coercible to a string. +author: Jordan Harband +---*/ + +assert.throws(TypeError, function() { + String.prototype.padStart.call(null); +}); + +assert.throws(TypeError, function() { + String.prototype.padStart.call(undefined); +}); + +var notCoercible = { + toString: function() { + throw new Test262Error('attempted toString'); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.padStart.call(notCoercible); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/exception-symbol.js b/js/src/tests/test262/built-ins/String/prototype/padStart/exception-symbol.js new file mode 100644 index 0000000000..0c9de71626 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/exception-symbol.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: String#padStart should fail if given a Symbol receiver. +author: Jordan Harband +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + String.prototype.padStart.call(Symbol()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/fill-string-empty.js b/js/src/tests/test262/built-ins/String/prototype/padStart/fill-string-empty.js new file mode 100644 index 0000000000..5d73afac3a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/fill-string-empty.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: > + String#padStart should return the string unchanged when + an explicit empty string is provided +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padStart(5, ''), 'abc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/fill-string-non-strings.js b/js/src/tests/test262/built-ins/String/prototype/padStart/fill-string-non-strings.js new file mode 100644 index 0000000000..cd1f0edc82 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/fill-string-non-strings.js @@ -0,0 +1,17 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: String#padStart should stringify a non-string fillString value +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padStart(10, false), 'falsefaabc'); +assert.sameValue('abc'.padStart(10, true), 'truetruabc'); +assert.sameValue('abc'.padStart(10, null), 'nullnulabc'); +assert.sameValue('abc'.padStart(10, 0), '0000000abc'); +assert.sameValue('abc'.padStart(10, -0), '0000000abc'); +assert.sameValue('abc'.padStart(10, NaN), 'NaNNaNNabc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/fill-string-omitted.js b/js/src/tests/test262/built-ins/String/prototype/padStart/fill-string-omitted.js new file mode 100644 index 0000000000..13a20abf32 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/fill-string-omitted.js @@ -0,0 +1,13 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: String#padStart should default to a fillString of " " when omitted +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padStart(5), ' abc'); +assert.sameValue('abc'.padStart(5, undefined), ' abc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/function-length.js b/js/src/tests/test262/built-ins/String/prototype/padStart/function-length.js new file mode 100644 index 0000000000..056e797a01 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/function-length.js @@ -0,0 +1,17 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: String#padStart should have length 1 +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +assert.sameValue(String.prototype.padStart.length, 1, 'Expected String#padStart.length to be 1'); + +verifyNotEnumerable(String.prototype.padStart, 'length'); +verifyNotWritable(String.prototype.padStart, 'length'); +verifyConfigurable(String.prototype.padStart, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/function-name.js b/js/src/tests/test262/built-ins/String/prototype/padStart/function-name.js new file mode 100644 index 0000000000..f7fb59889b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/function-name.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: String#padStart should have name property with value 'padStart' +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.prototype.padStart.name, + 'padStart', + 'Expected String#padStart.name to be "padStart"' +); + +verifyNotEnumerable(String.prototype.padStart, 'name'); +verifyNotWritable(String.prototype.padStart, 'name'); +verifyConfigurable(String.prototype.padStart, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/function-property-descriptor.js b/js/src/tests/test262/built-ins/String/prototype/padStart/function-property-descriptor.js new file mode 100644 index 0000000000..b49c71a64c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/function-property-descriptor.js @@ -0,0 +1,15 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: String#padStart should be writable, non-enumerable, and configurable +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(String.prototype, 'padStart'); +verifyWritable(String.prototype, 'padStart'); +verifyConfigurable(String.prototype, 'padStart'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/max-length-not-greater-than-string.js b/js/src/tests/test262/built-ins/String/prototype/padStart/max-length-not-greater-than-string.js new file mode 100644 index 0000000000..44476ecad0 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/max-length-not-greater-than-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: > + String#padStart should return the string unchanged when an integer max + length is not greater than the string length +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padStart(undefined, 'def'), 'abc'); +assert.sameValue('abc'.padStart(null, 'def'), 'abc'); +assert.sameValue('abc'.padStart(NaN, 'def'), 'abc'); +assert.sameValue('abc'.padStart(-Infinity, 'def'), 'abc'); +assert.sameValue('abc'.padStart(0, 'def'), 'abc'); +assert.sameValue('abc'.padStart(-1, 'def'), 'abc'); +assert.sameValue('abc'.padStart(3, 'def'), 'abc'); +assert.sameValue('abc'.padStart(3.9999, 'def'), 'abc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/normal-operation.js b/js/src/tests/test262/built-ins/String/prototype/padStart/normal-operation.js new file mode 100644 index 0000000000..c18a0f58cb --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/normal-operation.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: String#padStart should work in the general case +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padStart(7, 'def'), 'defdabc'); +assert.sameValue('abc'.padStart(5, '*'), '**abc'); + +// surrogate pairs +assert.sameValue('abc'.padStart(6, '\uD83D\uDCA9'), '\uD83D\uDCA9\uD83Dabc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/padStart/not-a-constructor.js new file mode 100644 index 0000000000..22ae62b3b1 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/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.padStart 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.padStart), + false, + 'isConstructor(String.prototype.padStart) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.padStart(); +}, '`new String.prototype.padStart()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/observable-operations.js b/js/src/tests/test262/built-ins/String/prototype/padStart/observable-operations.js new file mode 100644 index 0000000000..470d53fdfd --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/observable-operations.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-string.prototype.padstart +description: String#padStart should perform observable operations in the correct order +author: Jordan Harband +---*/ + +var log = ""; + +function createPrimitiveObserver(name, string, value) { + return { + toString: function() { + log += '|toString:' + name; + return string; + }, + valueOf: function() { + log += '|valueOf:' + name; + return value; + } + }; +}; + +var receiver = createPrimitiveObserver('receiver', {}, 'abc'); + +var fillString = createPrimitiveObserver('fillString', {}, 'def'); + +var maxLength = createPrimitiveObserver('maxLength', 11, {}); + +var result = String.prototype.padStart.call(receiver, maxLength, fillString); + +assert.sameValue(result, 'defdefdeabc'); + +assert.sameValue(log, '|' + [ + 'toString:receiver', + 'valueOf:receiver', + 'valueOf:maxLength', + 'toString:maxLength', + 'toString:fillString', + 'valueOf:fillString' +].join('|'), log); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padStart/shell.js b/js/src/tests/test262/built-ins/String/prototype/padStart/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padStart/shell.js |