Skip to content

Commit ca09e4c

Browse files
committed
Fix pattern matching assertions
1 parent 290281c commit ca09e4c

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

Orm/Xtensive.Orm.Tests.Framework/AssertEx.cs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,41 @@ namespace Xtensive.Orm.Tests
1919
/// </summary>
2020
public static class AssertEx
2121
{
22+
private const RegexOptions RegexSearchOptions = RegexOptions.Singleline | RegexOptions.CultureInvariant;
23+
2224
public static void IsPatternMatch(string source, string pattern)
2325
{
2426
pattern = "^"+Regex.Escape(pattern)+"$";
2527
pattern = pattern.Replace(@"\*", @".*");
2628
pattern = pattern.Replace(@"\?", @".");
27-
Regex r = new Regex(pattern, RegexOptions.Singleline | RegexOptions.CultureInvariant);
28-
Assert.That(r.Match(source), Is.True);
29+
var r = new Regex(pattern, RegexSearchOptions);
30+
Assert.That(r.IsMatch(source), Is.True);
2931
}
3032

3133
public static void IsNotPatternMatch(string source, string pattern)
3234
{
3335
pattern = "^"+Regex.Escape(pattern)+"$";
3436
pattern = pattern.Replace(@"\*", @".*");
3537
pattern = pattern.Replace(@"\?", @".");
36-
Regex r = new Regex(pattern, RegexOptions.Singleline | RegexOptions.CultureInvariant);
37-
Assert.That(r.Match(source), Is.False);
38+
var r = new Regex(pattern, RegexSearchOptions);
39+
Assert.That(r.IsMatch(source), Is.False);
3840
}
3941

4042
public static void IsRegexMatch(string source, string regexPattern)
4143
{
42-
Regex r = new Regex(regexPattern, RegexOptions.Singleline | RegexOptions.CultureInvariant);
43-
Assert.That(r.Match(source), Is.True);
44+
var r = new Regex(regexPattern, RegexSearchOptions);
45+
Assert.That(r.IsMatch(source), Is.True);
4446
}
4547

4648
public static void IsNotRegexMatch(string source, string regexPattern)
4749
{
48-
Regex r = new Regex(regexPattern, RegexOptions.Singleline | RegexOptions.CultureInvariant);
49-
Assert.That(r.Match(source), Is.False);
50+
var r = new Regex(regexPattern, RegexSearchOptions);
51+
Assert.That(r.IsMatch(source), Is.False);
5052
}
5153

5254
public static void HasSameElements<T>(IEnumerable<T> expected, IEnumerable<T> actual)
5355
{
54-
if (expected==null)
56+
if (expected is null)
5557
Assert.That(actual, Is.Null);
5658
else {
5759
var expectedSet = new HashSet<T>(expected);
@@ -96,29 +98,14 @@ public static void Throws<TException>([InstantHandle] Action action)
9698
Assert.Fail($"Expected '{typeof(TException).GetShortName()}' was not thrown.");
9799
}
98100

99-
public static void ThrowsNotSupportedException([InstantHandle] Action action)
100-
{
101-
Throws<NotSupportedException>(action);
102-
}
101+
public static void ThrowsNotSupportedException([InstantHandle] Action action) => Throws<NotSupportedException>(action);
103102

104-
public static void ThrowsInvalidOperationException([InstantHandle] Action action)
105-
{
106-
Throws<InvalidOperationException>(action);
107-
}
103+
public static void ThrowsInvalidOperationException([InstantHandle] Action action) => Throws<InvalidOperationException>(action);
108104

109-
public static void ThrowsArgumentException([InstantHandle] Action action)
110-
{
111-
Throws<ArgumentException>(action);
112-
}
105+
public static void ThrowsArgumentException([InstantHandle] Action action) => Throws<ArgumentException>(action);
113106

114-
public static void ThrowsArgumentOutOfRangeException([InstantHandle] Action action)
115-
{
116-
Throws<ArgumentOutOfRangeException>(action);
117-
}
107+
public static void ThrowsArgumentOutOfRangeException([InstantHandle] Action action) => Throws<ArgumentOutOfRangeException>(action);
118108

119-
public static void ThrowsArgumentNullException([InstantHandle] Action action)
120-
{
121-
Throws<ArgumentNullException>(action);
122-
}
109+
public static void ThrowsArgumentNullException([InstantHandle] Action action) => Throws<ArgumentNullException>(action);
123110
}
124111
}

0 commit comments

Comments
 (0)