1+ // Copyright (c) Microsoft Corporation.
2+ // Licensed under the MIT License.
3+
4+ using Azure . Sdk . Tools . Cli . Helpers ;
5+
6+ namespace Azure . Sdk . Tools . Cli . Tests . Helpers
7+ {
8+ [ TestFixture ]
9+ public class FileHelperTests
10+ {
11+ [ Test ]
12+ [ TestCase ( "src/test/file.cs" , new [ ] { "**/test/**" } , true ) ]
13+ [ TestCase ( "src/test/subfolder/file.cs" , new [ ] { "**/test/**" } , true ) ]
14+ [ TestCase ( "src/main/file.cs" , new [ ] { "**/test/**" } , false ) ]
15+ [ TestCase ( "file.tmp" , new [ ] { "*.tmp" } , true ) ]
16+ [ TestCase ( "file.cs" , new [ ] { "*.tmp" } , false ) ]
17+ [ TestCase ( "bin/Debug/file.dll" , new [ ] { "bin/**" } , true ) ]
18+ [ TestCase ( "obj/Release/file.obj" , new [ ] { "obj/**" } , true ) ]
19+ [ TestCase ( "src/file.cs" , new [ ] { "bin/**" , "obj/**" } , false ) ]
20+ [ TestCase ( "bin/file.dll" , new [ ] { "bin/**" , "obj/**" } , true ) ]
21+ [ TestCase ( "node_modules/package/file.js" , new [ ] { "**/node_modules/**" } , true ) ]
22+ [ TestCase ( "src/node_modules/file.js" , new [ ] { "**/node_modules/**" } , true ) ]
23+ [ TestCase ( "src/file.js" , new [ ] { "**/node_modules/**" } , false ) ]
24+ [ TestCase ( "Bin/Debug/file.dll" , new [ ] { "bin/**" } , true ) ]
25+ [ TestCase ( "BIN/DEBUG/FILE.DLL" , new [ ] { "bin/**" } , true ) ]
26+ [ TestCase ( "test.tmp" , new [ ] { "*.tmp" , "*.bak" , "**/test/**" } , true ) ]
27+ [ TestCase ( "test.bak" , new [ ] { "*.tmp" , "*.bak" , "**/test/**" } , true ) ]
28+ [ TestCase ( "src/test/file.cs" , new [ ] { "*.tmp" , "*.bak" , "**/test/**" } , true ) ]
29+ [ TestCase ( "src/main/file.cs" , new [ ] { "*.tmp" , "*.bak" , "**/test/**" } , false ) ]
30+ public void IsMatchingExcludePattern_ShouldReturnExpectedResult ( string filePath , string [ ] patterns , bool expected )
31+ {
32+ var result = FileHelper . IsMatchingExcludePattern ( filePath , patterns ) ;
33+
34+ Assert . That ( result , Is . EqualTo ( expected ) ,
35+ $ "Path '{ filePath } ' with patterns [{ string . Join ( ", " , patterns ) } ] should return { expected } but returned { result } ") ;
36+ }
37+
38+ [ Test ]
39+ public void IsMatchingExcludePattern_WithEmptyPatterns_ShouldReturnFalse ( )
40+ {
41+ var filePath = "any/file.cs" ;
42+ var patterns = Array . Empty < string > ( ) ;
43+
44+ var result = FileHelper . IsMatchingExcludePattern ( filePath , patterns ) ;
45+
46+ Assert . That ( result , Is . False ) ;
47+ }
48+
49+ [ Test ]
50+ public void IsMatchingExcludePattern_WithNullPatterns_ShouldReturnFalse ( )
51+ {
52+ var filePath = "any/file.cs" ;
53+ string [ ] ? patterns = null ;
54+
55+ var result = FileHelper . IsMatchingExcludePattern ( filePath , patterns ! ) ;
56+
57+ Assert . That ( result , Is . False ) ;
58+ }
59+
60+ [ Test ]
61+ public void IsMatchingExcludePattern_WithEmptyFilePath_ShouldReturnFalse ( )
62+ {
63+ var filePath = "" ;
64+ var patterns = new [ ] { "*.tmp" } ;
65+
66+ var result = FileHelper . IsMatchingExcludePattern ( filePath , patterns ) ;
67+
68+ Assert . That ( result , Is . False ) ;
69+ }
70+ }
71+ }
0 commit comments