1+ using System . Reflection ;
2+ using System . Text . RegularExpressions ;
3+ using Xunit ;
4+
5+ namespace CryptikLemur . AssetBundleBuilder . Tests ;
6+
7+ public class ExcludePatternTests {
8+ // Use reflection to test private methods
9+ private static bool IsExcluded ( string relativePath , List < string > excludePatterns ) {
10+ var type = typeof ( Program ) ;
11+ var method = type . GetMethod ( "IsExcluded" , BindingFlags . NonPublic | BindingFlags . Static ) ;
12+ return ( bool ) method ! . Invoke ( null , new object [ ] { relativePath , excludePatterns } ) ! ;
13+ }
14+
15+ private static string GlobToRegex ( string glob ) {
16+ var type = typeof ( Program ) ;
17+ var method = type . GetMethod ( "GlobToRegex" , BindingFlags . NonPublic | BindingFlags . Static ) ;
18+ return ( string ) method ! . Invoke ( null , new object [ ] { glob } ) ! ;
19+ }
20+
21+ [ Theory ]
22+ [ InlineData ( "*.tmp" , "file.tmp" , true ) ]
23+ [ InlineData ( "*.tmp" , "file.txt" , false ) ]
24+ [ InlineData ( "*.tmp" , "path/to/file.tmp" , true ) ]
25+ [ InlineData ( "backup/*" , "backup/file.txt" , true ) ]
26+ [ InlineData ( "backup/*" , "other/file.txt" , false ) ]
27+ [ InlineData ( "**/*.log" , "deep/nested/path/error.log" , true ) ]
28+ [ InlineData ( "**/*.log" , "error.log" , true ) ]
29+ [ InlineData ( "temp*" , "temporary.txt" , true ) ]
30+ [ InlineData ( "temp*" , "other.txt" , false ) ]
31+ [ InlineData ( "*.bak" , "file.bak" , true ) ]
32+ [ InlineData ( "*.bak" , "file.backup" , false ) ]
33+ public void IsExcluded_WithVariousPatterns_ShouldMatchCorrectly ( string pattern , string path , bool expected ) {
34+ var patterns = new List < string > { pattern } ;
35+ var result = IsExcluded ( path , patterns ) ;
36+ Assert . Equal ( expected , result ) ;
37+ }
38+
39+ [ Fact ]
40+ public void IsExcluded_WithMultiplePatterns_ShouldMatchAny ( ) {
41+ var patterns = new List < string > { "*.tmp" , "*.bak" , "backup/*" } ;
42+
43+ Assert . True ( IsExcluded ( "file.tmp" , patterns ) ) ;
44+ Assert . True ( IsExcluded ( "file.bak" , patterns ) ) ;
45+ Assert . True ( IsExcluded ( "backup/anything.txt" , patterns ) ) ;
46+ Assert . False ( IsExcluded ( "file.txt" , patterns ) ) ;
47+ }
48+
49+ [ Fact ]
50+ public void IsExcluded_WithNullPatterns_ShouldReturnFalse ( ) {
51+ Assert . False ( IsExcluded ( "any/path.txt" , null ! ) ) ;
52+ }
53+
54+ [ Fact ]
55+ public void IsExcluded_WithEmptyPatterns_ShouldReturnFalse ( ) {
56+ Assert . False ( IsExcluded ( "any/path.txt" , new List < string > ( ) ) ) ;
57+ }
58+
59+ [ Theory ]
60+ [ InlineData ( "*.txt" , @"^(^|.*/)[^/]*\.txt$" ) ]
61+ [ InlineData ( "backup/*" , @"^(^|.*/)backup/[^/]*$" ) ]
62+ [ InlineData ( "**/*.log" , @"^(.*/)?[^/]*\.log$" ) ]
63+ [ InlineData ( "/absolute/*.txt" , @"^/absolute/[^/]*\.txt$" ) ]
64+ [ InlineData ( "dir/" , @"^(^|.*/)dir/.*$" ) ]
65+ public void GlobToRegex_ShouldConvertCorrectly ( string glob , string expectedRegex ) {
66+ var result = GlobToRegex ( glob ) ;
67+ Assert . Equal ( expectedRegex , result ) ;
68+ }
69+
70+ [ Theory ]
71+ [ InlineData ( "file.tmp" , "file.tmp" ) ]
72+ [ InlineData ( @"path\to\file.tmp" , "path/to/file.tmp" ) ]
73+ [ InlineData ( @"C:\Users\test\file.tmp" , "C:/Users/test/file.tmp" ) ]
74+ public void IsExcluded_WithWindowsPaths_ShouldNormalize ( string windowsPath , string normalizedPath ) {
75+ var patterns = new List < string > { "*.tmp" } ;
76+
77+ // Both should match because paths are normalized
78+ var windowsResult = IsExcluded ( windowsPath , patterns ) ;
79+ var normalizedResult = IsExcluded ( normalizedPath , patterns ) ;
80+
81+ Assert . True ( windowsResult ) ;
82+ Assert . True ( normalizedResult ) ;
83+ Assert . Equal ( windowsResult , normalizedResult ) ;
84+ }
85+
86+ [ Fact ]
87+ public void IsExcluded_CaseInsensitive_ShouldMatch ( ) {
88+ var patterns = new List < string > { "*.TMP" } ;
89+
90+ Assert . True ( IsExcluded ( "file.tmp" , patterns ) ) ;
91+ Assert . True ( IsExcluded ( "FILE.TMP" , patterns ) ) ;
92+ Assert . True ( IsExcluded ( "File.Tmp" , patterns ) ) ;
93+ }
94+ }
0 commit comments