Skip to content

Tests for RegExp lookbehind#999

Closed
littledan wants to merge 3 commits intotc39:masterfrom
littledan:lookbehind
Closed

Tests for RegExp lookbehind#999
littledan wants to merge 3 commits intotc39:masterfrom
littledan:lookbehind

Conversation

@littledan
Copy link
Copy Markdown
Member

Thanks @hashseed for writing these tests; this patch is a simple port.

This is a convenience function which tries to make tests easier
to read and write.
Tests for the stage 3 proposal at
https://tc39.github.io/proposal-regexp-lookbehind/

Tests ported from V8, written by @hashseed
Copy link
Copy Markdown
Member

@leobalter leobalter left a comment

Choose a reason for hiding this comment

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

I suggested some split on these tests, as with that, we might also structure the files to be all prefixed with lookbehind- including the lookbehind-negative- parts.

Something that would be interesting is finding negative cases where the lookbehind pattern is malformed.

Other part that I'm missing is checking the tests with match only. Adding some simple test, exec and replace would be interesting as well.

Comment thread harness/compareArray.js Outdated

message += 'Expected SameValue(«' + String(actual) + '», «' + String(expected) + '») to be true';

$ERROR(`${message}${message === undefined ? '' : ' '}Expected the arrays [${actual}] to have the same contents as [${expected}]`);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

message is never undefined here.

Also, it seems the message is redundant. Line 26 already cast actual and expected to String values.

My suggestion for this function:

assert.compareArray = function(actual, expected, message = '') {
  assert(
    compareArray(actual, expected),
    `Expected ${String(actual)} and ${String(expected)} to have the same contents. ${message}`
  );
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Gah, I meant to delete those lines in the middle!

Changed as suggested.

assert.compareArray(["def"], "abcdefdef".match(/(?<=^\w+)def/));
assert.compareArray(["def", "def"], "abcdefdef".match(/(?<=^\w+)def/g));

// Word boundary matches.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

splitting these tests in multiple files help identifying the purpose of each one.

Plus, it helps identifying multiple aspects.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Would splitting up the tests help more than the comments in the test file helps? The tests in a particular file are all getting at the same bit of spec text.

assert.compareArray(["abc", "abc"], /(abc\1)/.exec("abc\u1234"));
assert.compareArray(["abc", "abc"], /(abc\1)/i.exec("abc"));
assert.compareArray(["abc", "abc"], /(abc\1)/i.exec("abc\u1234"));
var oob_subject = "abcdefghijklmnabcdefghijklmn".substr(14);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why not use "abcdefghijklmn"?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Many JS implementations use a sort of virtual slice for situations like this, without copying. This test verifies that such implementations don't make the mistake of allowing lookbehind to go beyond the start of the string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the idea is catching very specific behaviors, that's why I insist we should have split files.

At least a comment explaining this, otherwise the substr seems completely unnecessary for the purpose of testing the final value in oob_subject

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@littledan ...

Many JS implementations use a sort of virtual slice for situations like this, without copying. This test verifies that such implementations don't make the mistake of allowing lookbehind to go beyond the start of the string.

With respect, I have a hard time believing that the code you're referring to is actually doing what you claim it's doing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this test originates from V8, this targets V8's sliced strings, which are used for substrings above a length of 13 characters. I wrote this test for exactly the reason @littledan mentioned. That's why the variable name is called oob_subject. The underlying string backing store extends beyond the actual boundary of the sliced string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I only need some sort of description like a comment - it's better in a separate file - otherwise this can be removed in any further maintenance because it's implementation specific and I can't observe the behavior from the specs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, so it's a purely V8 implementation specific issue? If that's the case, and it's not testing anything that's actually observable per spec, then it falls in one of the following:

  1. Doesn't belong here.
  2. Belongs in a special "shame" file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Honestly, this is like saying that test262 should start supporting V8's testing macros.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I agree that that part should be removed.

I don't feel really strongly about this, and I think neither does @littledan. He simply adapted the tests I wrote while implementing lookbehind for V8 because that is more convenient than coming up with ones from scratch. It's not like we are trying to force them into test262.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I disagree that we should have such a high bar for getting test262 tests in, that we shouldn't have tests that target possible bug sources. If it is a test that's correct according to the spec, is it really creating such a big maintenance burden? I bet V8 isn't the only engine to treat strings like this either--this is likely useful for other engines too. Having such strict requirements for tests just discourages contributions and gives us all less test coverage.

@leobalter
Copy link
Copy Markdown
Member

lookBehing is in stage 3, so this PR has blocker other than the review feedback.

@leobalter
Copy link
Copy Markdown
Member

I'll get this fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants