-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String.prototype.{ trimStart, trimEnd, trimLeft, trimRight } tests #1246
Changes from 17 commits
f6fba77
b532507
2250dac
ead4335
e3e97f7
5daafd8
8e5f5ac
a279432
1fbd770
db51688
55a82a9
104f4bf
aeadb9e
6bfbf95
7c1aa35
d852e17
ebef322
ccf5abc
7b0bd99
78549f6
142b14a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimLeft | ||
description: > | ||
String.prototype.trimLeft.length is 0. | ||
info: > | ||
String.prototype.trimLeft ( ) | ||
|
||
17 ECMAScript Standard Built-in Objects: | ||
Every built-in Function object, including constructors, has a length | ||
property whose value is an integer. Unless otherwise specified, this | ||
value is equal to the largest number of named arguments shown in the | ||
subclause headings for the function description, including optional | ||
parameters. However, rest parameters shown using the form “...name” | ||
are not included in the default argument count. | ||
|
||
Unless otherwise specified, the length property of a built-in Function | ||
object has the attributes { [[Writable]]: false, [[Enumerable]]: false, | ||
[[Configurable]]: true }. | ||
includes: [propertyHelper.js] | ||
features: [string-trimming] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.trimLeft, "length", { | ||
value: 0, | ||
enumerable: false, | ||
writable: false, | ||
configurable: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimLeft | ||
description: > | ||
String.prototype.trimLeft.name is "trimLeft". | ||
info: > | ||
String.prototype.trimLeft ( ) | ||
|
||
17 ECMAScript Standard Built-in Objects: | ||
Every built-in Function object, including constructors, that is not | ||
identified as an anonymous function has a name property whose value | ||
is a String. | ||
|
||
Unless otherwise specified, the name property of a built-in Function | ||
object, if it exists, has the attributes { [[Writable]]: false, | ||
[[Enumerable]]: false, [[Configurable]]: true }. | ||
includes: [propertyHelper.js] | ||
features: [string-trimming] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.trimLeft, "name", { | ||
value: "trimLeft", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? According to the proposal’s README the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests in test/built-ins/String/prototype/* are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is irrelevant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the confusing part of how this is speced. The property name is what is defined in annex B, but even in annex B, this is the same function instance as trimStart so it has the same Note that it otherwise gets impossible to pass both these name tests and the same value equality test: https://github.com/tc39/test262/pull/1246/files#diff-c045566571ceee76729db55485a41779 You can't have the same value with two different names. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It took me a second to see what I misunderstood. I'll fix this locally before pushing to master There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Same as the function in thanks for catching this. |
||
enumerable: false, | ||
writable: false, | ||
configurable: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2017 The Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimLeft | ||
description: > | ||
"trimLeft" property of String.prototype | ||
info: > | ||
17 ECMAScript Standard Built-in Objects: | ||
|
||
Every other data property described in clauses 18 through 26 and in Annex B.2 | ||
has the attributes { [[Writable]]: true, [[Enumerable]]: false, | ||
[[Configurable]]: true } unless otherwise specified. | ||
includes: [propertyHelper.js] | ||
features: [string-trimming] | ||
---*/ | ||
|
||
verifyProperty(String.prototype, "trimLeft", { | ||
enumerable: false, | ||
writable: true, | ||
configurable: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (C) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimLeft | ||
description: > | ||
String.prototype.trimLeft is a reference to String.prototype.trimStart. | ||
info: > | ||
String.prototype.trimLeft ( ) | ||
|
||
The function object that is the initial value of String.prototype.trimLeft | ||
is the same function object that is the initial value of | ||
String.prototype.trimStart. | ||
features: [string-trimming] | ||
---*/ | ||
|
||
assert.sameValue(String.prototype.trimLeft, String.prototype.trimStart); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimRight | ||
description: > | ||
String.prototype.trimRight.length is 0. | ||
info: > | ||
String.prototype.trimRight ( ) | ||
|
||
17 ECMAScript Standard Built-in Objects: | ||
Every built-in Function object, including constructors, has a length | ||
property whose value is an integer. Unless otherwise specified, this | ||
value is equal to the largest number of named arguments shown in the | ||
subclause headings for the function description, including optional | ||
parameters. However, rest parameters shown using the form “...name” | ||
are not included in the default argument count. | ||
|
||
Unless otherwise specified, the length property of a built-in Function | ||
object has the attributes { [[Writable]]: false, [[Enumerable]]: false, | ||
[[Configurable]]: true }. | ||
includes: [propertyHelper.js] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
features: [string-trimming] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.trimRight, "length", { | ||
value: 0, | ||
enumerable: false, | ||
writable: false, | ||
configurable: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimRight | ||
description: > | ||
String.prototype.trimRight.name is "trimRight". | ||
info: > | ||
String.prototype.trimRight ( ) | ||
|
||
17 ECMAScript Standard Built-in Objects: | ||
Every built-in Function object, including constructors, that is not | ||
identified as an anonymous function has a name property whose value | ||
is a String. | ||
|
||
Unless otherwise specified, the name property of a built-in Function | ||
object, if it exists, has the attributes { [[Writable]]: false, | ||
[[Enumerable]]: false, [[Configurable]]: true }. | ||
includes: [propertyHelper.js] | ||
features: [string-trimming] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.trimRight, "name", { | ||
value: "trimRight", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is annex B ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I see the oversight now, thanks for your patience :) |
||
enumerable: false, | ||
writable: false, | ||
configurable: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2017 The Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimRight | ||
description: > | ||
"trimRight" property of String.prototype | ||
info: > | ||
17 ECMAScript Standard Built-in Objects: | ||
|
||
Every other data property described in clauses 18 through 26 and in Annex B.2 | ||
has the attributes { [[Writable]]: true, [[Enumerable]]: false, | ||
[[Configurable]]: true } unless otherwise specified. | ||
includes: [propertyHelper.js] | ||
features: [string-trimming] | ||
---*/ | ||
|
||
verifyProperty(String.prototype, "trimRight", { | ||
enumerable: false, | ||
writable: true, | ||
configurable: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (C) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimRight | ||
description: > | ||
String.prototype.trimRight is a reference to String.prototype.trimEnd. | ||
info: > | ||
String.prototype.trimRight ( ) | ||
|
||
The function object that is the initial value of String.prototype.trimRight | ||
is the same function object that is the initial value of | ||
String.prototype.trimEnd. | ||
features: [string-trimming] | ||
---*/ | ||
|
||
assert.sameValue(String.prototype.trimRight, String.prototype.trimEnd); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (C) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimEnd | ||
description: > | ||
String.prototype.trimEnd.length is 0. | ||
info: > | ||
String.prototype.trimEnd ( ) | ||
|
||
17 ECMAScript Standard Built-in Objects: | ||
Every built-in Function object, including constructors, has a length | ||
property whose value is an integer. Unless otherwise specified, this | ||
value is equal to the largest number of named arguments shown in the | ||
subclause headings for the function description, including optional | ||
parameters. However, rest parameters shown using the form “...name” | ||
are not included in the default argument count. | ||
|
||
Unless otherwise specified, the length property of a built-in Function | ||
object has the attributes { [[Writable]]: false, [[Enumerable]]: false, | ||
[[Configurable]]: true }. | ||
includes: [propertyHelper.js] | ||
features: [string-trimming] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.trimEnd, "length", { | ||
value: 0, | ||
enumerable: false, | ||
writable: false, | ||
configurable: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimEnd | ||
description: > | ||
String.prototype.trimEnd.name is "trimEnd". | ||
info: > | ||
String.prototype.trimEnd ( ) | ||
|
||
17 ECMAScript Standard Built-in Objects: | ||
Every built-in Function object, including constructors, that is not | ||
identified as an anonymous function has a name property whose value | ||
is a String. | ||
|
||
Unless otherwise specified, the name property of a built-in Function | ||
object, if it exists, has the attributes { [[Writable]]: false, | ||
[[Enumerable]]: false, [[Configurable]]: true }. | ||
includes: [propertyHelper.js] | ||
features: [string-trimming] | ||
---*/ | ||
|
||
verifyProperty(String.prototype.trimEnd, "name", { | ||
value: "trimEnd", | ||
enumerable: false, | ||
writable: false, | ||
configurable: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2017 The Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimEnd | ||
description: > | ||
"trimEnd" property of String.prototype | ||
info: > | ||
17 ECMAScript Standard Built-in Objects: | ||
|
||
Every other data property described in clauses 18 through 26 and in Annex B.2 | ||
has the attributes { [[Writable]]: true, [[Enumerable]]: false, | ||
[[Configurable]]: true } unless otherwise specified. | ||
includes: [propertyHelper.js] | ||
features: [string-trimming] | ||
---*/ | ||
|
||
verifyProperty(String.prototype, "trimEnd", { | ||
enumerable: false, | ||
writable: true, | ||
configurable: true, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimEnd | ||
description: Behavior when "this" value is a boolean. | ||
info: | | ||
TrimString | ||
2. Let S be ? ToString(str). | ||
|
||
ToString | ||
Argument Type: Boolean | ||
Result: | ||
If argument is true, return "true". | ||
If argument is false, return "false". | ||
features: [string-trimming] | ||
---*/ | ||
|
||
var trimEnd = String.prototype.trimEnd | ||
|
||
assert.sameValue( | ||
trimEnd.call(true), | ||
'true', | ||
'String.prototype.trimEnd.call(true)' | ||
); | ||
|
||
assert.sameValue( | ||
String.prototype.trimEnd.call(false), | ||
'false', | ||
'String.prototype.trimEnd.call(false)' | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimEnd | ||
description: TrimEnd removes all line terminators from the end of a string. | ||
info: | | ||
Runtime Symantics: TrimString ( string, where ) | ||
... | ||
4. Else if where is "end", let T be a String value that is a copy of S with | ||
trailing white space removed. | ||
... | ||
|
||
The definition of white space is the union of WhiteSpace and LineTerminator. | ||
|
||
features: [string-trimming] | ||
---*/ | ||
|
||
var trimEnd = String.prototype.trimEnd; | ||
|
||
// A string of all valid LineTerminator Unicode code points | ||
var lt = '\u000A\u000D\u2028\u2029'; | ||
|
||
var str = lt + 'a' + lt + 'b' + lt; | ||
var expected = lt + 'a' + lt + 'b'; | ||
|
||
assert.sameValue( | ||
trimEnd.call(str), | ||
expected, | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (C) 2017 Valerie Young. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-string.prototype.trimEnd | ||
description: The "this" value must be object-coercible | ||
info: | | ||
1. Let O be ? RequireObjectCoercible(this value). | ||
features: [string-trimming] | ||
---*/ | ||
|
||
var trimEnd = String.prototype.trimEnd; | ||
|
||
assert.sameValue(typeof trimEnd, 'function'); | ||
|
||
assert.throws(TypeError, function() { | ||
trimEnd.call(undefined); | ||
}, 'undefined'); | ||
|
||
assert.throws(TypeError, function() { | ||
trimEnd.call(null); | ||
}, 'null'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
features: [string-trimming]
(and all files in this PR)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add
string-trimming
to FEATURES.txtThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't add it in the master branch yet. This is still a stage 2 feature. This should be added to this same branch.