Skip to content

Commit e8bb072

Browse files
committed
Clean up partial classes in SourceGenRegexAsync test helper
1 parent 3d4ac7d commit e8bb072

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

src/libraries/System.Text.RegularExpressions/tests/RegexGeneratorHelper.netcoreapp.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,29 @@ internal static async Task<Regex[]> SourceGenRegexAsync(
6161

6262
var code = new StringBuilder();
6363
code.AppendLine("using System.Text.RegularExpressions;");
64+
code.AppendLine("public partial class C {");
6465

6566
// Build up the code for all of the regexes
6667
int count = 0;
6768
foreach (var regex in regexes)
6869
{
6970
Assert.True(regex.options is not null || regex.matchTimeout is null);
70-
string attr = $"[RegexGenerator({SymbolDisplay.FormatLiteral(regex.pattern, quote: true)}";
71+
code.Append($" [RegexGenerator({SymbolDisplay.FormatLiteral(regex.pattern, quote: true)}");
7172
if (regex.options is not null)
7273
{
73-
attr += $", {string.Join(" | ", regex.options.ToString().Split(',').Select(o => $"RegexOptions.{o.Trim()}"))}";
74+
code.Append($", {string.Join(" | ", regex.options.ToString().Split(',').Select(o => $"RegexOptions.{o.Trim()}"))}");
7475
if (regex.matchTimeout is not null)
7576
{
76-
attr += string.Create(CultureInfo.InvariantCulture, $", {(int)regex.matchTimeout.Value.TotalMilliseconds}");
77+
code.Append(string.Create(CultureInfo.InvariantCulture, $", {(int)regex.matchTimeout.Value.TotalMilliseconds}"));
7778
}
7879
}
79-
attr += ")]";
80-
81-
// Create the source boilerplate for the pattern
82-
code.AppendLine($@"public partial class C
83-
{{
84-
{attr}
85-
public static partial Regex Get{count}();
86-
}}");
80+
code.AppendLine($")] public static partial Regex Get{count}();");
8781

8882
count++;
8983
}
9084

85+
code.AppendLine("}");
86+
9187
// Use a cached compilation to save a little time. Rather than creating an entirely new workspace
9288
// for each test, just create a single compilation, cache it, and then replace its syntax tree
9389
// on each test.

0 commit comments

Comments
 (0)