diff --git a/test/built-ins/String/prototype/endsWith/coerced-values-of-position.js b/test/built-ins/String/prototype/endsWith/coerced-values-of-position.js new file mode 100644 index 0000000000..59f53ebb83 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/coerced-values-of-position.js @@ -0,0 +1,36 @@ +// 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.6 +description: > + Returns based on coerced values of endPosition. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 10. If endPosition is undefined, let pos be len, else let pos be + ToInteger(endPosition). + 11. ReturnIfAbrupt(pos). + 12. Let end be min(max(pos, 0), len). + 13. Let searchLength be the number of elements in searchStr. + 14. Let start be end - searchLength. + 15. If start is less than 0, return false. + 16. If the sequence of elements of S starting at start of length searchLength + is the same as the full element sequence of searchStr, return true. + 17. Otherwise, return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert(str.endsWith('', NaN), 'NaN coerced to 0'); +assert(str.endsWith('', null), 'null coerced to 0'); +assert(str.endsWith('', false), 'false coerced to 0'); +assert(str.endsWith('', ''), '"" coerced to 0'); +assert(str.endsWith('', '0'), '"0" coerced to 0'); +assert(str.endsWith('', undefined), 'undefined coerced to 0'); + +assert(str.endsWith('The future', 10.4), '10.4 coerced to 10'); +assert(str.endsWith('T', true), 'true coerced to 1'); + +assert(str.endsWith('The future', '10'), '"10" coerced to 10'); diff --git a/test/built-ins/String/prototype/endsWith/endsWith.js b/test/built-ins/String/prototype/endsWith/endsWith.js new file mode 100644 index 0000000000..323b4df1cb --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/endsWith.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.6 +description: > + Property type and descriptor. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + typeof String.prototype.endsWith, + 'function', + '`typeof String.prototype.endsWith` is `function`' +); + +verifyNotEnumerable(String.prototype, 'endsWith'); +verifyWritable(String.prototype, 'endsWith'); +verifyConfigurable(String.prototype, 'endsWith'); diff --git a/test/built-ins/String/prototype/endsWith/length.js b/test/built-ins/String/prototype/endsWith/length.js new file mode 100644 index 0000000000..94d1bacdba --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/length.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.6 +description: > + String.prototype.endsWith.length value and descriptor. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + The length property of the endsWith method is 1. + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.prototype.endsWith.length, 1, + 'The value of `String.prototype.endsWith.length` is `1`' +); + +verifyNotEnumerable(String.prototype.endsWith, 'length'); +verifyNotWritable(String.prototype.endsWith, 'length'); +verifyConfigurable(String.prototype.endsWith, 'length'); diff --git a/test/built-ins/String/prototype/endsWith/name.js b/test/built-ins/String/prototype/endsWith/name.js new file mode 100644 index 0000000000..6dd674f0df --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/name.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.6 +description: > + String.prototype.endsWith.name value and descriptor. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +---*/ + +assert.sameValue( + String.prototype.endsWith.name, 'endsWith', + 'The value of `String.prototype.endsWith.name` is `"endsWith"`' +); + +verifyNotEnumerable(String.prototype.endsWith, 'name'); +verifyNotWritable(String.prototype.endsWith, 'name'); +verifyConfigurable(String.prototype.endsWith, 'name'); diff --git a/test/built-ins/String/prototype/endsWith/return-abrupt-from-position-as-symbol.js b/test/built-ins/String/prototype/endsWith/return-abrupt-from-position-as-symbol.js new file mode 100644 index 0000000000..6c0ad476ac --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/return-abrupt-from-position-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.6 +description: > + Returns abrupt from ToInteger(endPosition) as a Symbol. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 10. If endPosition is undefined, let pos be len, else let pos be + ToInteger(endPosition). + 11. ReturnIfAbrupt(pos). + ... +features: [Symbol] +---*/ + +var position = Symbol(); + +assert.throws(TypeError, function() { + ''.endsWith('', position); +}); diff --git a/test/built-ins/String/prototype/endsWith/return-abrupt-from-position.js b/test/built-ins/String/prototype/endsWith/return-abrupt-from-position.js new file mode 100644 index 0000000000..e7916d9241 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/return-abrupt-from-position.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.6 +description: > + Returns abrupt from ToInteger(endPosition). +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 10. If endPosition is undefined, let pos be len, else let pos be + ToInteger(endPosition). + 11. ReturnIfAbrupt(pos). + ... +---*/ + +var position = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.endsWith('', position); +}); diff --git a/test/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-as-symbol.js b/test/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-as-symbol.js new file mode 100644 index 0000000000..568316cd8c --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-as-symbol.js @@ -0,0 +1,21 @@ +// 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.6 +description: > + Returns abrupt from ToString(searchString) as a Symbol +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 7. Let searchStr be ToString(searchString). + 8. ReturnIfAbrupt(searchStr). + ... +features: [Symbol] +---*/ + +var s = Symbol(); + +assert.throws(TypeError, function() { + ''.endsWith(s); +}); diff --git a/test/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-regexp-test.js b/test/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-regexp-test.js new file mode 100644 index 0000000000..ea46e0404c --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-regexp-test.js @@ -0,0 +1,42 @@ +// 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.6 +description: > + Returns abrupt from IsRegExp(searchString). +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 4. Let isRegExp be IsRegExp(searchString). + 5. ReturnIfAbrupt(isRegExp). + ... + + 7.2.8 IsRegExp ( argument ) + + 2. Let isRegExp be Get(argument, @@match). + 3. ReturnIfAbrupt(isRegExp). +features: [Symbol.match] +---*/ + +var obj = {}; +Object.defineProperty(obj, Symbol.match, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + ''.endsWith(obj); +}); + +var regexp = /./; +Object.defineProperty(regexp, Symbol.match, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + ''.endsWith(regexp); +}); diff --git a/test/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring.js b/test/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring.js new file mode 100644 index 0000000000..9497b73de7 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring.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.6 +description: > + Returns abrupt from ToString(searchString) +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 7. Let searchStr be ToString(searchString). + 8. ReturnIfAbrupt(searchStr). + ... +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.endsWith(obj); +}); diff --git a/test/built-ins/String/prototype/endsWith/return-abrupt-from-this-as-symbol.js b/test/built-ins/String/prototype/endsWith/return-abrupt-from-this-as-symbol.js new file mode 100644 index 0000000000..8e17dc66ab --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/return-abrupt-from-this-as-symbol.js @@ -0,0 +1,21 @@ +// 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.6 +description: > + Returns abrupt from ToString(this) where this is a Symbol +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + 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.endsWith.call(s, ''); +}); diff --git a/test/built-ins/String/prototype/endsWith/return-abrupt-from-this.js b/test/built-ins/String/prototype/endsWith/return-abrupt-from-this.js new file mode 100644 index 0000000000..4e1d6aa8d2 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/return-abrupt-from-this.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.6 +description: > + Returns abrupt from ToString(this) +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + 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.endsWith.call(o, ''); +}); diff --git a/test/built-ins/String/prototype/endsWith/return-false-if-search-start-is-less-than-zero.js b/test/built-ins/String/prototype/endsWith/return-false-if-search-start-is-less-than-zero.js new file mode 100644 index 0000000000..c3c139ec1c --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/return-false-if-search-start-is-less-than-zero.js @@ -0,0 +1,32 @@ +// 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.6 +description: > + Returns false if search start is less than 0. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 9. Let len be the number of elements in S. + 10. If endPosition is undefined, let pos be len, else let pos be + ToInteger(endPosition). + 11. ReturnIfAbrupt(pos). + 12. Let end be min(max(pos, 0), len). + 13. Let searchLength be the number of elements in searchStr. + 14. Let start be end - searchLength. + 15. If start is less than 0, return false. + ... + + Note: (min(max(pos, 0), len) - searchString.length) < 0; +---*/ + +assert.sameValue( + 'web'.endsWith('w', 0), false, + '"web".endsWith("w", 0) returns false' +); + +assert.sameValue( + 'Bob'.endsWith(' Bob'), false, + '"Bob".endsWith(" Bob") returns false' +); diff --git a/test/built-ins/String/prototype/endsWith/return-true-if-searchstring-is-empty.js b/test/built-ins/String/prototype/endsWith/return-true-if-searchstring-is-empty.js new file mode 100644 index 0000000000..2188726e2e --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/return-true-if-searchstring-is-empty.js @@ -0,0 +1,48 @@ +// 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.6 +description: > + Returns true if searchString.length == 0. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 10. If endPosition is undefined, let pos be len, else let pos be + ToInteger(endPosition). + 11. ReturnIfAbrupt(pos). + 12. Let end be min(max(pos, 0), len). + 13. Let searchLength be the number of elements in searchStr. + 14. Let start be end - searchLength. + 15. If start is less than 0, return false. + 16. If the sequence of elements of S starting at start of length searchLength + is the same as the full element sequence of searchStr, return true. + ... +---*/ + +var str = 'The future is cool!'; + +assert( + str.endsWith(''), + 'str.endsWith("") returns true' +); + +assert( + str.endsWith('', str.length), + 'str.endsWith("", str.length) returns true' +); + +assert( + str.endsWith('', Infinity), + 'str.endsWith("", Infinity) returns true' +); + +assert( + str.endsWith('', -1), + 'str.endsWith("", -1) returns true' +); + +assert( + str.endsWith('', -Infinity), + 'str.endsWith("", -Infinity) returns true' +); \ No newline at end of file diff --git a/test/built-ins/String/prototype/endsWith/searchstring-found-with-position.js b/test/built-ins/String/prototype/endsWith/searchstring-found-with-position.js new file mode 100644 index 0000000000..cae2e6f013 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/searchstring-found-with-position.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.6 +description: > + Returns true if searchString appears as a substring of the given string with a + given position. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 10. If endPosition is undefined, let pos be len, else let pos be + ToInteger(endPosition). + 11. ReturnIfAbrupt(pos). + 12. Let end be min(max(pos, 0), len). + 13. Let searchLength be the number of elements in searchStr. + 14. Let start be end - searchLength. + 15. If start is less than 0, return false. + 16. If the sequence of elements of S starting at start of length searchLength + is the same as the full element sequence of searchStr, return true. + ... +---*/ + +var str = 'The future is cool!'; + +assert( + str.endsWith('The future', 10), + 'str.endsWith("The future", 10) === true' +); +assert( + str.endsWith('future', 10), + 'str.endsWith("future", 10) === true' +); +assert( + str.endsWith(' is cool!', str.length), + 'str.endsWith(" is cool!", str.length) === true' +); diff --git a/test/built-ins/String/prototype/endsWith/searchstring-found-without-position.js b/test/built-ins/String/prototype/endsWith/searchstring-found-without-position.js new file mode 100644 index 0000000000..731a01b1c9 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/searchstring-found-without-position.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.6 +description: > + Returns true if searchString appears as a substring of the given string. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 10. If endPosition is undefined, let pos be len, else let pos be + ToInteger(endPosition). + 11. ReturnIfAbrupt(pos). + 12. Let end be min(max(pos, 0), len). + 13. Let searchLength be the number of elements in searchStr. + 14. Let start be end - searchLength. + 15. If start is less than 0, return false. + 16. If the sequence of elements of S starting at start of length searchLength + is the same as the full element sequence of searchStr, return true. + ... +---*/ + +var str = 'The future is cool!'; + +assert(str.endsWith('cool!'), 'str.endsWith("cool!") === true'); +assert(str.endsWith('!'), 'str.endsWith("!") === true'); +assert(str.endsWith(str), 'str.endsWith(str) === true'); diff --git a/test/built-ins/String/prototype/endsWith/searchstring-is-regexp-throws.js b/test/built-ins/String/prototype/endsWith/searchstring-is-regexp-throws.js new file mode 100644 index 0000000000..4079b99f76 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/searchstring-is-regexp-throws.js @@ -0,0 +1,21 @@ +// 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.6 +description: > + Throws a TypeError if searchString is a RegExp. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 4. Let isRegExp be IsRegExp(searchString). + 5. ReturnIfAbrupt(isRegExp). + 6. If isRegExp is true, throw a TypeError exception. + ... +---*/ + +var searchString = /./; + +assert.throws(TypeError, function() { + ''.endsWith(searchString); +}); diff --git a/test/built-ins/String/prototype/endsWith/searchstring-not-found-with-position.js b/test/built-ins/String/prototype/endsWith/searchstring-not-found-with-position.js new file mode 100644 index 0000000000..60a6cc0762 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/searchstring-not-found-with-position.js @@ -0,0 +1,34 @@ +// 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.6 +description: > + Returns false if searchString is not found with a given position. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 10. If endPosition is undefined, let pos be len, else let pos be + ToInteger(endPosition). + 11. ReturnIfAbrupt(pos). + 12. Let end be min(max(pos, 0), len). + 13. Let searchLength be the number of elements in searchStr. + 14. Let start be end - searchLength. + 15. If start is less than 0, return false. + 16. If the sequence of elements of S starting at start of length searchLength + is the same as the full element sequence of searchStr, return true. + 17. Otherwise, return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert.sameValue( + str.endsWith('is cool!', str.length - 1), false, + 'str.endsWith("is cool!", str.length - 1) === false' +); + +assert.sameValue( + str.endsWith('!', 1), false, + 'str.endsWith("!", 1) === false' +); diff --git a/test/built-ins/String/prototype/endsWith/searchstring-not-found-without-position.js b/test/built-ins/String/prototype/endsWith/searchstring-not-found-without-position.js new file mode 100644 index 0000000000..ad0a93c19d --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/searchstring-not-found-without-position.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.6 +description: > + Returns false if searchString is not found. +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 10. If endPosition is undefined, let pos be len, else let pos be + ToInteger(endPosition). + 11. ReturnIfAbrupt(pos). + 12. Let end be min(max(pos, 0), len). + 13. Let searchLength be the number of elements in searchStr. + 14. Let start be end - searchLength. + 15. If start is less than 0, return false. + 16. If the sequence of elements of S starting at start of length searchLength + is the same as the full element sequence of searchStr, return true. + 17. Otherwise, return false. + ... +---*/ + +var str = 'The future is cool!'; + +assert.sameValue( + str.endsWith('is Flash!'), false, + 'str.endsWith("is Flash!") === false' +); +assert.sameValue( + str.endsWith('IS COOL!'), false, + 'endsWith is case sensitive' +); +assert.sameValue( + str.endsWith('The future'), false, + 'str.endsWith("The future") === false' +); diff --git a/test/built-ins/String/prototype/endsWith/this-is-null-throws.js b/test/built-ins/String/prototype/endsWith/this-is-null-throws.js new file mode 100644 index 0000000000..71449e9671 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/this-is-null-throws.js @@ -0,0 +1,16 @@ +// 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.6 +description: > + Throws TypeError when `this` is null +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). +---*/ + +assert.throws(TypeError, function() { + String.prototype.endsWith.call(null, ''); +}); diff --git a/test/built-ins/String/prototype/endsWith/this-is-undefined-throws.js b/test/built-ins/String/prototype/endsWith/this-is-undefined-throws.js new file mode 100644 index 0000000000..3e174b05b7 --- /dev/null +++ b/test/built-ins/String/prototype/endsWith/this-is-undefined-throws.js @@ -0,0 +1,16 @@ +// 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.6 +description: > + Throws TypeError when `this` is undefined +info: > + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). +---*/ + +assert.throws(TypeError, function() { + String.prototype.endsWith.call(undefined, ''); +});