forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
String#padStart
and String#padEnd
.
- Loading branch information
Showing
18 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
test/built-ins/String/prototype/padEnd/exception-not-object-coercible.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padend | ||
description: String#padEnd should fail if given a null or undefined value | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.throws(TypeError, function () { | ||
String.prototype.padEnd.call(null); | ||
}); | ||
|
||
assert.throws(TypeError, function () { | ||
String.prototype.padEnd.call(undefined); | ||
}); |
12 changes: 12 additions & 0 deletions
12
test/built-ins/String/prototype/padEnd/fill-string-empty.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padend | ||
description: | | ||
String#padEnd should return the string unchanged when | ||
an explicit empty string is provided | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.sameValue('abc'.padEnd(5, ''), 'abc'); |
11 changes: 11 additions & 0 deletions
11
test/built-ins/String/prototype/padEnd/fill-string-omitted.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padend | ||
description: String#padEnd should default to a fillString of " " when omitted | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.sameValue('abc'.padEnd(5), 'abc '); | ||
assert.sameValue('abc'.padEnd(5, undefined), 'abc '); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padend | ||
description: String#padEnd should have length 1 | ||
author: Jordan Harband | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
assert.sameValue(String.prototype.padEnd.length, 1, 'Expected String#padEnd.length to be 1'); | ||
|
||
verifyNotEnumerable(String.prototype.padEnd, 'length'); | ||
verifyNotWritable(String.prototype.padEnd, 'length'); | ||
verifyConfigurable(String.prototype.padEnd, 'length'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padend | ||
description: String#padEnd should have name property with value 'padEnd' | ||
author: Jordan Harband | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
assert.sameValue( | ||
String.prototype.padEnd.name, | ||
'padEnd', | ||
'Expected String#padEnd.name to be "padEnd"' | ||
); | ||
|
||
verifyNotEnumerable(String.prototype.padEnd, 'name'); | ||
verifyNotWritable(String.prototype.padEnd, 'name'); | ||
verifyConfigurable(String.prototype.padEnd, 'name'); |
13 changes: 13 additions & 0 deletions
13
test/built-ins/String/prototype/padEnd/function-property-descriptor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padend | ||
description: String#padEnd should be writable, non-enumerable, and configurable | ||
author: Jordan Harband | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
verifyNotEnumerable(String.prototype, 'padEnd'); | ||
verifyWritable(String.prototype, 'padEnd'); | ||
verifyConfigurable(String.prototype, 'padEnd'); |
19 changes: 19 additions & 0 deletions
19
test/built-ins/String/prototype/padEnd/max-length-not-greater-than-string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padend | ||
description: | | ||
String#padEnd should return the string unchanged when an integer max | ||
length is not greater than the string length | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.sameValue('abc'.padEnd(undefined, 'def'), 'abc'); | ||
assert.sameValue('abc'.padEnd(null, 'def'), 'abc'); | ||
assert.sameValue('abc'.padEnd(NaN, 'def'), 'abc'); | ||
assert.sameValue('abc'.padEnd(-Infinity, 'def'), 'abc'); | ||
assert.sameValue('abc'.padEnd(0, 'def'), 'abc'); | ||
assert.sameValue('abc'.padEnd(-1, 'def'), 'abc'); | ||
assert.sameValue('abc'.padEnd(3, 'def'), 'abc'); | ||
assert.sameValue('abc'.padEnd(3.9999, 'def'), 'abc'); |
14 changes: 14 additions & 0 deletions
14
test/built-ins/String/prototype/padEnd/normal-operation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padend | ||
description: String#padEnd should work in the general case | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.sameValue('abc'.padEnd(7, 'def'), 'abcdefd'); | ||
assert.sameValue('abc'.padEnd(5, '*'), 'abc**'); | ||
|
||
// surrogate pairs | ||
assert.sameValue('abc'.padEnd(6, '\uD83D\uDCA9'), 'abc\uD83D\uDCA9\uD83D'); |
34 changes: 34 additions & 0 deletions
34
test/built-ins/String/prototype/padEnd/observable-operations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padend | ||
description: String#padEnd should perform observable operations in the correct order | ||
author: Jordan Harband | ||
---*/ | ||
|
||
function createPrimitiveObserver(name, string, value) { | ||
return { | ||
toString: function () { | ||
log += '|toString:' + name; | ||
return string; | ||
}, | ||
valueOf: function () { | ||
log += '|valueOf:' + name; | ||
return value; | ||
} | ||
}; | ||
}; | ||
|
||
var log = ""; | ||
var receiver = createPrimitiveObserver('receiver', 'abc'); | ||
|
||
var fillString = createPrimitiveObserver('fillString', 'def'); | ||
|
||
var maxLength = createPrimitiveObserver('maxLength', {}, 11); | ||
|
||
var result = String.prototype.padEnd.call(receiver, fillString, maxLength); | ||
|
||
assert.sameValue(result, 'abcdefdefde'); | ||
|
||
assert.sameValue(log, "|toString:receiver|valueOf:maxLength|toString:fillString", log); |
16 changes: 16 additions & 0 deletions
16
test/built-ins/String/prototype/padStart/exception-not-object-coercible.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padstart | ||
description: String#padStart should fail if given a null or undefined value | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.throws(TypeError, function () { | ||
String.prototype.padStart.call(null); | ||
}); | ||
|
||
assert.throws(TypeError, function () { | ||
String.prototype.padStart.call(undefined); | ||
}); |
12 changes: 12 additions & 0 deletions
12
test/built-ins/String/prototype/padStart/fill-string-empty.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padstart | ||
description: | | ||
String#padStart should return the string unchanged when | ||
an explicit empty string is provided | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.sameValue('abc'.padStart(5, ''), 'abc'); |
11 changes: 11 additions & 0 deletions
11
test/built-ins/String/prototype/padStart/fill-string-omitted.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padstart | ||
description: String#padStart should default to a fillString of " " when omitted | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.sameValue('abc'.padStart(5), ' abc'); | ||
assert.sameValue('abc'.padStart(5, undefined), ' abc'); |
15 changes: 15 additions & 0 deletions
15
test/built-ins/String/prototype/padStart/function-length.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padstart | ||
description: String#padStart should have length 1 | ||
author: Jordan Harband | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
assert.sameValue(String.prototype.padStart.length, 1, 'Expected String#padStart.length to be 1'); | ||
|
||
verifyNotEnumerable(String.prototype.padStart, 'length'); | ||
verifyNotWritable(String.prototype.padStart, 'length'); | ||
verifyConfigurable(String.prototype.padStart, 'length'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padstart | ||
description: String#padStart should have name property with value 'padStart' | ||
author: Jordan Harband | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
assert.sameValue( | ||
String.prototype.padStart.name, | ||
'padStart', | ||
'Expected String#padStart.name to be "padStart"' | ||
); | ||
|
||
verifyNotEnumerable(String.prototype.padStart, 'name'); | ||
verifyNotWritable(String.prototype.padStart, 'name'); | ||
verifyConfigurable(String.prototype.padStart, 'name'); |
13 changes: 13 additions & 0 deletions
13
test/built-ins/String/prototype/padStart/function-property-descriptor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padstart | ||
description: String#padStart should be writable, non-enumerable, and configurable | ||
author: Jordan Harband | ||
includes: [propertyHelper.js] | ||
---*/ | ||
|
||
verifyNotEnumerable(String.prototype, 'padStart'); | ||
verifyWritable(String.prototype, 'padStart'); | ||
verifyConfigurable(String.prototype, 'padStart'); |
19 changes: 19 additions & 0 deletions
19
test/built-ins/String/prototype/padStart/max-length-not-greater-than-string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padstart | ||
description: | | ||
String#padStart should return the string unchanged when an integer max | ||
length is not greater than the string length | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.sameValue('abc'.padStart(undefined, 'def'), 'abc'); | ||
assert.sameValue('abc'.padStart(null, 'def'), 'abc'); | ||
assert.sameValue('abc'.padStart(NaN, 'def'), 'abc'); | ||
assert.sameValue('abc'.padStart(-Infinity, 'def'), 'abc'); | ||
assert.sameValue('abc'.padStart(0, 'def'), 'abc'); | ||
assert.sameValue('abc'.padStart(-1, 'def'), 'abc'); | ||
assert.sameValue('abc'.padStart(3, 'def'), 'abc'); | ||
assert.sameValue('abc'.padStart(3.9999, 'def'), 'abc'); |
14 changes: 14 additions & 0 deletions
14
test/built-ins/String/prototype/padStart/normal-operation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padstart | ||
description: String#padStart should work in the general case | ||
author: Jordan Harband | ||
---*/ | ||
|
||
assert.sameValue('abc'.padStart(7, 'def'), 'defdabc'); | ||
assert.sameValue('abc'.padStart(5, '*'), '**abc'); | ||
|
||
// surrogate pairs | ||
assert.sameValue('abc'.padStart(6, '\uD83D\uDCA9'), '\uD83D\uDCA9\uD83Dabc'); |
34 changes: 34 additions & 0 deletions
34
test/built-ins/String/prototype/padStart/observable-operations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (C) 2016 Jordan Harband. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.padstart | ||
description: String#padStart should perform observable operations in the correct order | ||
author: Jordan Harband | ||
---*/ | ||
|
||
function createPrimitiveObserver(name, string, value) { | ||
return { | ||
toString: function () { | ||
log += '|toString:' + name; | ||
return string; | ||
}, | ||
valueOf: function () { | ||
log += '|valueOf:' + name; | ||
return value; | ||
} | ||
}; | ||
}; | ||
|
||
var log = ""; | ||
var receiver = createPrimitiveObserver('receiver', 'abc'); | ||
|
||
var fillString = createPrimitiveObserver('fillString', 'def'); | ||
|
||
var maxLength = createPrimitiveObserver('maxLength', {}, 11); | ||
|
||
var result = String.prototype.padStart.call(receiver, fillString, maxLength); | ||
|
||
assert.sameValue(result, 'defdefdeabc'); | ||
|
||
assert.sameValue(log, "|toString:receiver|valueOf:maxLength|toString:fillString", log); |