Merge pull request #366 from bocoup/String.prototype.repeat

Add tests for String.prototype.repeat
This commit is contained in:
Brian Terlson 2015-07-22 17:13:44 -07:00
commit 57b3d1752b
15 changed files with 300 additions and 0 deletions

View File

@ -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: >
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 ""');

View File

@ -0,0 +1,15 @@
// 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);
});

View File

@ -0,0 +1,15 @@
// 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), '');

View File

@ -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.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);
});

View File

@ -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.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)');

View File

@ -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: >
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');

View File

@ -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: >
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');

View File

@ -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.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);

View File

@ -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: >
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');

View File

@ -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.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);
});

View File

@ -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 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);
});

View File

@ -0,0 +1,20 @@
// 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);
});

View File

@ -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.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);
});

View File

@ -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.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);
});

View File

@ -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.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);
});