Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>6003aa6296ad2bebdf8147de94afbea9b5f16264</Sha>
</Dependency>
<Dependency Name="System.Text.RegularExpressions.TestData" Version="7.0.0-beta.21602.1">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>6003aa6296ad2bebdf8147de94afbea9b5f16264</Sha>
</Dependency>
<Dependency Name="System.Windows.Extensions.TestData" Version="7.0.0-beta.21602.1">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>6003aa6296ad2bebdf8147de94afbea9b5f16264</Sha>
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<SystemPrivateRuntimeUnicodeDataVersion>7.0.0-beta.21602.1</SystemPrivateRuntimeUnicodeDataVersion>
<SystemRuntimeTimeZoneDataVersion>7.0.0-beta.21602.1</SystemRuntimeTimeZoneDataVersion>
<SystemSecurityCryptographyX509CertificatesTestDataVersion>7.0.0-beta.21602.1</SystemSecurityCryptographyX509CertificatesTestDataVersion>
<SystemTextRegularExpressionsTestDataVersion>7.0.0-beta.21602.1</SystemTextRegularExpressionsTestDataVersion>
<SystemWindowsExtensionsTestDataVersion>7.0.0-beta.21602.1</SystemWindowsExtensionsTestDataVersion>
<MicrosoftDotNetCilStripSourcesVersion>7.0.0-beta.21602.1</MicrosoftDotNetCilStripSourcesVersion>
<!-- dotnet-optimization dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -1405,5 +1407,66 @@ public void TerminationInNonBacktrackingVsBackTracking(RegexOptions options, int
// NonBacktracking needs way less than 1s
Assert.False(re.Match(input).Success);
}

//
// dotnet/runtime-assets contains a set a regular expressions sourced from
// permissively-licensed packages. Validate Regex behavior with those expressions.
//

[Theory]
[InlineData(RegexEngine.Interpreter)]
[InlineData(RegexEngine.Compiled)]
public async Task PatternsDataSet_ConstructRegexForAll(RegexEngine engine)
{
foreach (DataSetExpression exp in s_patternsDataSet.Value)
{
await RegexHelpers.GetRegexAsync(engine, exp.Pattern, exp.Options);
}
}

private static Lazy<DataSetExpression[]> s_patternsDataSet = new Lazy<DataSetExpression[]>(() =>
{
using Stream json = File.OpenRead("Regex_RealWorldPatterns.json");
return JsonSerializer.Deserialize<DataSetExpression[]>(json, new JsonSerializerOptions() { ReadCommentHandling = JsonCommentHandling.Skip }).Distinct().ToArray();
});

private sealed class DataSetExpression : IEquatable<DataSetExpression>
{
public int Count { get; set; }
public RegexOptions Options { get; set; }
public string Pattern { get; set; }

public bool Equals(DataSetExpression? other) =>
other is not null &&
other.Pattern == Pattern &&
(Options & ~RegexOptions.Compiled) == (other.Options & ~RegexOptions.Compiled); // Compiled doesn't affect semantics, so remove it from equality for our purposes
}

#if NETCOREAPP
[OuterLoop("Takes many seconds")]
[Fact]
public async Task PatternsDataSet_ConstructRegexForAll_NonBacktracking()
{
foreach (DataSetExpression exp in s_patternsDataSet.Value)
{
try
{
await RegexHelpers.GetRegexAsync(RegexEngine.NonBacktracking, exp.Pattern, exp.Options);
}
catch (Exception e) when (e.Message.Contains(nameof(RegexOptions.NonBacktracking))) { }
}
}

[OuterLoop("Takes minutes to generate and compile thousands of expressions")]
[Fact]
public void PatternsDataSet_ConstructRegexForAll_SourceGenerated()
{
Parallel.ForEach(s_patternsDataSet.Value.Chunk(50), chunk =>
{
RegexHelpers.GetRegexesAsync(RegexEngine.SourceGenerated,
chunk.Select(r => (r.Pattern, (RegexOptions?)r.Options, (TimeSpan?)null)).ToArray()).GetAwaiter().GetResult();
});
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<Compile Include="RegexAssert.netfx.cs" />
<Compile Include="RegexParserTests.netfx.cs" />
<Compile Include="RegexGeneratorHelper.netfx.cs" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<Compile Include="RegexAssert.netcoreapp.cs" />
Expand All @@ -57,4 +58,7 @@
<PackageReference Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisVersion)" />
<ProjectReference Include="..\gen\System.Text.RegularExpressions.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="true" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Text.RegularExpressions.TestData" Version="$(SystemTextRegularExpressionsTestDataVersion)" />
</ItemGroup>
</Project>