@@ -9,21 +9,32 @@ namespace System.IO.Tests
99{
1010 public class Win32MatcherTests
1111 {
12- [ Theory , MemberData ( nameof ( Win32MatchData ) ) , MemberData ( nameof ( EscapedWin32MatchData ) ) ]
12+ [ Theory ,
13+ MemberData ( nameof ( SimpleMatchData ) ) ,
14+ MemberData ( nameof ( EscapedSimpleMatchData ) ) ,
15+ MemberData ( nameof ( Win32MatchData ) ) ,
16+ MemberData ( nameof ( EscapedWin32MatchData ) ) ]
1317 public static void Win32Match ( string expression , string name , bool ignoreCase , bool expected )
1418 {
1519 Assert . Equal ( expected , FileSystemName . MatchesWin32Expression ( expression , name . AsSpan ( ) , ignoreCase ) ) ;
1620 }
1721
18- public static TheoryData < string , string , bool , bool > EscapedWin32MatchData => new TheoryData < string , string , bool , bool >
22+ [ Theory ,
23+ MemberData ( nameof ( SimpleMatchData ) ) ,
24+ MemberData ( nameof ( EscapedSimpleMatchData ) ) ]
25+ public static void SimpleMatch ( string expression , string name , bool ignoreCase , bool expected )
26+ {
27+ Assert . Equal ( expected , FileSystemName . MatchesSimpleExpression ( expression , name . AsSpan ( ) , ignoreCase ) ) ;
28+ }
29+
30+ public static TheoryData < string , string , bool , bool > EscapedSimpleMatchData => new TheoryData < string , string , bool , bool >
1931 {
2032 // Trailing escape matches as it is considered "invisible"
2133 { "\\ " , "\\ " , false , true } ,
2234 { "\\ " , "\\ " , true , true } ,
2335 { "\\ \\ " , "\\ " , false , true } ,
2436 { "\\ \\ " , "\\ " , true , true } ,
2537
26-
2738 { "\\ *" , "a" , false , false } ,
2839 { "\\ *" , "a" , true , false } ,
2940 { "\\ *" , "*" , false , true } ,
@@ -36,14 +47,17 @@ public static void Win32Match(string expression, string name, bool ignoreCase, b
3647 { "*\\ *" , "***A" , true , false } ,
3748 { "*\\ *" , "ABC*A" , false , false } ,
3849 { "*\\ *" , "ABC*A" , true , false } ,
50+ } ;
3951
52+ public static TheoryData < string , string , bool , bool > EscapedWin32MatchData => new TheoryData < string , string , bool , bool >
53+ {
4054 { "\\ \" " , "a" , false , false } ,
4155 { "\\ \" " , "a" , true , false } ,
4256 { "\\ \" " , "\" " , false , true } ,
4357 { "\\ \" " , "\" " , true , true } ,
4458 } ;
4559
46- public static TheoryData < string , string , bool , bool > Win32MatchData => new TheoryData < string , string , bool , bool >
60+ public static TheoryData < string , string , bool , bool > SimpleMatchData => new TheoryData < string , string , bool , bool >
4761 {
4862 { null , "" , false , false } ,
4963 { null , "" , true , false } ,
@@ -58,14 +72,17 @@ public static void Win32Match(string expression, string name, bool ignoreCase, b
5872 { "*foo" , "nofoo" , true , true } ,
5973 { "*foo" , "NoFOO" , true , true } ,
6074 { "*foo" , "noFOO" , false , false } ,
61-
6275 { @"*" , @"foo.txt" , true , true } ,
6376 { @"." , @"foo.txt" , true , false } ,
6477 { @"." , @"footxt" , true , false } ,
6578 { @"*.*" , @"foo.txt" , true , true } ,
6679 { @"*.*" , @"foo." , true , true } ,
6780 { @"*.*" , @".foo" , true , true } ,
6881 { @"*.*" , @"footxt" , true , false } ,
82+ } ;
83+
84+ public static TheoryData < string , string , bool , bool > Win32MatchData => new TheoryData < string , string , bool , bool >
85+ {
6986 { "<\" *" , @"footxt" , true , true } , // DOS equivalent of *.*
7087 { "<\" *" , @"foo.txt" , true , true } , // DOS equivalent of *.*
7188 { "<\" *" , @".foo" , true , true } , // DOS equivalent of *.*
@@ -112,5 +129,19 @@ public static void Win32Match(string expression, string name, bool ignoreCase, b
112129 { @"<." , @"a." , true , true } ,
113130 { @"<." , @"a.b" , true , false } ,
114131 } ;
132+
133+ [ Theory ,
134+ InlineData ( "" , "*" ) ,
135+ InlineData ( "*.*" , "*" ) ,
136+ InlineData ( "*" , "*" ) ,
137+ InlineData ( "." , "." ) ,
138+ InlineData ( "?" , ">" ) ,
139+ InlineData ( "*." , "<" ) ,
140+ InlineData ( "?.?" , ">\" >" ) ,
141+ InlineData ( "foo*." , "foo<" ) ]
142+ public void TranslateExpression ( string expression , string expected )
143+ {
144+ Assert . Equal ( expected , FileSystemName . TranslateWin32Expression ( expression ) ) ;
145+ }
115146 }
116147}
0 commit comments