diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/padEnd')
15 files changed, 273 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/browser.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/exception-fill-string-symbol.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/exception-fill-string-symbol.js new file mode 100644 index 0000000000..37b9eb63ce --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: String#padEnd should fail if given a Symbol fillString. +author: Jordan Harband +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + 'abc'.padEnd(10, Symbol()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/exception-not-object-coercible.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/exception-not-object-coercible.js new file mode 100644 index 0000000000..ba7c08faf1 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: > + String#padEnd 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.padEnd.call(null); +}); + +assert.throws(TypeError, function() { + String.prototype.padEnd.call(undefined); +}); + +var notCoercible = { + toString: function() { + throw new Test262Error('attempted toString'); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.padEnd.call(notCoercible); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/exception-symbol.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/exception-symbol.js new file mode 100644 index 0000000000..deac35a8b7 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: String#padEnd should fail if given a Symbol receiver. +author: Jordan Harband +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + String.prototype.padEnd.call(Symbol()); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/fill-string-empty.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/fill-string-empty.js new file mode 100644 index 0000000000..e22ee5a185 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: > + String#padEnd should return the string unchanged when + an explicit empty string is provided +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padEnd(5, ''), 'abc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/fill-string-non-strings.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/fill-string-non-strings.js new file mode 100644 index 0000000000..76bbe749ce --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: String#padEnd should stringify a non-string fillString value +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padEnd(10, false), 'abcfalsefa'); +assert.sameValue('abc'.padEnd(10, true), 'abctruetru'); +assert.sameValue('abc'.padEnd(10, null), 'abcnullnul'); +assert.sameValue('abc'.padEnd(10, 0), 'abc0000000'); +assert.sameValue('abc'.padEnd(10, -0), 'abc0000000'); +assert.sameValue('abc'.padEnd(10, NaN), 'abcNaNNaNN'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/fill-string-omitted.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/fill-string-omitted.js new file mode 100644 index 0000000000..f0a6c475dc --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: String#padEnd should default to a fillString of " " when omitted +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padEnd(5), 'abc '); +assert.sameValue('abc'.padEnd(5, undefined), 'abc '); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/function-length.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/function-length.js new file mode 100644 index 0000000000..4b38c5a4a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: String#padEnd should have length 1 +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +assert.sameValue(String.prototype.padEnd.length, 1, 'Expected String#padEnd.length to be 1'); + +verifyNotEnumerable(String.prototype.padEnd, 'length'); +verifyNotWritable(String.prototype.padEnd, 'length'); +verifyConfigurable(String.prototype.padEnd, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/function-name.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/function-name.js new file mode 100644 index 0000000000..cf0c201497 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: String#padEnd should have name property with value 'padEnd' +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.prototype.padEnd.name, + 'padEnd', + 'Expected String#padEnd.name to be "padEnd"' +); + +verifyNotEnumerable(String.prototype.padEnd, 'name'); +verifyNotWritable(String.prototype.padEnd, 'name'); +verifyConfigurable(String.prototype.padEnd, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/function-property-descriptor.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/function-property-descriptor.js new file mode 100644 index 0000000000..9dd0ce8aec --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: String#padEnd should be writable, non-enumerable, and configurable +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(String.prototype, 'padEnd'); +verifyWritable(String.prototype, 'padEnd'); +verifyConfigurable(String.prototype, 'padEnd'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/max-length-not-greater-than-string.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/max-length-not-greater-than-string.js new file mode 100644 index 0000000000..79a4f59169 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: > + String#padEnd should return the string unchanged when an integer max + length is not greater than the string length +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padEnd(undefined, 'def'), 'abc'); +assert.sameValue('abc'.padEnd(null, 'def'), 'abc'); +assert.sameValue('abc'.padEnd(NaN, 'def'), 'abc'); +assert.sameValue('abc'.padEnd(-Infinity, 'def'), 'abc'); +assert.sameValue('abc'.padEnd(0, 'def'), 'abc'); +assert.sameValue('abc'.padEnd(-1, 'def'), 'abc'); +assert.sameValue('abc'.padEnd(3, 'def'), 'abc'); +assert.sameValue('abc'.padEnd(3.9999, 'def'), 'abc'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/normal-operation.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/normal-operation.js new file mode 100644 index 0000000000..0b5b1023da --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: String#padEnd should work in the general case +author: Jordan Harband +---*/ + +assert.sameValue('abc'.padEnd(7, 'def'), 'abcdefd'); +assert.sameValue('abc'.padEnd(5, '*'), 'abc**'); + +// surrogate pairs +assert.sameValue('abc'.padEnd(6, '\uD83D\uDCA9'), 'abc\uD83D\uDCA9\uD83D'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/not-a-constructor.js new file mode 100644 index 0000000000..ed5f84458c --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padEnd 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.padEnd), + false, + 'isConstructor(String.prototype.padEnd) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.padEnd(); +}, '`new String.prototype.padEnd()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/padEnd/observable-operations.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/observable-operations.js new file mode 100644 index 0000000000..6af105ca4b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/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.padend +description: String#padEnd 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.padEnd.call(receiver, maxLength, fillString); + +assert.sameValue(result, 'abcdefdefde'); + +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/padEnd/shell.js b/js/src/tests/test262/built-ins/String/prototype/padEnd/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/padEnd/shell.js |