diff --git a/test/built-ins/String/prototype/padEnd/exception-fill-string-symbol.js b/test/built-ins/String/prototype/padEnd/exception-fill-string-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..1bd167844833d4e9631f51646d1fe158f5ade5be --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/exception-fill-string-symbol.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 fail if given a Symbol fillString. +author: Jordan Harband +features: [Symbol] +---*/ + +assert.throws(TypeError, function () { + 'abc'.padEnd(10, Symbol()); +}); diff --git a/test/built-ins/String/prototype/padEnd/exception-not-object-coercible.js b/test/built-ins/String/prototype/padEnd/exception-not-object-coercible.js new file mode 100644 index 0000000000000000000000000000000000000000..ef89429a2daf601da7650268135fe9abcddb0eb1 --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/exception-not-object-coercible.js @@ -0,0 +1,28 @@ +// 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); +}); diff --git a/test/built-ins/String/prototype/padEnd/exception-symbol.js b/test/built-ins/String/prototype/padEnd/exception-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..949d4d927b13778a815fc464d6c807924c288868 --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/exception-symbol.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 fail if given a Symbol receiver. +author: Jordan Harband +features: [Symbol] +---*/ + +assert.throws(TypeError, function () { + String.prototype.padEnd.call(Symbol()); +}); diff --git a/test/built-ins/String/prototype/padEnd/fill-string-empty.js b/test/built-ins/String/prototype/padEnd/fill-string-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..4b4547a83893bb3078f498105090882544455b6b --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/fill-string-empty.js @@ -0,0 +1,12 @@ +// 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'); diff --git a/test/built-ins/String/prototype/padEnd/fill-string-non-strings.js b/test/built-ins/String/prototype/padEnd/fill-string-non-strings.js new file mode 100644 index 0000000000000000000000000000000000000000..2549a783975524ae45456fe9f1703ff600dca723 --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/fill-string-non-strings.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 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'); diff --git a/test/built-ins/String/prototype/padEnd/fill-string-omitted.js b/test/built-ins/String/prototype/padEnd/fill-string-omitted.js new file mode 100644 index 0000000000000000000000000000000000000000..90a9bc35ec55c429929730aea0f636bbda018ba6 --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/fill-string-omitted.js @@ -0,0 +1,11 @@ +// 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 '); diff --git a/test/built-ins/String/prototype/padEnd/function-length.js b/test/built-ins/String/prototype/padEnd/function-length.js new file mode 100644 index 0000000000000000000000000000000000000000..37ea2a27e976774ae2e760c82a699ff100df5b3b --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/function-length.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 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'); diff --git a/test/built-ins/String/prototype/padEnd/function-name.js b/test/built-ins/String/prototype/padEnd/function-name.js new file mode 100644 index 0000000000000000000000000000000000000000..0b6b7db74a700a291b79a5aaafe622d72e3e893d --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/function-name.js @@ -0,0 +1,19 @@ +// 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'); diff --git a/test/built-ins/String/prototype/padEnd/function-property-descriptor.js b/test/built-ins/String/prototype/padEnd/function-property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..97d2ad37252797a383b6e6cedb17b765164cd854 --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/function-property-descriptor.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 be writable, non-enumerable, and configurable +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(String.prototype, 'padEnd'); +verifyWritable(String.prototype, 'padEnd'); +verifyConfigurable(String.prototype, 'padEnd'); diff --git a/test/built-ins/String/prototype/padEnd/max-length-not-greater-than-string.js b/test/built-ins/String/prototype/padEnd/max-length-not-greater-than-string.js new file mode 100644 index 0000000000000000000000000000000000000000..6d0dfa494b55b888a054aa0a0fbc6a6ea8025f37 --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/max-length-not-greater-than-string.js @@ -0,0 +1,19 @@ +// 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'); diff --git a/test/built-ins/String/prototype/padEnd/normal-operation.js b/test/built-ins/String/prototype/padEnd/normal-operation.js new file mode 100644 index 0000000000000000000000000000000000000000..35e4f424f11178e713041488faea138386940940 --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/normal-operation.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 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'); diff --git a/test/built-ins/String/prototype/padEnd/observable-operations.js b/test/built-ins/String/prototype/padEnd/observable-operations.js new file mode 100644 index 0000000000000000000000000000000000000000..38315b3c444454bc3a2b32c626f17152cbf891a6 --- /dev/null +++ b/test/built-ins/String/prototype/padEnd/observable-operations.js @@ -0,0 +1,42 @@ +// 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); diff --git a/test/built-ins/String/prototype/padStart/exception-fill-string-symbol.js b/test/built-ins/String/prototype/padStart/exception-fill-string-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..73f5435445c1fc88c381075dccca363ab4409909 --- /dev/null +++ b/test/built-ins/String/prototype/padStart/exception-fill-string-symbol.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 fail if given a Symbol fillString. +author: Jordan Harband +features: [Symbol] +---*/ + +assert.throws(TypeError, function () { + 'abc'.padStart(10, Symbol()); +}); diff --git a/test/built-ins/String/prototype/padStart/exception-not-object-coercible.js b/test/built-ins/String/prototype/padStart/exception-not-object-coercible.js new file mode 100644 index 0000000000000000000000000000000000000000..7d08deae0067c73add4c774045f96fbfefe7fc33 --- /dev/null +++ b/test/built-ins/String/prototype/padStart/exception-not-object-coercible.js @@ -0,0 +1,28 @@ +// 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); +}); diff --git a/test/built-ins/String/prototype/padStart/exception-symbol.js b/test/built-ins/String/prototype/padStart/exception-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..66521f28c3fd59b674cdede6701b8045f24a009f --- /dev/null +++ b/test/built-ins/String/prototype/padStart/exception-symbol.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 fail if given a Symbol receiver. +author: Jordan Harband +features: [Symbol] +---*/ + +assert.throws(TypeError, function () { + String.prototype.padStart.call(Symbol()); +}); diff --git a/test/built-ins/String/prototype/padStart/fill-string-empty.js b/test/built-ins/String/prototype/padStart/fill-string-empty.js new file mode 100644 index 0000000000000000000000000000000000000000..b1ba8377a70ab89edd51254b78c2e12daf2f6ee4 --- /dev/null +++ b/test/built-ins/String/prototype/padStart/fill-string-empty.js @@ -0,0 +1,12 @@ +// 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'); diff --git a/test/built-ins/String/prototype/padStart/fill-string-non-strings.js b/test/built-ins/String/prototype/padStart/fill-string-non-strings.js new file mode 100644 index 0000000000000000000000000000000000000000..acbb73ea77086a74b0853c626f79fbffce050dc7 --- /dev/null +++ b/test/built-ins/String/prototype/padStart/fill-string-non-strings.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 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'); diff --git a/test/built-ins/String/prototype/padStart/fill-string-omitted.js b/test/built-ins/String/prototype/padStart/fill-string-omitted.js new file mode 100644 index 0000000000000000000000000000000000000000..829edbcb209e6cdaf0e85dcf8a449c46403920bc --- /dev/null +++ b/test/built-ins/String/prototype/padStart/fill-string-omitted.js @@ -0,0 +1,11 @@ +// 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'); diff --git a/test/built-ins/String/prototype/padStart/function-length.js b/test/built-ins/String/prototype/padStart/function-length.js new file mode 100644 index 0000000000000000000000000000000000000000..a096add5ede2488717c0d6b985f6f88332e56478 --- /dev/null +++ b/test/built-ins/String/prototype/padStart/function-length.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 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'); diff --git a/test/built-ins/String/prototype/padStart/function-name.js b/test/built-ins/String/prototype/padStart/function-name.js new file mode 100644 index 0000000000000000000000000000000000000000..0b63be0e4ed017c218bddafbba45cda6325fc5a1 --- /dev/null +++ b/test/built-ins/String/prototype/padStart/function-name.js @@ -0,0 +1,19 @@ +// 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'); diff --git a/test/built-ins/String/prototype/padStart/function-property-descriptor.js b/test/built-ins/String/prototype/padStart/function-property-descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..5fece20c26f20cbec280ea516f2143987c666032 --- /dev/null +++ b/test/built-ins/String/prototype/padStart/function-property-descriptor.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 be writable, non-enumerable, and configurable +author: Jordan Harband +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(String.prototype, 'padStart'); +verifyWritable(String.prototype, 'padStart'); +verifyConfigurable(String.prototype, 'padStart'); diff --git a/test/built-ins/String/prototype/padStart/max-length-not-greater-than-string.js b/test/built-ins/String/prototype/padStart/max-length-not-greater-than-string.js new file mode 100644 index 0000000000000000000000000000000000000000..1dac96fee6a1c813f3d826661b72c8918b9b5b1d --- /dev/null +++ b/test/built-ins/String/prototype/padStart/max-length-not-greater-than-string.js @@ -0,0 +1,19 @@ +// 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'); diff --git a/test/built-ins/String/prototype/padStart/normal-operation.js b/test/built-ins/String/prototype/padStart/normal-operation.js new file mode 100644 index 0000000000000000000000000000000000000000..f6f6b17cf94d53f9178c3448f7966aa0d3e9daeb --- /dev/null +++ b/test/built-ins/String/prototype/padStart/normal-operation.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 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'); diff --git a/test/built-ins/String/prototype/padStart/observable-operations.js b/test/built-ins/String/prototype/padStart/observable-operations.js new file mode 100644 index 0000000000000000000000000000000000000000..dfb9a0f2619ef53e39a2e1a0d4845740e6f37bda --- /dev/null +++ b/test/built-ins/String/prototype/padStart/observable-operations.js @@ -0,0 +1,42 @@ +// 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);