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

Add back regex tests from reverted .* optimization #56070

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,11 @@ public static IEnumerable<object[]> Match_Basic_TestData()
yield return new object[] { "abc", "abc", RegexOptions.None, 0, 3, true, "abc" };
yield return new object[] { "abc", "aBc", RegexOptions.None, 0, 3, false, string.Empty };
yield return new object[] { "abc", "aBc", RegexOptions.IgnoreCase, 0, 3, true, "aBc" };
yield return new object[] { @"abc.*def", "abcghiDEF", RegexOptions.IgnoreCase, 0, 9, true, "abcghiDEF" };

// Using *, +, ?, {}: Actual - "a+\\.?b*\\.?c{2}"
yield return new object[] { @"a+\.?b*\.+c{2}", "ab.cc", RegexOptions.None, 0, 5, true, "ab.cc" };
yield return new object[] { @"[^a]+\.[^z]+", "zzzzz", RegexOptions.None, 0, 5, false, string.Empty };

// RightToLeft
yield return new object[] { @"\s+\d+", "sdf 12sad", RegexOptions.RightToLeft, 0, 9, true, " 12" };
Expand Down Expand Up @@ -381,6 +383,62 @@ public static IEnumerable<object[]> Match_Basic_TestData()
yield return new object[] { "\u05D0(?:\u05D1|\u05D2|\u05D3)", "\u05D0\u05D2", options, 0, 2, true, "\u05D0\u05D2" };
yield return new object[] { "\u05D0(?:\u05D1|\u05D2|\u05D3)", "\u05D0\u05D4", options, 0, 0, false, "" };
}

// .* : Case sensitive
foreach (RegexOptions options in new[] { RegexOptions.None, RegexOptions.Compiled })
{
yield return new object[] { @".*\nfoo", "This shouldn't match", options, 0, 20, false, "" };
yield return new object[] { @"a.*\nfoo", "This shouldn't match", options, 0, 20, false, "" };
yield return new object[] { @".*\nFoo", $"\nFooThis should match", options, 0, 21, true, "\nFoo" };
yield return new object[] { @".*\nfoo", "\nfooThis should match", options, 4, 17, false, "" };

yield return new object[] { @".*\dfoo", "This shouldn't match", options, 0, 20, false, "" };
yield return new object[] { @".*\dFoo", "This1Foo should match", options, 0, 21, true, "This1Foo" };
yield return new object[] { @".*\dFoo", "This1foo should 2Foo match", options, 0, 26, true, "This1foo should 2Foo" };
yield return new object[] { @".*\dFoo", "This1foo shouldn't 2foo match", options, 0, 29, false, "" };
yield return new object[] { @".*\dfoo", "This1foo shouldn't 2foo match", options, 24, 5, false, "" };

yield return new object[] { @".*\dfoo", "1fooThis1foo should 1foo match", options, 4, 9, true, "This1foo" };
yield return new object[] { @".*\dfoo", "This shouldn't match 1foo", options, 0, 20, false, "" };
}

// .* : Case insensitive
foreach (RegexOptions options in new[] { RegexOptions.IgnoreCase, RegexOptions.IgnoreCase | RegexOptions.Compiled })
{
yield return new object[] { @".*\nFoo", "\nfooThis should match", options, 0, 21, true, "\nfoo" };
yield return new object[] { @".*\dFoo", "This1foo should match", options, 0, 21, true, "This1foo" };
yield return new object[] { @".*\dFoo", "This1foo should 2FoO match", options, 0, 26, true, "This1foo should 2FoO" };
yield return new object[] { @".*\dFoo", "This1Foo should 2fOo match", options, 0, 26, true, "This1Foo should 2fOo" };
yield return new object[] { @".*\dfoo", "1fooThis1FOO should 1foo match", options, 4, 9, true, "This1FOO" };
}

// .* : RTL, Case-sensitive
foreach (RegexOptions options in new[] { RegexOptions.None | RegexOptions.RightToLeft, RegexOptions.Compiled | RegexOptions.RightToLeft })
{
yield return new object[] { @".*\nfoo", "This shouldn't match", options, 0, 20, false, "" };
yield return new object[] { @"a.*\nfoo", "This shouldn't match", options, 0, 20, false, "" };
yield return new object[] { @".*\nFoo", $"This should match\nFoo", options, 0, 21, true, "This should match\nFoo" };
Copy link
Member

Choose a reason for hiding this comment

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

Nit Unnecessary $

yield return new object[] { @".*\nfoo", "This should matchfoo\n", options, 4, 13, false, "" };

yield return new object[] { @".*\dfoo", "This shouldn't match", options, 0, 20, false, "" };
yield return new object[] { @".*\dFoo", "This1Foo should match", options, 0, 21, true, "This1Foo" };
yield return new object[] { @".*\dFoo", "This1foo should 2Foo match", options, 0, 26, true, "This1foo should 2Foo" };
yield return new object[] { @".*\dFoo", "This1foo shouldn't 2foo match", options, 0, 29, false, "" };
yield return new object[] { @".*\dfoo", "This1foo shouldn't 2foo match", options, 19, 0, false, "" };

yield return new object[] { @".*\dfoo", "1fooThis2foo should 1foo match", options, 8, 4, true, "2foo" };
yield return new object[] { @".*\dfoo", "This shouldn't match 1foo", options, 0, 20, false, "" };
}

// .* : RTL, case insensitive
foreach (RegexOptions options in new[] { RegexOptions.IgnoreCase | RegexOptions.RightToLeft, RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.RightToLeft })
{
yield return new object[] { @".*\nFoo", "\nfooThis should match", options, 0, 21, true, "\nfoo" };
yield return new object[] { @".*\dFoo", "This1foo should match", options, 0, 21, true, "This1foo" };
yield return new object[] { @".*\dFoo", "This1foo should 2FoO match", options, 0, 26, true, "This1foo should 2FoO" };
yield return new object[] { @".*\dFoo", "This1Foo should 2fOo match", options, 0, 26, true, "This1Foo should 2fOo" };
yield return new object[] { @".*\dfoo", "1fooThis2FOO should 1foo match", options, 8, 4, true, "2FOO" };
}
}

public static IEnumerable<object[]> Match_Basic_TestData_NetCore()
Expand Down Expand Up @@ -617,7 +675,7 @@ public void Match_Timeout_Loop_Throws(string pattern, RegexOptions options)
public void Match_Timeout_Repetition_Throws(RegexOptions options)
{
int repetitionCount = 800_000_000;
var regex = new Regex(@"a\s{" + repetitionCount+ "}", options, TimeSpan.FromSeconds(1));
var regex = new Regex(@"a\s{" + repetitionCount + "}", options, TimeSpan.FromSeconds(1));
string input = @"a" + new string(' ', repetitionCount) + @"b";
Assert.Throws<RegexMatchTimeoutException>(() => regex.Match(input));
}
Expand Down