diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/endsWith')
29 files changed, 721 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail.js new file mode 100644 index 0000000000..6c130e2297 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail.js @@ -0,0 +1,12 @@ +// Copyright (c) 2014 Ryan Lewis. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ryan Lewis +description: endsWith should return false when called on 'word' and passed 'r'. +features: [String.prototype.endsWith] +---*/ + +assert.sameValue('word'.endsWith('r'), false, '"word".endsWith("r")'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail_2.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail_2.js new file mode 100644 index 0000000000..18e2ddd4e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Fail_2.js @@ -0,0 +1,14 @@ +// Copyright (c) 2014 Ryan Lewis. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ryan Lewis +description: > + endsWith should return false when called on 'word' and passed 'd', + with an endPosition of 3. +features: [String.prototype.endsWith] +---*/ + +assert.sameValue('word'.endsWith('d', 3), false, '"word".endsWith("d", 3)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success.js new file mode 100644 index 0000000000..1d58e3a9fd --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success.js @@ -0,0 +1,14 @@ +// Copyright (c) 2014 Ryan Lewis. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ryan Lewis +description: > + endsWith should return true when called on 'word' and passed 'd' + and with no endPosition (defaults to 4). +features: [String.prototype.endsWith] +---*/ + +assert.sameValue('word'.endsWith('d'), true, '"word".endsWith("d")'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_2.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_2.js new file mode 100644 index 0000000000..03b97f024e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_2.js @@ -0,0 +1,14 @@ +// Copyright (c) 2014 Ryan Lewis. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ryan Lewis +description: > + endsWith should return true when called on 'word' and passed 'd' + and with an endPosition of 4. +features: [String.prototype.endsWith] +---*/ + +assert.sameValue('word'.endsWith('d', 4), true, '"word".endsWith("d", 4)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_3.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_3.js new file mode 100644 index 0000000000..9d2a03a672 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_3.js @@ -0,0 +1,14 @@ +// Copyright (c) 2014 Ryan Lewis. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ryan Lewis +description: > + endsWith should return true when called on 'word' and passed 'd' + and with an endPosition of 25. +features: [String.prototype.endsWith] +---*/ + +assert.sameValue('word'.endsWith('d', 25), true, '"word".endsWith("d", 25)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_4.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_4.js new file mode 100644 index 0000000000..19956fc76d --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/String.prototype.endsWith_Success_4.js @@ -0,0 +1,14 @@ +// Copyright (c) 2014 Ryan Lewis. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ryan Lewis +description: > + endsWith should return true when called on 'word' and passed 'r', + with an endPosition of 3. +features: [String.prototype.endsWith] +---*/ + +assert.sameValue('word'.endsWith('r', 3), true, '"word".endsWith("r", 3)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/browser.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/coerced-values-of-position.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/coerced-values-of-position.js new file mode 100644 index 0000000000..5b8ce9acd7 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/coerced-values-of-position.js @@ -0,0 +1,39 @@ +// 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. + ... +features: [String.prototype.endsWith] +---*/ + +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/endsWith.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/endsWith.js new file mode 100644 index 0000000000..e33b121a23 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/endsWith.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: > + Property type and descriptor. +info: | + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [String.prototype.endsWith] +---*/ + +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/length.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/length.js new file mode 100644 index 0000000000..d5040bab96 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/length.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: > + 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] +features: [String.prototype.endsWith] +---*/ + +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/name.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/name.js new file mode 100644 index 0000000000..d4aa6ee5f5 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/name.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: > + 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] +features: [String.prototype.endsWith] +---*/ + +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/not-a-constructor.js new file mode 100644 index 0000000000..2112ea842d --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/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.endsWith 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, String.prototype.endsWith, arrow-function] +---*/ + +assert.sameValue( + isConstructor(String.prototype.endsWith), + false, + 'isConstructor(String.prototype.endsWith) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.endsWith(); +}, '`new String.prototype.endsWith()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-position-as-symbol.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-position-as-symbol.js new file mode 100644 index 0000000000..6c035f420e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-position-as-symbol.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 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, String.prototype.endsWith] +---*/ + +var position = Symbol(); + +assert.throws(TypeError, function() { + ''.endsWith('', position); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-position.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-position.js new file mode 100644 index 0000000000..86c26233a1 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-position.js @@ -0,0 +1,28 @@ +// 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). + ... +features: [String.prototype.endsWith] +---*/ + +var position = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.endsWith('', position); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-as-symbol.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-as-symbol.js new file mode 100644 index 0000000000..33e6cf455a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-as-symbol.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(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, String.prototype.endsWith] +---*/ + +var s = Symbol(); + +assert.throws(TypeError, function() { + ''.endsWith(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-regexp-test.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-regexp-test.js new file mode 100644 index 0000000000..165b14f6f1 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring-regexp-test.js @@ -0,0 +1,44 @@ +// 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, String.prototype.endsWith] +---*/ + +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring.js new file mode 100644 index 0000000000..915803e6b6 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-searchstring.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 abrupt from ToString(searchString) +info: | + 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition] ) + + ... + 7. Let searchStr be ToString(searchString). + 8. ReturnIfAbrupt(searchStr). + ... +features: [String.prototype.endsWith] +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.endsWith(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-this-as-symbol.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-this-as-symbol.js new file mode 100644 index 0000000000..8930406092 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-this-as-symbol.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) 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, String.prototype.endsWith] +---*/ + +var s = Symbol(''); + +assert.throws(TypeError, function() { + String.prototype.endsWith.call(s, ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-this.js new file mode 100644 index 0000000000..5ad458c006 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-abrupt-from-this.js @@ -0,0 +1,26 @@ +// 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). +features: [String.prototype.endsWith] +---*/ + +var o = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.endsWith.call(o, ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/return-false-if-search-start-is-less-than-zero.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-false-if-search-start-is-less-than-zero.js new file mode 100644 index 0000000000..37ec778399 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-false-if-search-start-is-less-than-zero.js @@ -0,0 +1,35 @@ +// 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; +features: [String.prototype.endsWith] +---*/ + +assert.sameValue( + 'web'.endsWith('w', 0), false, + '"web".endsWith("w", 0) returns false' +); + +assert.sameValue( + 'Bob'.endsWith(' Bob'), false, + '"Bob".endsWith(" Bob") returns false' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/return-true-if-searchstring-is-empty.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-true-if-searchstring-is-empty.js new file mode 100644 index 0000000000..1871492039 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/return-true-if-searchstring-is-empty.js @@ -0,0 +1,51 @@ +// 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. + ... +features: [String.prototype.endsWith] +---*/ + +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' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-found-with-position.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-found-with-position.js new file mode 100644 index 0000000000..0c0445e1fe --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-found-with-position.js @@ -0,0 +1,40 @@ +// 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. + ... +features: [String.prototype.endsWith] +---*/ + +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' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-found-without-position.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-found-without-position.js new file mode 100644 index 0000000000..3eabfafb4d --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-found-without-position.js @@ -0,0 +1,30 @@ +// 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. + ... +features: [String.prototype.endsWith] +---*/ + +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-is-regexp-throws.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-is-regexp-throws.js new file mode 100644 index 0000000000..8cdf821300 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-is-regexp-throws.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: > + 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. + ... +features: [String.prototype.endsWith] +---*/ + +var searchString = /./; + +assert.throws(TypeError, function() { + ''.endsWith(searchString); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-not-found-with-position.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-not-found-with-position.js new file mode 100644 index 0000000000..cf7bb58854 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-not-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 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. + ... +features: [String.prototype.endsWith] +---*/ + +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' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-not-found-without-position.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-not-found-without-position.js new file mode 100644 index 0000000000..58e6f1f63a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/searchstring-not-found-without-position.js @@ -0,0 +1,40 @@ +// 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. + ... +features: [String.prototype.endsWith] +---*/ + +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' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/shell.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/shell.js diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/this-is-null-throws.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/this-is-null-throws.js new file mode 100644 index 0000000000..7828dd9e71 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/this-is-null-throws.js @@ -0,0 +1,19 @@ +// 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). +features: [String.prototype.endsWith] +---*/ + +assert.throws(TypeError, function() { + String.prototype.endsWith.call(null, ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/endsWith/this-is-undefined-throws.js b/js/src/tests/test262/built-ins/String/prototype/endsWith/this-is-undefined-throws.js new file mode 100644 index 0000000000..f0b95cd90a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/endsWith/this-is-undefined-throws.js @@ -0,0 +1,19 @@ +// 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). +features: [String.prototype.endsWith] +---*/ + +assert.throws(TypeError, function() { + String.prototype.endsWith.call(undefined, ''); +}); + +reportCompare(0, 0); |