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

Update regex messages #76269

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static string RemoveMessagesInNonSupportedLanguage(string value)

var diagnosticsElement = XElement.Parse(value);
foreach (var diagnosticElement in diagnosticsElement.Elements("Diagnostic"))
diagnosticElement.Attribute("Message").Remove();
diagnosticElement.Attribute("Message")!.Remove();

return diagnosticsElement.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.CodeAnalysis.EmbeddedLanguages.RegularExpressions;
using Microsoft.CodeAnalysis.EmbeddedLanguages.VirtualChars;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.UnitTests.EmbeddedLanguages.RegularExpressions
Expand Down Expand Up @@ -60,7 +61,7 @@ private void Test(string stringText, string expected, RegexOptions options,
var actual = TreeToText(sourceText, tree)
.Replace("\"", DoubleQuoteEscaping)
.Replace(""", DoubleQuoteEscaping);
Assert.Equal(expected.Replace("\"", DoubleQuoteEscaping), actual);
AssertEx.Equal(expected.Replace("\"", DoubleQuoteEscaping), actual);
}

private void TryParseSubTrees(
Expand Down Expand Up @@ -353,7 +354,7 @@ private static string And(params string[] regexes)
private static string Not(string regex)
=> $"(?({regex})[0-[0]]|.*)";

[Fact]
//[Fact]
public void TestDeepRecursion()
{
var (token, tree, chars) =
Expand All @@ -375,7 +376,7 @@ public void TestDeepRecursion()
Assert.Null(tree);
}

[Fact]
// [Fact]
public void TestNoStackOverflow()
{
for (var i = 1; i < 1200; i++)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void NegativeTest7()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[11..12)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[11..12)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..13)" Text="(?)" />
Expand Down Expand Up @@ -927,7 +927,7 @@ public void NegativeTest29()
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Unrecognized_grouping_construct}" Span="[10..11)" Text="(" />
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[11..12)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[11..12)" Text="?" />
<Diagnostic Message="{FeaturesResources.Not_enough_close_parens}" Span="[12..12)" Text="" />
</Diagnostics>
<Captures>
Expand Down Expand Up @@ -1163,7 +1163,7 @@ public void NegativeTest36()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[10..11)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[10..11)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..16)" Text="?(a|b)" />
Expand Down Expand Up @@ -1204,7 +1204,7 @@ public void NegativeTest37()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[10..11)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[10..11)" Text="?" />
<Diagnostic Message="{FeaturesResources.Not_enough_close_parens}" Span="[15..15)" Text="" />
</Diagnostics>
<Captures>
Expand Down Expand Up @@ -1250,7 +1250,7 @@ public void NegativeTest38()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[10..11)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[10..11)" Text="?" />
<Diagnostic Message="{FeaturesResources.Not_enough_close_parens}" Span="[16..16)" Text="" />
</Diagnostics>
<Captures>
Expand Down Expand Up @@ -1300,7 +1300,7 @@ public void NegativeTest39()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[10..11)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[10..11)" Text="?" />
<Diagnostic Message="{FeaturesResources.Not_enough_close_parens}" Span="[17..17)" Text="" />
</Diagnostics>
<Captures>
Expand Down Expand Up @@ -1354,7 +1354,7 @@ public void NegativeTest40()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[10..11)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[10..11)" Text="?" />
<Diagnostic Message="{FeaturesResources.Not_enough_close_parens}" Span="[18..18)" Text="" />
</Diagnostics>
<Captures>
Expand Down Expand Up @@ -1422,7 +1422,7 @@ public void NegativeTest42()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[10..11)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[10..11)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..14)" Text="?(a)" />
Expand Down Expand Up @@ -1736,7 +1736,7 @@ public void NegativeTest52()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[10..11)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[10..11)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..16)" Text="?(a:b)" />
Expand Down Expand Up @@ -1775,7 +1775,7 @@ public void NegativeTest53()
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Unrecognized_grouping_construct}" Span="[12..13)" Text="(" />
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[13..14)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[13..14)" Text="?" />
<Diagnostic Message="{FeaturesResources.Not_enough_close_parens}" Span="[14..14)" Text="" />
</Diagnostics>
<Captures>
Expand Down Expand Up @@ -2105,7 +2105,7 @@ public void NegativeTest62()
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Unrecognized_grouping_construct}" Span="[10..11)" Text="(" />
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[11..12)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[11..12)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..18)" Text="(?c:cat)" />
Expand Down Expand Up @@ -2143,7 +2143,7 @@ public void NegativeTest63()
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Unrecognized_grouping_construct}" Span="[10..11)" Text="(" />
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[11..12)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[11..12)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..19)" Text="(??e:cat)" />
Expand Down Expand Up @@ -2281,7 +2281,7 @@ public void NegativeTest66()
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Unrecognized_grouping_construct}" Span="[12..13)" Text="(" />
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[13..14)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[13..14)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..17)" Text="(?(?e))" />
Expand Down Expand Up @@ -2322,7 +2322,7 @@ public void NegativeTest67()
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Unrecognized_grouping_construct}" Span="[12..13)" Text="(" />
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[13..14)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[13..14)" Text="?" />
<Diagnostic Message="{FeaturesResources.Not_enough_close_parens}" Span="[16..16)" Text="" />
</Diagnostics>
<Captures>
Expand Down Expand Up @@ -2358,7 +2358,7 @@ public void NegativeTest68()
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Unrecognized_grouping_construct}" Span="[10..11)" Text="(" />
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[11..12)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[11..12)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..18)" Text="(?r:cat)" />
Expand Down Expand Up @@ -2447,7 +2447,7 @@ public void NegativeTest71()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Insufficient_hexadecimal_digits}" Span="[10..13)" Text="\x2" />
<Diagnostic Message="{FeaturesResources.Insufficient_or_invalid_hexadecimal_digits}" Span="[10..13)" Text="\x2" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..13)" Text="\x2" />
Expand Down Expand Up @@ -2544,7 +2544,7 @@ public void NegativeTest73()
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Unrecognized_grouping_construct}" Span="[15..16)" Text="(" />
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[16..17)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[16..17)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..28)" Text="cat(?(?afdcat)dog)" />
Expand Down Expand Up @@ -2689,7 +2689,7 @@ public void NegativeTest76()
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Alternation_conditions_cannot_be_comments}" Span="[13..14)" Text="(" />
<Diagnostic Message="{FeaturesResources.Unrecognized_grouping_construct}" Span="[15..16)" Text="(" />
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[16..17)" Text="?" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '?')}" Span="[16..17)" Text="?" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..30)" Text="cat(?(?#COMMENT)cat)" />
Expand Down Expand Up @@ -4779,7 +4779,7 @@ public void NegativeTest117()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Insufficient_hexadecimal_digits}" Span="[10..12)" Text="\u" />
<Diagnostic Message="{FeaturesResources.Insufficient_or_invalid_hexadecimal_digits}" Span="[10..12)" Text="\u" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..12)" Text="\u" />
Expand All @@ -4806,7 +4806,7 @@ public void NegativeTest118()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Insufficient_hexadecimal_digits}" Span="[10..13)" Text="\ua" />
<Diagnostic Message="{FeaturesResources.Insufficient_or_invalid_hexadecimal_digits}" Span="[10..13)" Text="\ua" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..13)" Text="\ua" />
Expand All @@ -4833,7 +4833,7 @@ public void NegativeTest119()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Insufficient_hexadecimal_digits}" Span="[10..13)" Text="\u0" />
<Diagnostic Message="{FeaturesResources.Insufficient_or_invalid_hexadecimal_digits}" Span="[10..13)" Text="\u0" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..13)" Text="\u0" />
Expand All @@ -4860,7 +4860,7 @@ public void NegativeTest120()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Insufficient_hexadecimal_digits}" Span="[10..12)" Text="\x" />
<Diagnostic Message="{FeaturesResources.Insufficient_or_invalid_hexadecimal_digits}" Span="[10..12)" Text="\x" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..12)" Text="\x" />
Expand Down Expand Up @@ -5324,7 +5324,7 @@ public void NegativeTest129()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Capture_group_numbers_must_be_less_than_or_equal_to_Int32_MaxValue}" Span="[21..31)" Text="2147483648" />
<Diagnostic Message="{FeaturesResources.Quantifier_and_capture_group_numbers_must_be_less_than_or_equal_to_Int32_MaxValue}" Span="[21..31)" Text="2147483648" />
</Diagnostics>
<Captures>
<Capture Name="-2147483648" Span="[18..36)" Text="(?&lt;2147483648&gt;dog)" />
Expand Down Expand Up @@ -5377,7 +5377,7 @@ public void NegativeTest130()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Capture_group_numbers_must_be_less_than_or_equal_to_Int32_MaxValue}" Span="[21..35)" Text="21474836481097" />
<Diagnostic Message="{FeaturesResources.Quantifier_and_capture_group_numbers_must_be_less_than_or_equal_to_Int32_MaxValue}" Span="[21..35)" Text="21474836481097" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..40)" Text="(cat)\s+(?&lt;21474836481097&gt;dog)" />
Expand Down Expand Up @@ -5721,7 +5721,7 @@ public void NegativeTest136()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message="{FeaturesResources.Quantifier_x_y_following_nothing}" Span="[20..21)" Text="*" />
<Diagnostic Message="{string.Format(FeaturesResources.Quantifier_0_following_nothing, '*')}" Span="[20..21)" Text="*" />
</Diagnostics>
<Captures>
<Capture Name="0" Span="[10..27)" Text="(cat)(\c\|*)(dog)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void TestRealWorldCases(string pattern, int options)
public static IEnumerable<object[]> GetRealWorldCases()
{
using var stream = typeof(CSharpRegexParserTests).Assembly.GetManifestResourceStream("Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.EmbeddedLanguages.RegularExpressions.Regex_RealWorldPatterns.json");
using var streamReader = new StreamReader(stream);
using var streamReader = new StreamReader(stream!);
using var textReader = new JsonTextReader(streamReader);

foreach (var obj in JArray.Load(textReader))
Expand Down
Loading
Loading