Skip to content
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

Closed
wants to merge 21 commits into from

Conversation

spectranaut
Copy link
Contributor

No description provided.

@spectranaut spectranaut changed the title Trims WIP Trims initial commit Sep 27, 2017
@rwaldron rwaldron changed the title WIP Trims initial commit [WIP] String.prototype.{ trimLeft, trimRight } tests Sep 27, 2017
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
Copy link
Contributor

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)

Copy link
Contributor

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.txt

Copy link
Member

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.

Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

features: [String.prototype.trimRight] (here and all trimRight test files)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use features: [string-trimming] for consistency

includes: [propertyHelper.js]
---*/

assert.sameValue(String.prototype.trimRight.name, "valueOf");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"valueOf" => "trimRight"

includes: [propertyHelper.js]
---*/

assert.sameValue(String.prototype.trimStart.name, "valueOf");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"valueOf" => "trimStart"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may appear elsewhere, please update as needed


verifyNotEnumerable(String.prototype.trimLeft, "name");
verifyNotWritable(String.prototype.trimLeft, "name");
verifyConfigurable(String.prototype.trimLeft, "name");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use:

verifyProperty(String.prototype.trimLeft, "name", {
  value: "trimLeft",
  enumerable: false,
  writable: false,
  configurable: true,
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use verifyProperty instead of the other functions in the other files as well, we are trying to get rid of the legacy stuff over Test262.

includes: [propertyHelper.js]
---*/

assert.sameValue(String.prototype.trimLeft.name, "valueOf");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"valueOf" => "trimLeft"


verifyNotEnumerable(String.prototype, "trimLeft");
verifyWritable(String.prototype, "trimLeft");
verifyConfigurable(String.prototype, "trimLeft);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a closing quote


verifyNotEnumerable(String.prototype, "trimRight");
verifyWritable(String.prototype, "trimRight");
verifyConfigurable(String.prototype, "trimRight);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing closing quote

---*/

var trimEnd = String.prototype.trimEnd;
var symbol = Symbol()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;

---*/

var trimStart = String.prototype.trimStart;
var symbol = Symbol()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;

// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: pending
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safe to use sec-string.prototype.trimleft for the esid. This applies to the other files too


verifyNotEnumerable(String.prototype.trimLeft, "name");
verifyNotWritable(String.prototype.trimLeft, "name");
verifyConfigurable(String.prototype.trimLeft, "name");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use verifyProperty instead of the other functions in the other files as well, we are trying to get rid of the legacy stuff over Test262.


/*---
esid: pending
description: Behavoir when "this" value is a boolean.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo on Behavior.

missing info and feature tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought "info" wasn't mandatory? Especially because this is a success case, I wasn't sure what text from ecmascript to include..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while it's not mandatory, we are trying to enforce its use with the matching spec text for the unit being tested. It helps a ton while reading the test with a cross reference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime Semantics: TrimString ( string, where )

1. Let str be ? RequireObjectCoercible(string).
2. Let S be ? ToString(str). 
...

ToString ( argument )

- If argument is true, return "true".
- If argument is false, return "false".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later Friday day, after making this comment, I came to the same conclusion as you! Commit here:
4587c81

But I didn't include quite as much information, "TrimString" instead of "Runtime Semantics: TrimString (string, where)". I think I should add the extra information for extra clarity.

assert.sameValue(
trimStart.call(true),
'true',
'String.prototype.trimStart.call(true)'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for adding the assertion messages! It helps identifying them.

@rwaldron rwaldron changed the title [WIP] String.prototype.{ trimLeft, trimRight } tests [WIP] String.prototype.{ trimStart, trimEnd, trimLeft, trimRight } tests Sep 27, 2017
@leobalter leobalter added awaiting stage 2.7 Supports a "Stage 2" feature coverage labels Oct 2, 2017
@leobalter
Copy link
Member

The current set is looking good to me.

We can't merge anything yet as this is still on stage 2.

},
toString: function() {
throw new Test262Error(
'this.toString called before this[Symbol.toPrimitive]'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

...

ToString ( argument )
If arguement is Object:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

/*---
esid: sec-String.prototype.trimStart
description: >
ToString perfers Symbol.toPrimitive to toString to valueOf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: perfers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing:

to toString to valueOf

@@ -0,0 +1,95 @@
// Copyright (C) 2017 the Valerie Young. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you're the Valerie Young, but maybe just your name (no the) is fine here. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahahaha...

Copy link
Contributor

@rwaldron rwaldron Oct 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Valerie Young

Excellent.

trimStart.call(thisVal);
assert.sameValue(called, 1, '[Symbol.toPrimitive] expected to have been called');

var called = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels so much like deserving a separate file. You even redeclare called and thisVal, looks like ready to find a new home in a new file.

};

// Test that valueOf is called when neither [Symbol.toPrimitive] nor toString
// are defined.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space

toString: undefined,
get valueOf() {
called += 1;
return function() { return '' };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you check it gets valueOf once, but not that it calls it.

Also, returning some other string might help to verify the result, e.g.: return ' 42 ';

@leobalter leobalter changed the title [WIP] String.prototype.{ trimStart, trimEnd, trimLeft, trimRight } tests String.prototype.{ trimStart, trimEnd, trimLeft, trimRight } tests Oct 6, 2017
@leobalter
Copy link
Member

In a first round of review for all the commits, there isn't anything I'm missing or that needs a fix.

I'll check the changes locally but it seems great so far.

---*/

verifyProperty(String.prototype.trimLeft, "name", {
value: "trimLeft",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? According to the proposal’s README the name should be trimStart, although I agree the currently proposed spec text doesn’t make that happen. +@sebmarkbage @evilpie @ljharb

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be trimStart. Nice catch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests in test/built-ins/String/prototype/* are trimEnd and trimStart, these are annex B

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is irrelevant.

Choose a reason for hiding this comment

The 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 functionInstance.name field by definition.

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.

Copy link
Contributor

@rwaldron rwaldron Jan 25, 2018

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Same as the function in Array.prototype[Symbol.iterator] is named values, trimLeft.name is "trimStart".

thanks for catching this.

---*/

verifyProperty(String.prototype.trimRight, "name", {
value: "trimRight",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is annex B ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, trimLeft and trimRight are Annex B features, but the tests should still match the specified behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I see the oversight now, thanks for your patience :)

Copy link

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names still need to be updated like @mathiasbynens pointed out.

The "name" property of String.prototype.trimLeft should be "trimStart".

The "name" property of String.prototype.trimRight should be "trimEnd".

@rwaldron
Copy link
Contributor

@sebmarkbage 👍

@rwaldron
Copy link
Contributor

Landed

@rwaldron rwaldron closed this Jan 25, 2018
var trimEnd = String.prototype.trimEnd;

// A string of all valid WhiteSpace Unicode code points
var wspc = '\u0009\u000B\u000C\u0020\u00A0\FEFF\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\FEFF should be \uFEFF.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var trimStart = String.prototype.trimStart;

// A string of all valid WhiteSpace Unicode code points
var wspc = '\u0009\u000B\u000C\u0020\u00A0\FEFF\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\FEFF should be \uFEFF. Also, some whitespace code points are missing. PR incoming.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mathiasbynens added a commit to mathiasbynens/test262 that referenced this pull request Jan 25, 2018
This patch fixes a typo (`\FEFF` → `\uFEFF`) and adds some missing whitespace symbols as a follow-up to tc39#1246.
rwaldron pushed a commit that referenced this pull request Jan 25, 2018
This patch fixes a typo (`\FEFF` → `\uFEFF`) and adds some missing whitespace symbols as a follow-up to #1246.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting stage 2.7 Supports a "Stage 2" feature coverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants