Skip to content

Commit

Permalink
Address PR feedback to normalize version
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Jan 23, 2023
1 parent 3ada698 commit a725e37
Showing 1 changed file with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ public async Task ValidateExpectedOutput(string program, string expected)
{
string actual = await RegexGeneratorHelper.GenerateSourceText(program, allowUnsafe: true, checkOverflow: false);

Console.OutputEncoding = Encoding.UTF8;
AssertExtensions.Equal(Normalize(expected), Normalize(actual));

expected = NormalizeWhiteSpace(expected);
actual = NormalizeWhiteSpace(actual);
AssertExtensions.Equal(expected, actual);

static string NormalizeWhiteSpace(string code)
static string Normalize(string code)
{
string versionString = typeof(Generator.RegexGenerator).Assembly.GetName().Version?.ToString() ?? "";

var input = new StringReader(code);
var output = new StringBuilder();

string line;
while ((line = input.ReadLine()) != null)
{
line = line.Replace("%VERSION%", versionString);

if (string.IsNullOrWhiteSpace(line))
{
line = "";
Expand Down Expand Up @@ -84,7 +84,7 @@ partial class C
/// ○ Match '/'.<br/>
/// </code>
/// </remarks>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "42.42.42.42")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "%VERSION%")]
public static partial global::System.Text.RegularExpressions.Regex Valid() => global::System.Text.RegularExpressions.Generated.Valid_0.Instance;
}

Expand All @@ -101,7 +101,7 @@ namespace System.Text.RegularExpressions.Generated
using System.Threading;

/// <summary>Custom <see cref="Regex"/>-derived type for the Valid method.</summary>
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "42.42.42.42")]
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "%VERSION%")]
[SkipLocalsInit]
file sealed class Valid_0 : Regex
{
Expand Down Expand Up @@ -341,7 +341,7 @@ void UncaptureUntil(int capturePosition)
}

/// <summary>Helper methods used by generated <see cref="Regex"/>-derived implementations.</summary>
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "42.42.42.42")]
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "%VERSION%")]
file static class Utilities
{
/// <summary>Default timeout value set in <see cref="AppContext"/>, or <see cref="Regex.InfiniteMatchTimeout"/> if none was set.</summary>
Expand Down Expand Up @@ -447,7 +447,7 @@ partial class C
/// ○ Match a character in the set [^&gt;\s] atomically at least once.<br/>
/// </code>
/// </remarks>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "42.42.42.42")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "%VERSION%")]
public static partial global::System.Text.RegularExpressions.Regex Valid() => global::System.Text.RegularExpressions.Generated.Valid_0.Instance;
}

Expand All @@ -464,7 +464,7 @@ namespace System.Text.RegularExpressions.Generated
using System.Threading;

/// <summary>Custom <see cref="Regex"/>-derived type for the Valid method.</summary>
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "42.42.42.42")]
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "%VERSION%")]
[SkipLocalsInit]
file sealed class Valid_0 : Regex
{
Expand Down Expand Up @@ -732,7 +732,7 @@ partial class C
/// ○ Match a character in the set [A-Za-z] atomically at least once.<br/>
/// </code>
/// </remarks>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "42.42.42.42")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "%VERSION%")]
public static partial global::System.Text.RegularExpressions.Regex Valid() => global::System.Text.RegularExpressions.Generated.Valid_0.Instance;
}

Expand All @@ -749,7 +749,7 @@ namespace System.Text.RegularExpressions.Generated
using System.Threading;

/// <summary>Custom <see cref="Regex"/>-derived type for the Valid method.</summary>
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "42.42.42.42")]
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "%VERSION%")]
[SkipLocalsInit]
file sealed class Valid_0 : Regex
{
Expand Down Expand Up @@ -855,7 +855,7 @@ private bool TryMatchAtCurrentPosition(ReadOnlySpan<char> inputSpan)
}

/// <summary>Helper methods used by generated <see cref="Regex"/>-derived implementations.</summary>
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "42.42.42.42")]
[GeneratedCodeAttribute("System.Text.RegularExpressions.Generator", "%VERSION%")]
file static class Utilities
{
/// <summary>Default timeout value set in <see cref="AppContext"/>, or <see cref="Regex.InfiniteMatchTimeout"/> if none was set.</summary>
Expand Down

0 comments on commit a725e37

Please sign in to comment.