summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/String/prototype/repeat
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/String/prototype/repeat')
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/count-coerced-to-zero-returns-empty-string.js24
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/count-is-infinity-throws.js17
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/count-is-zero-returns-empty-string.js17
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/count-less-than-zero-throws.js21
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/empty-string-returns-empty.js21
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/length.js24
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/name.js24
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/not-a-constructor.js35
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/repeat-string-n-times.js30
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/repeat.js24
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-count-as-symbol.js21
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-count.js24
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-this-as-symbol.js22
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-this.js25
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/shell.js0
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/this-is-null-throws.js18
-rw-r--r--js/src/tests/test262/built-ins/String/prototype/repeat/this-is-undefined-throws.js18
18 files changed, 365 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/browser.js b/js/src/tests/test262/built-ins/String/prototype/repeat/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/browser.js
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/count-coerced-to-zero-returns-empty-string.js b/js/src/tests/test262/built-ins/String/prototype/repeat/count-coerced-to-zero-returns-empty-string.js
new file mode 100644
index 0000000000..574a1731fd
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/count-coerced-to-zero-returns-empty-string.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.13
+description: >
+ If ToInteger(count) is zero, returns an empty String.
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 8. Let T be a String value that is made from n copies of S appended together.
+ If n is 0, T is the empty String.
+ 9. Return T.
+---*/
+
+var str = 'ES2015';
+
+assert.sameValue(str.repeat(NaN), '', 'str.repeat(NaN) returns ""');
+assert.sameValue(str.repeat(null), '', 'str.repeat(null) returns ""');
+assert.sameValue(str.repeat(undefined), '', 'str.repeat(undefined) returns ""');
+assert.sameValue(str.repeat(false), '', 'str.repeat(false) returns ""');
+assert.sameValue(str.repeat('0'), '', 'str.repeat("0") returns ""');
+assert.sameValue(str.repeat(0.9), '', 'str.repeat(0.9) returns ""');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/count-is-infinity-throws.js b/js/src/tests/test262/built-ins/String/prototype/repeat/count-is-infinity-throws.js
new file mode 100644
index 0000000000..f8ac8b0eba
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/count-is-infinity-throws.js
@@ -0,0 +1,17 @@
+// 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.13
+description: >
+ Throws a RangeError if count < 0
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 7. If n is +∞, throw a RangeError exception.
+---*/
+
+assert.throws(RangeError, function() {
+ ''.repeat(Infinity);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/count-is-zero-returns-empty-string.js b/js/src/tests/test262/built-ins/String/prototype/repeat/count-is-zero-returns-empty-string.js
new file mode 100644
index 0000000000..5a0403b5e7
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/count-is-zero-returns-empty-string.js
@@ -0,0 +1,17 @@
+// 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.13
+description: >
+ If count is zero, returns an empty String.
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 8. Let T be a String value that is made from n copies of S appended together.
+ If n is 0, T is the empty String.
+ 9. Return T.
+---*/
+
+assert.sameValue('foo'.repeat(0), '');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/count-less-than-zero-throws.js b/js/src/tests/test262/built-ins/String/prototype/repeat/count-less-than-zero-throws.js
new file mode 100644
index 0000000000..3d589395e8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/count-less-than-zero-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.13
+description: >
+ Throws a RangeError if count < 0
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 6. If n < 0, throw a RangeError exception.
+---*/
+
+assert.throws(RangeError, function() {
+ ''.repeat(-1);
+});
+
+assert.throws(RangeError, function() {
+ ''.repeat(-Infinity);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/empty-string-returns-empty.js b/js/src/tests/test262/built-ins/String/prototype/repeat/empty-string-returns-empty.js
new file mode 100644
index 0000000000..848bd5417a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/empty-string-returns-empty.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.13
+description: >
+ An empty repeated n times will return an empty string.
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 8. Let T be a String value that is made from n copies of S appended together.
+ If n is 0, T is the empty String.
+ 9. Return T.
+---*/
+
+assert.sameValue(''.repeat(1), '', '"".repeat(1)');
+assert.sameValue(''.repeat(3), '', '"".repeat(3)');
+
+var maxSafe32bitInt = 2147483647;
+assert.sameValue(''.repeat(maxSafe32bitInt), '', '"".repeat(maxSafe32bitInt)');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/length.js b/js/src/tests/test262/built-ins/String/prototype/repeat/length.js
new file mode 100644
index 0000000000..2151718be9
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/length.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.13
+description: >
+ String.prototype.repeat.length value and descriptor.
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+ String.prototype.repeat.length, 1,
+ 'The value of `String.prototype.repeat.length` is `1`'
+);
+
+verifyNotEnumerable(String.prototype.repeat, 'length');
+verifyNotWritable(String.prototype.repeat, 'length');
+verifyConfigurable(String.prototype.repeat, 'length');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/name.js b/js/src/tests/test262/built-ins/String/prototype/repeat/name.js
new file mode 100644
index 0000000000..3c640857de
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/name.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.13
+description: >
+ String.prototype.repeat.name value and descriptor.
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 17 ECMAScript Standard Built-in Objects
+
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+ String.prototype.repeat.name, 'repeat',
+ 'The value of `String.prototype.repeat.name` is `"repeat"`'
+);
+
+verifyNotEnumerable(String.prototype.repeat, 'name');
+verifyNotWritable(String.prototype.repeat, 'name');
+verifyConfigurable(String.prototype.repeat, 'name');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/not-a-constructor.js b/js/src/tests/test262/built-ins/String/prototype/repeat/not-a-constructor.js
new file mode 100644
index 0000000000..b8acfb0e7f
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/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.repeat 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.repeat),
+ false,
+ 'isConstructor(String.prototype.repeat) must return false'
+);
+
+assert.throws(TypeError, () => {
+ new String.prototype.repeat();
+}, '`new String.prototype.repeat()` throws TypeError');
+
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/repeat-string-n-times.js b/js/src/tests/test262/built-ins/String/prototype/repeat/repeat-string-n-times.js
new file mode 100644
index 0000000000..3e7905c1b4
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/repeat-string-n-times.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.13
+description: >
+ Returns a String made from n copies of the original String appended together.
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 8. Let T be a String value that is made from n copies of S appended together.
+ If n is 0, T is the empty String.
+ 9. Return T.
+---*/
+
+var str = 'abc';
+assert.sameValue(str.repeat(1), str, 'str.repeat(1) === str');
+assert.sameValue(str.repeat(3), 'abcabcabc', 'str.repeat(3) === "abcabcabc"');
+
+str = '';
+var i = 0;
+var count = 10000;
+
+while (i < count) {
+ str += '.';
+ i++;
+}
+
+assert.sameValue('.'.repeat(count), str);
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/repeat.js b/js/src/tests/test262/built-ins/String/prototype/repeat/repeat.js
new file mode 100644
index 0000000000..c6df5c1df3
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/repeat.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.13
+description: >
+ Property type and descriptor.
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 17 ECMAScript Standard Built-in Objects
+includes: [propertyHelper.js]
+---*/
+
+assert.sameValue(
+ typeof String.prototype.repeat,
+ 'function',
+ '`typeof String.prototype.repeat` is `function`'
+);
+
+verifyNotEnumerable(String.prototype, 'repeat');
+verifyWritable(String.prototype, 'repeat');
+verifyConfigurable(String.prototype, 'repeat');
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-count-as-symbol.js b/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-count-as-symbol.js
new file mode 100644
index 0000000000..4f316daa43
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-count-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.13
+description: >
+ Returns abrupt from ToInteger(count) where count is a Symbol
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 4. Let n be ToInteger(count).
+ 5. ReturnIfAbrupt(n).
+features: [Symbol]
+---*/
+
+var s = Symbol('');
+
+assert.throws(TypeError, function() {
+ ''.repeat(s);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-count.js b/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-count.js
new file mode 100644
index 0000000000..a9e8df8091
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-count.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.13
+description: >
+ Returns abrupt from ToInteger(count)
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 4. Let n be ToInteger(count).
+ 5. ReturnIfAbrupt(n).
+---*/
+
+var o = {
+ toString: function() {
+ throw new Test262Error();
+ }
+}
+
+assert.throws(Test262Error, function() {
+ ''.repeat(o);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-this-as-symbol.js b/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-this-as-symbol.js
new file mode 100644
index 0000000000..58daa15d23
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/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.13
+description: >
+ Returns abrupt from ToString(this) where this is a Symbol
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 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.repeat.call(s);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/String/prototype/repeat/return-abrupt-from-this.js
new file mode 100644
index 0000000000..5576d7108c
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/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.13
+description: >
+ Returns abrupt from ToString(this)
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 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.repeat.call(o);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/shell.js b/js/src/tests/test262/built-ins/String/prototype/repeat/shell.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/shell.js
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/this-is-null-throws.js b/js/src/tests/test262/built-ins/String/prototype/repeat/this-is-null-throws.js
new file mode 100644
index 0000000000..a93f0e5592
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/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.13
+description: >
+ Throws TypeError when `this` is null
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 1. Let O be RequireObjectCoercible(this value).
+ 2. Let S be ToString(O).
+---*/
+
+assert.throws(TypeError, function() {
+ String.prototype.repeat.call(null);
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/String/prototype/repeat/this-is-undefined-throws.js b/js/src/tests/test262/built-ins/String/prototype/repeat/this-is-undefined-throws.js
new file mode 100644
index 0000000000..0defa229b2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/String/prototype/repeat/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.13
+description: >
+ Throws TypeError when `this` is undefined
+info: |
+ 21.1.3.13 String.prototype.repeat ( count )
+
+ 1. Let O be RequireObjectCoercible(this value).
+ 2. Let S be ToString(O).
+---*/
+
+assert.throws(TypeError, function() {
+ String.prototype.repeat.call(undefined);
+});
+
+reportCompare(0, 0);