diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/String/prototype/includes | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/includes')
29 files changed, 697 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_FailBadLocation.js b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_FailBadLocation.js new file mode 100644 index 0000000000..73876d5392 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_FailBadLocation.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: > + String should return false if a location is passed that is + greather than the length of the string. +features: [String.prototype.includes] +---*/ + +assert.sameValue('word'.includes('w', 5), false, '"word".includes("w", 5)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_FailLocation.js b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_FailLocation.js new file mode 100644 index 0000000000..e8415f3e1e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_FailLocation.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: > + String should return false if a letter is not found in the word + starting from the passed location. +features: [String.prototype.includes] +---*/ + +assert.sameValue('word'.includes('o', 3), false, '"word".includes("o", 3)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_FailMissingLetter.js b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_FailMissingLetter.js new file mode 100644 index 0000000000..c9eb1245a7 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_FailMissingLetter.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: String should return false if a letter is not found in the word. +features: [String.prototype.includes] +---*/ + +assert.sameValue('word'.includes('a', 0), false, '"word".includes("a", 0)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_Success.js b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_Success.js new file mode 100644 index 0000000000..1651d00988 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_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: > + String should return true when called on 'word' and passed 'w' and + the location 0. +features: [String.prototype.includes] +---*/ + +assert.sameValue('word'.includes('w', 0), true, '"word".includes("w", 0)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_SuccessNoLocation.js b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_SuccessNoLocation.js new file mode 100644 index 0000000000..49551f6ab7 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_SuccessNoLocation.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: > + String should return true when called on 'word' and passed 'w' and + with no location (defaults to 0). +features: [String.prototype.includes] +---*/ + +assert.sameValue('word'.includes('w'), true, '"word".includes("w")'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_lengthProp.js b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_lengthProp.js new file mode 100644 index 0000000000..b268186511 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/String.prototype.includes_lengthProp.js @@ -0,0 +1,11 @@ +// 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: String should have the property length with size of 1. +features: [String.prototype.includes] +---*/ +assert.sameValue('word'.includes.length, 1, '"word".includes.length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/browser.js b/js/src/tests/test262/built-ins/String/prototype/includes/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/browser.js diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/coerced-values-of-position.js b/js/src/tests/test262/built-ins/String/prototype/includes/coerced-values-of-position.js new file mode 100644 index 0000000000..5976cde337 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/coerced-values-of-position.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.7 +description: > + Returns based on coerced values of position. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 9. Let pos be ToInteger(position). (If position is undefined, this step + produces the value 0). + 10. ReturnIfAbrupt(pos). + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +features: [String.prototype.includes] +---*/ + +var str = 'The future is cool!'; + +assert(str.includes('The future', NaN), 'NaN coerced to 0'); +assert(str.includes('The future', null), 'null coerced to 0'); +assert(str.includes('The future', false), 'false coerced to 0'); +assert(str.includes('The future', ''), '"" coerced to 0'); +assert(str.includes('The future', '0'), '"0" coerced to 0'); +assert(str.includes('The future', undefined), 'undefined coerced to 0'); +assert(str.includes('The future', 0.4), '0.4 coerced to 0'); + +assert(str.includes('The future', -1)); + +assert.sameValue(str.includes('The future', true), false, 'true coerced to 1'); +assert.sameValue(str.includes('The future', '1'), false, '"1" coerced to 1'); +assert.sameValue(str.includes('The future', 1.4), false, '1.4 coerced to 1'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/includes.js b/js/src/tests/test262/built-ins/String/prototype/includes/includes.js new file mode 100644 index 0000000000..e155f7effa --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/includes.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.7 +description: > + Property type and descriptor. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 17 ECMAScript Standard Built-in Objects +includes: [propertyHelper.js] +features: [String.prototype.includes] +---*/ + +assert.sameValue( + typeof String.prototype.includes, + 'function', + '`typeof String.prototype.includes` is `function`' +); + +verifyNotEnumerable(String.prototype, 'includes'); +verifyWritable(String.prototype, 'includes'); +verifyConfigurable(String.prototype, 'includes'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/length.js b/js/src/tests/test262/built-ins/String/prototype/includes/length.js new file mode 100644 index 0000000000..c74ad3f706 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/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.7 +description: > + String.prototype.includes.length value and descriptor. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [String.prototype.includes] +---*/ + +assert.sameValue( + String.prototype.includes.length, 1, + 'The value of `String.prototype.includes.length` is `1`' +); + +verifyNotEnumerable(String.prototype.includes, 'length'); +verifyNotWritable(String.prototype.includes, 'length'); +verifyConfigurable(String.prototype.includes, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/name.js b/js/src/tests/test262/built-ins/String/prototype/includes/name.js new file mode 100644 index 0000000000..24bf088db4 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/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.7 +description: > + String.prototype.includes.name value and descriptor. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 17 ECMAScript Standard Built-in Objects + +includes: [propertyHelper.js] +features: [String.prototype.includes] +---*/ + +assert.sameValue( + String.prototype.includes.name, 'includes', + 'The value of `String.prototype.includes.name` is `"includes"`' +); + +verifyNotEnumerable(String.prototype.includes, 'name'); +verifyNotWritable(String.prototype.includes, 'name'); +verifyConfigurable(String.prototype.includes, 'name'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/includes/not-a-constructor.js new file mode 100644 index 0000000000..f276a53f92 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/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.includes 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.includes), + false, + 'isConstructor(String.prototype.includes) must return false' +); + +assert.throws(TypeError, () => { + new String.prototype.includes(1); +}, '`new String.prototype.includes(1)` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-position-as-symbol.js b/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-position-as-symbol.js new file mode 100644 index 0000000000..9b54287580 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/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.7 +description: > + Returns abrupt from ToInteger(position) as a Symbol. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 9. Let pos be ToInteger(position). (If position is undefined, this step + produces the value 0). + 10. ReturnIfAbrupt(pos). + ... +features: [Symbol, String.prototype.includes] +---*/ + +var position = Symbol(); + +assert.throws(TypeError, function() { + ''.includes('', position); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-position.js b/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-position.js new file mode 100644 index 0000000000..440bcec201 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/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.7 +description: > + Returns abrupt from ToInteger(position). +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 9. Let pos be ToInteger(position). (If position is undefined, this step + produces the value 0). + 10. ReturnIfAbrupt(pos). + ... +features: [String.prototype.includes] +---*/ + +var position = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.includes('', position); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-searchstring-as-symbol.js b/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-searchstring-as-symbol.js new file mode 100644 index 0000000000..6aa47b08ba --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/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.7 +description: > + Returns abrupt from ToString(searchString) as a Symbol +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 7. Let searchStr be ToString(searchString). + 8. ReturnIfAbrupt(searchStr). + ... +features: [Symbol, String.prototype.includes] +---*/ + +var s = Symbol(); + +assert.throws(TypeError, function() { + ''.includes(s); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-searchstring-regexp-test.js b/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-searchstring-regexp-test.js new file mode 100644 index 0000000000..3b6f379e93 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/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.7 +description: > + Returns abrupt from IsRegExp(searchString). +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 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.includes] +---*/ + +var obj = {}; +Object.defineProperty(obj, Symbol.match, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + ''.includes(obj); +}); + +var regexp = /./; +Object.defineProperty(regexp, Symbol.match, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + ''.includes(regexp); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-searchstring.js b/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-searchstring.js new file mode 100644 index 0000000000..dbab997afc --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/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.7 +description: > + Returns abrupt from ToString(searchString) +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 7. Let searchStr be ToString(searchString). + 8. ReturnIfAbrupt(searchStr). + ... +features: [String.prototype.includes] +---*/ + +var obj = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + ''.includes(obj); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-this-as-symbol.js b/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-this-as-symbol.js new file mode 100644 index 0000000000..af8905d962 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-this-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.7 +description: > + Returns abrupt from ToString(this) where this is a Symbol +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). +features: [Symbol, String.prototype.includes] +---*/ + +var s = Symbol(''); + +assert.throws(TypeError, function() { + String.prototype.includes.call(s, ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-this.js new file mode 100644 index 0000000000..d811e7e12e --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/return-abrupt-from-this.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.7 +description: > + Returns abrupt from ToString(this) +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). + 3. ReturnIfAbrupt(S). +features: [String.prototype.includes] +---*/ +var o = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + String.prototype.includes.call(o, ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/return-false-with-out-of-bounds-position.js b/js/src/tests/test262/built-ins/String/prototype/includes/return-false-with-out-of-bounds-position.js new file mode 100644 index 0000000000..fda6edafc7 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/return-false-with-out-of-bounds-position.js @@ -0,0 +1,45 @@ +// 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.7 +description: > + Returns false if position is >= this.length and searchString.length > 0. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +features: [String.prototype.includes] +---*/ + +var str = 'The future is cool!'; + +assert.sameValue( + str.includes('!', str.length + 1), false, + 'str.includes("!", str.length + 1) returns false' +); + +assert.sameValue( + str.includes('!', 100), false, + 'str.includes("!", 100) returns false' +); + +assert.sameValue( + str.includes('!', Infinity), false, + 'str.includes("!", Infinity) returns false' +); + +assert.sameValue( + str.includes('!', str.length), false, + 'str.includes("!", str.length) returns false' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/return-true-if-searchstring-is-empty.js b/js/src/tests/test262/built-ins/String/prototype/includes/return-true-if-searchstring-is-empty.js new file mode 100644 index 0000000000..dfeaa58403 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/return-true-if-searchstring-is-empty.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.7 +description: > + Returns true if searchString.length == 0. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +features: [String.prototype.includes] +---*/ + +var str = 'The future is cool!'; + +assert( + str.includes('', str.length), + 'str.includes("", str.length) returns true' +); + +assert( + str.includes(''), + 'str.includes("") returns true' +); + +assert( + str.includes('', Infinity), + 'str.includes("", Infinity) returns true' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-found-with-position.js b/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-found-with-position.js new file mode 100644 index 0000000000..26907b4bd4 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-found-with-position.js @@ -0,0 +1,33 @@ +// 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.7 +description: > + Returns true if searchString appears as a substring of the given string with a + given position. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +features: [String.prototype.includes] +---*/ + +var str = 'The future is cool!'; + +assert( + str.includes('The future', 0), + 'Returns true for str.includes("The future", 0)' +); +assert(str.includes(' is ', 1), 'Returns true for str.includes(" is ", 1)'); +assert(str.includes('cool!', 10), 'Returns true for str.includes("cool!", 10)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-found-without-position.js b/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-found-without-position.js new file mode 100644 index 0000000000..11d9d92d8b --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-found-without-position.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.7 +description: > + Returns true if searchString appears as a substring of the given string. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +features: [String.prototype.includes] +---*/ + +var str = 'The future is cool!'; + +assert( + str.includes('The future'), + 'Returns true for str.includes("The future")' +); +assert(str.includes('is cool!'), 'Returns true for str.includes("is cool!")'); +assert(str.includes(str), 'Returns true for str.includes(str)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-is-regexp-throws.js b/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-is-regexp-throws.js new file mode 100644 index 0000000000..3006a4956a --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-is-regexp-throws.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.7 +description: > + Throws a TypeError if searchString is a RegExp. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 4. Let isRegExp be IsRegExp(searchString). + 5. ReturnIfAbrupt(isRegExp). + 6. If isRegExp is true, throw a TypeError exception. + ... +features: [String.prototype.includes] +---*/ +var searchString = /./; + +assert.throws(TypeError, function() { + ''.includes(searchString); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-not-found-with-position.js b/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-not-found-with-position.js new file mode 100644 index 0000000000..cf126204eb --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/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.7 +description: > + Returns false if searchString is not found with a given position. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +features: [String.prototype.includes] +---*/ +var str = 'The future is cool!'; + +assert.sameValue( + str.includes('The future', 1), false, + 'Returns false on str.includes("The future", 1)' +); + +assert.sameValue( + str.includes(str, 1), false, + 'Returns false on str.includes(str, 1)' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-not-found-without-position.js b/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-not-found-without-position.js new file mode 100644 index 0000000000..3888d0eb96 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/searchstring-not-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.7 +description: > + Returns false if searchString is not found. +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + ... + 11. Let len be the number of elements in S. + 12. Let start be min(max(pos, 0), len). + 13. Let searchLen be the number of elements in searchStr. + 14. If there exists any integer k not smaller than start such that k + + searchLen is not greater than len, and for all nonnegative integers j less + than searchLen, the code unit at index k+j of S is the same as the code unit + at index j of searchStr, return true; but if there is no such integer k, + return false. + ... +features: [String.prototype.includes] +---*/ +var str = 'The future is cool!'; + +assert.sameValue( + str.includes('Flash'), false, + 'Flash if not included' +); +assert.sameValue(str.includes('FUTURE'), false, 'includes is case sensitive'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/shell.js b/js/src/tests/test262/built-ins/String/prototype/includes/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/shell.js diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/this-is-null-throws.js b/js/src/tests/test262/built-ins/String/prototype/includes/this-is-null-throws.js new file mode 100644 index 0000000000..4bdee98384 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/this-is-null-throws.js @@ -0,0 +1,18 @@ +// 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.7 +description: > + Throws TypeError when `this` is null +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). +features: [String.prototype.includes] +---*/ +assert.throws(TypeError, function() { + String.prototype.includes.call(null, ''); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/String/prototype/includes/this-is-undefined-throws.js b/js/src/tests/test262/built-ins/String/prototype/includes/this-is-undefined-throws.js new file mode 100644 index 0000000000..230cb1cdb5 --- /dev/null +++ b/js/src/tests/test262/built-ins/String/prototype/includes/this-is-undefined-throws.js @@ -0,0 +1,18 @@ +// 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.7 +description: > + Throws TypeError when `this` is undefined +info: | + 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) + + 1. Let O be RequireObjectCoercible(this value). + 2. Let S be ToString(O). +features: [String.prototype.includes] +---*/ +assert.throws(TypeError, function() { + String.prototype.includes.call(undefined, ''); +}); + +reportCompare(0, 0); |