Skip to content

Commit

Permalink
Fix few failing tests in Mono runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
joperezr committed Feb 26, 2022
1 parent 8295331 commit 7dc8ca7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1011,20 +1011,20 @@ public void Match_DefaultTimeout_Throws(RegexOptions options)
if ((RegexOptions)int.Parse(optionsString, CultureInfo.InvariantCulture) == RegexOptions.None)
{
Assert.Throws<RegexMatchTimeoutException>(() => new Regex(Pattern).Match(input));
VerifyIsMatchThrows<RegexMatchTimeoutException>(new Regex(Pattern), input, Regex.InfiniteMatchTimeout);
Assert.Throws<RegexMatchTimeoutException>(() => new Regex(Pattern).IsMatch(input));
Assert.Throws<RegexMatchTimeoutException>(() => new Regex(Pattern).Matches(input).Count);
Assert.Throws<RegexMatchTimeoutException>(() => Regex.Match(input, Pattern));
VerifyIsMatchThrows<RegexMatchTimeoutException>(null, input, Regex.InfiniteMatchTimeout, Pattern);
Assert.Throws<RegexMatchTimeoutException>(() => Regex.IsMatch(input, Pattern));
Assert.Throws<RegexMatchTimeoutException>(() => Regex.Matches(input, Pattern).Count);
}
Assert.Throws<RegexMatchTimeoutException>(() => new Regex(Pattern, (RegexOptions)int.Parse(optionsString, CultureInfo.InvariantCulture)).Match(input));
VerifyIsMatchThrows<RegexMatchTimeoutException>(new Regex(Pattern, (RegexOptions)int.Parse(optionsString, CultureInfo.InvariantCulture)), input, Regex.InfiniteMatchTimeout);
Assert.Throws<RegexMatchTimeoutException>(() => new Regex(Pattern, (RegexOptions)int.Parse(optionsString, CultureInfo.InvariantCulture)).IsMatch(input));
Assert.Throws<RegexMatchTimeoutException>(() => new Regex(Pattern, (RegexOptions)int.Parse(optionsString, CultureInfo.InvariantCulture)).Matches(input).Count);
Assert.Throws<RegexMatchTimeoutException>(() => Regex.Match(input, Pattern, (RegexOptions)int.Parse(optionsString, CultureInfo.InvariantCulture)));
VerifyIsMatchThrows<RegexMatchTimeoutException>(null, input, Regex.InfiniteMatchTimeout, Pattern, (RegexOptions)int.Parse(optionsString, CultureInfo.InvariantCulture));
Assert.Throws<RegexMatchTimeoutException>(() => Regex.IsMatch(input, Pattern, (RegexOptions)int.Parse(optionsString, CultureInfo.InvariantCulture)));
Assert.Throws<RegexMatchTimeoutException>(() => Regex.Matches(input, Pattern, (RegexOptions)int.Parse(optionsString, CultureInfo.InvariantCulture)).Count);
}, ((int)options).ToString(CultureInfo.InvariantCulture)).Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ namespace System.Text.RegularExpressions.Tests
public class RegexRunnerTests
{
[Theory]
[InlineData(RegexEngine.Interpreter)]
[InlineData(RegexEngine.Compiled)]
[InlineData(RegexEngine.SourceGenerated)]
[InlineData(RegexEngine.NonBacktracking)]
[MemberData(nameof(RegexHelpers.AvailableEngines_MemberData), MemberType = typeof(RegexHelpers))]
public async Task EnginesThrowNotImplementedForGoAndFFC(RegexEngine engine)
{
Regex re = await RegexHelpers.GetRegexAsync(engine, /*lang=regex*/@"abc");
Expand All @@ -34,10 +31,7 @@ public async Task EnginesThrowNotImplementedForGoAndFFC(RegexEngine engine)
}

[Theory]
[InlineData(RegexEngine.Interpreter)]
[InlineData(RegexEngine.Compiled)]
[InlineData(RegexEngine.SourceGenerated)]
[InlineData(RegexEngine.NonBacktracking)]
[MemberData(nameof(RegexHelpers.AvailableEngines_MemberData), MemberType = typeof(RegexHelpers))]
public async Task EnsureRunmatchValueIsNulledAfterIsMatch(RegexEngine engine)
{
Regex re = await RegexHelpers.GetRegexAsync(engine, /*lang=regex*/@"abc");
Expand All @@ -53,8 +47,8 @@ public async Task EnsureRunmatchValueIsNulledAfterIsMatch(RegexEngine engine)
Assert.NotNull(runmatch);

// Ensure that the Value of runmatch was nulled out, so as to not keep a reference to it in a cache.
PropertyInfo textProperty = typeof(Match).GetProperty("Text", BindingFlags.Instance | BindingFlags.NonPublic);
Assert.Null(textProperty.GetValue(runmatch));
MethodInfo getTextMethod = typeof(Match).GetMethod("get_Text", BindingFlags.Instance | BindingFlags.NonPublic);
Assert.Null(getTextMethod.Invoke(runmatch, new object[] { }));
Assert.Equal(string.Empty, runmatch.Value);
#if NET7_0_OR_GREATER
Assert.True(runmatch.ValueSpan == ReadOnlySpan<char>.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<ItemGroup>
<Compile Include="AttRegexTests.cs" />
<Compile Include="CaptureCollectionTests.cs" />
<Compile Include="CustomDerivedRegexScenarioTest.cs" />
<Compile Include="GroupCollectionTests.cs" />
<Compile Include="MatchCollectionTests.cs" />
<Compile Include="MonoRegexTests.cs" />
Expand All @@ -33,7 +32,6 @@
<Compile Include="RegexMatchTimeoutExceptionTests.cs" />
<Compile Include="RegexParserTests.cs" />
<Compile Include="RegexReductionTests.cs" />
<Compile Include="RegexRunnerTests.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
<Compile Include="..\src\System\Text\RegularExpressions\RegexParseError.cs" Link="System\Text\RegularExpressions\RegexParseError.cs" />
Expand All @@ -43,6 +41,8 @@
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<Compile Include="CustomDerivedRegexScenarioTest.cs" />
<Compile Include="RegexRunnerTests.cs" />
<Compile Include="Regex.Count.Tests.cs" />
<Compile Include="RegexAssert.netcoreapp.cs" />
<Compile Include="RegexParserTests.netcoreapp.cs" />
Expand Down

0 comments on commit 7dc8ca7

Please sign in to comment.