-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabling padStart and padEnd by default on.
Apart from enabling it, I found that spec for padStart/padEnd got changed where , 8. If filler is the empty String, return S. (https://tc39.github.io/ecma262/#sec-string.prototype.padstart) fixed that and updated the test. test262 is fully passed for these two APIs.
- Loading branch information
Showing
6 changed files
with
84 additions
and
97 deletions.
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
@@ -1,75 +1,75 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
|
||
var tests = [ | ||
{ | ||
name: "String.prototype.padStart/padEnd should exist and constructed properly", | ||
body: function () { | ||
assert.isTrue(String.prototype.hasOwnProperty('padStart'), "String.prototype should have a padStart method"); | ||
assert.isTrue(String.prototype.hasOwnProperty('padEnd'), "String.prototype should have a padEnd method"); | ||
assert.areEqual(1, String.prototype.padStart.length, "padStart method takes one argument"); | ||
assert.areEqual(1, String.prototype.padEnd.length, "padEnd method takes one argument"); | ||
assert.areEqual("padStart", String.prototype.padStart.name, "padStart.name is 'padStart'"); | ||
assert.areEqual("padEnd", String.prototype.padEnd.name, "padEnd.name is 'padEnd'"); | ||
|
||
var descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padStart'); | ||
assert.isTrue(descriptor.writable, "writable(padStart) must be true"); | ||
assert.isFalse(descriptor.enumerable, "enumerable(padStart) must be false"); | ||
assert.isTrue(descriptor.configurable, "configurable(padStart) must be true"); | ||
|
||
descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padEnd'); | ||
assert.isTrue(descriptor.writable, "writable(padEnd) must be true"); | ||
assert.isFalse(descriptor.enumerable, "enumerable(padEnd) must be false"); | ||
assert.isTrue(descriptor.configurable, "configurable(padEnd) must be true"); | ||
} | ||
}, | ||
{ | ||
name: "String.prototype.padStart functionality", | ||
body: function () { | ||
assert.areEqual('foo'.padStart(), 'foo', "No arguments to padStart will not affect string"); | ||
assert.areEqual('foo'.padStart(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string"); | ||
assert.areEqual('foo'.padStart(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string"); | ||
assert.areEqual('foo'.padStart(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string"); | ||
assert.areEqual('foo'.padStart(4), ' foo', "String with one ' ' (SPACE) as pad is returned"); | ||
assert.areEqual('foo'.padStart(10), ' foo', "String of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padStart(10, ''), ' foo', "Empty fillString - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padStart(10, undefined), ' foo', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padStart(10, ' '), ' foo', "fillString as one space - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padStart(4, '123'), '1foo', "String of length 4, with only one character from fillString added as a padding, is returned"); | ||
assert.areEqual('foo'.padStart(10, '123'), '1231231foo', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned"); | ||
} | ||
}, | ||
{ | ||
name: "String.prototype.padEnd functionality", | ||
body: function () { | ||
assert.areEqual('foo'.padEnd(), 'foo', "No arguments to padEnd will not affect string"); | ||
assert.areEqual('foo'.padEnd(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string"); | ||
assert.areEqual('foo'.padEnd(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string"); | ||
assert.areEqual('foo'.padEnd(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string"); | ||
assert.areEqual('foo'.padEnd(4), 'foo ', "String with one ' ' (SPACE) as pad is returned"); | ||
assert.areEqual('foo'.padEnd(10), 'foo ', "String of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padEnd(10, ''), 'foo ', "Empty fillString - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padEnd(10, undefined), 'foo ', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padEnd(10, ' '), 'foo ', "fillString as one space - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padEnd(4, '123'), 'foo1', "String of length 4, with only one character from fillString added as a padding, is returned"); | ||
assert.areEqual('foo'.padEnd(10, '123'), 'foo1231231', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned"); | ||
} | ||
}, | ||
{ | ||
name: "String.prototype.padStart OOM scenario", | ||
body: function () { | ||
try { | ||
'foo'.padStart(2147483647); | ||
} | ||
catch(e) { | ||
assert.areEqual(e.message, "Out of memory", "validating out of memory for maxLength >= int_max"); | ||
} | ||
} | ||
} | ||
]; | ||
|
||
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
|
||
var tests = [ | ||
{ | ||
name: "String.prototype.padStart/padEnd should exist and constructed properly", | ||
body: function () { | ||
assert.isTrue(String.prototype.hasOwnProperty('padStart'), "String.prototype should have a padStart method"); | ||
assert.isTrue(String.prototype.hasOwnProperty('padEnd'), "String.prototype should have a padEnd method"); | ||
assert.areEqual(1, String.prototype.padStart.length, "padStart method takes one argument"); | ||
assert.areEqual(1, String.prototype.padEnd.length, "padEnd method takes one argument"); | ||
assert.areEqual("padStart", String.prototype.padStart.name, "padStart.name is 'padStart'"); | ||
assert.areEqual("padEnd", String.prototype.padEnd.name, "padEnd.name is 'padEnd'"); | ||
|
||
var descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padStart'); | ||
assert.isTrue(descriptor.writable, "writable(padStart) must be true"); | ||
assert.isFalse(descriptor.enumerable, "enumerable(padStart) must be false"); | ||
assert.isTrue(descriptor.configurable, "configurable(padStart) must be true"); | ||
|
||
descriptor = Object.getOwnPropertyDescriptor(String.prototype, 'padEnd'); | ||
assert.isTrue(descriptor.writable, "writable(padEnd) must be true"); | ||
assert.isFalse(descriptor.enumerable, "enumerable(padEnd) must be false"); | ||
assert.isTrue(descriptor.configurable, "configurable(padEnd) must be true"); | ||
} | ||
}, | ||
{ | ||
name: "String.prototype.padStart functionality", | ||
body: function () { | ||
assert.areEqual('foo'.padStart(), 'foo', "No arguments to padStart will not affect string"); | ||
assert.areEqual('foo'.padStart(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string"); | ||
assert.areEqual('foo'.padStart(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string"); | ||
assert.areEqual('foo'.padStart(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string"); | ||
assert.areEqual('foo'.padStart(4), ' foo', "String with one ' ' (SPACE) as pad is returned"); | ||
assert.areEqual('foo'.padStart(10), ' foo', "String of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padStart(10, ''), 'foo', "No padding added if the fillString is empty string"); | ||
assert.areEqual('foo'.padStart(10, undefined), ' foo', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padStart(10, ' '), ' foo', "fillString as one space - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padStart(4, '123'), '1foo', "String of length 4, with only one character from fillString added as a padding, is returned"); | ||
assert.areEqual('foo'.padStart(10, '123'), '1231231foo', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned"); | ||
} | ||
}, | ||
{ | ||
name: "String.prototype.padEnd functionality", | ||
body: function () { | ||
assert.areEqual('foo'.padEnd(), 'foo', "No arguments to padEnd will not affect string"); | ||
assert.areEqual('foo'.padEnd(1), 'foo', "No padding added if maxLength (first argument) is less than the length of actual string"); | ||
assert.areEqual('foo'.padEnd(-1), 'foo', "No padding added if maxLength (first argument), negative, is less than the length of actual string"); | ||
assert.areEqual('foo'.padEnd(3), 'foo', "No padding added if maxLength (first argument) is equal to the length of actual string"); | ||
assert.areEqual('foo'.padEnd(4), 'foo ', "String with one ' ' (SPACE) as pad is returned"); | ||
assert.areEqual('foo'.padEnd(10), 'foo ', "String of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padEnd(10, ''), 'foo', "No padding added if the fillString is empty string"); | ||
assert.areEqual('foo'.padEnd(10, undefined), 'foo ', "'undefined' fillString - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padEnd(10, ' '), 'foo ', "fillString as one space - string of length 10, with spaces filled as padding, is returned"); | ||
assert.areEqual('foo'.padEnd(4, '123'), 'foo1', "String of length 4, with only one character from fillString added as a padding, is returned"); | ||
assert.areEqual('foo'.padEnd(10, '123'), 'foo1231231', "String of length 10, with repeatedly adding characters from fillString to create enough padding, is returned"); | ||
} | ||
}, | ||
{ | ||
name: "String.prototype.padStart OOM scenario", | ||
body: function () { | ||
try { | ||
'foo'.padStart(2147483647); | ||
} | ||
catch(e) { | ||
assert.areEqual(e.message, "Out of memory", "validating out of memory for maxLength >= int_max"); | ||
} | ||
} | ||
} | ||
]; | ||
|
||
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); |