@@ -48,6 +48,112 @@ public void MatchWildcard_MatchesSubstrings()
4848 Assert . IsFalse ( filter . MatchesFilter ( "/ProjectB.FunctionalTests" , new PropertyBag ( ) ) ) ;
4949 }
5050
51+ [ TestMethod ]
52+ public void LiteralSegment_IsCaseInsensitive ( )
53+ {
54+ TreeNodeFilter filter = new ( "/MyAssembly/*/MyClass" ) ;
55+ Assert . IsTrue ( filter . MatchesFilter ( "/MyAssembly/MyNamespace/MyClass" , new PropertyBag ( ) ) ) ;
56+ Assert . IsTrue ( filter . MatchesFilter ( "/MYASSEMBLY/MyNamespace/myclass" , new PropertyBag ( ) ) ) ;
57+ Assert . IsFalse ( filter . MatchesFilter ( "/MyAssembly/MyNamespace/MyClass2" , new PropertyBag ( ) ) ) ;
58+ Assert . IsFalse ( filter . MatchesFilter ( "/MyAssembly/MyNamespace/MyKlass" , new PropertyBag ( ) ) ) ;
59+ }
60+
61+ [ TestMethod ]
62+ public void LiteralSegment_WithEscapedCharacters_MatchesExactly ( )
63+ {
64+ TreeNodeFilter filter = new ( "/My.Assembly/Method\\ (1, 2\\ )" ) ;
65+ Assert . IsTrue ( filter . MatchesFilter ( "/My.Assembly/Method(1, 2)" , new PropertyBag ( ) ) ) ;
66+ Assert . IsTrue ( filter . MatchesFilter ( "/my.assembly/method(1, 2)" , new PropertyBag ( ) ) ) ;
67+ Assert . IsFalse ( filter . MatchesFilter ( "/MyXAssembly/Method(1, 2)" , new PropertyBag ( ) ) ) ;
68+ Assert . IsFalse ( filter . MatchesFilter ( "/My.Assembly/Method(1, 3)" , new PropertyBag ( ) ) ) ;
69+ }
70+
71+ [ TestMethod ]
72+ public void LiteralSegment_NonAsciiCaseEquivalence_MatchesLikeRegex ( )
73+ {
74+ // The Kelvin sign (U+212A) is case-insensitively equal to 'K' and 'k' in a regex, but not in an ordinal comparison.
75+ TreeNodeFilter filter = new ( "/Kelvin" ) ;
76+ Assert . IsTrue ( filter . MatchesFilter ( "/\u212A elvin" , new PropertyBag ( ) ) ) ;
77+ Assert . IsFalse ( filter . MatchesFilter ( "/\u212B elvin" , new PropertyBag ( ) ) ) ;
78+
79+ TreeNodeFilter nonAsciiFilter = new ( "/\u00C9 t\u00E9 " ) ;
80+ Assert . IsTrue ( nonAsciiFilter . MatchesFilter ( "/\u00E9 T\u00C9 " , new PropertyBag ( ) ) ) ;
81+ Assert . IsFalse ( nonAsciiFilter . MatchesFilter ( "/Ete" , new PropertyBag ( ) ) ) ;
82+ }
83+
84+ [ TestMethod ]
85+ public void Segment_WithNewLine_MatchesLikeRegex ( )
86+ {
87+ // '$' matches before a final new line, and '.' doesn't match a new line.
88+ Assert . IsTrue ( new TreeNodeFilter ( "/A" ) . MatchesFilter ( "/A\n " , new PropertyBag ( ) ) ) ;
89+ Assert . IsFalse ( new TreeNodeFilter ( "/A" ) . MatchesFilter ( "/A\n B" , new PropertyBag ( ) ) ) ;
90+ Assert . IsTrue ( new TreeNodeFilter ( "/*" ) . MatchesFilter ( "/A\n " , new PropertyBag ( ) ) ) ;
91+ Assert . IsFalse ( new TreeNodeFilter ( "/*" ) . MatchesFilter ( "/A\n B" , new PropertyBag ( ) ) ) ;
92+ }
93+
94+ [ TestMethod ]
95+ public void LiteralSegment_TurkishCulture_MatchesLikeRegex ( )
96+ {
97+ CultureInfo originalCulture = CultureInfo . CurrentCulture ;
98+ try
99+ {
100+ CultureInfo . CurrentCulture = new CultureInfo ( "tr-TR" ) ;
101+ TreeNodeFilter filter = new ( "/file" ) ;
102+ bool regexMatches = new Regex ( "^file$" , RegexOptions . IgnoreCase ) . IsMatch ( "FILE" ) ;
103+
104+ Assert . AreEqual ( regexMatches , filter . MatchesFilter ( "/FILE" , new PropertyBag ( ) ) ) ;
105+ Assert . IsTrue ( filter . MatchesFilter ( "/file" , new PropertyBag ( ) ) ) ;
106+ }
107+ finally
108+ {
109+ CultureInfo . CurrentCulture = originalCulture ;
110+ }
111+ }
112+
113+ [ TestMethod ]
114+ public void LiteralSegment_CultureChangedToTurkishAfterConstruction_MatchesLikeRegex ( )
115+ {
116+ CultureInfo originalCulture = CultureInfo . CurrentCulture ;
117+ try
118+ {
119+ CultureInfo . CurrentCulture = new CultureInfo ( "en-US" ) ;
120+ TreeNodeFilter filter = new ( "/file" ) ;
121+ Regex regex = new ( "^file$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
122+
123+ // On .NET Framework, the regex uses the current culture when matching, so 'I' no longer matches 'i'.
124+ CultureInfo . CurrentCulture = new CultureInfo ( "tr-TR" ) ;
125+
126+ Assert . AreEqual ( regex . IsMatch ( "FILE" ) , filter . MatchesFilter ( "/FILE" , new PropertyBag ( ) ) ) ;
127+ Assert . IsTrue ( filter . MatchesFilter ( "/file" , new PropertyBag ( ) ) ) ;
128+ }
129+ finally
130+ {
131+ CultureInfo . CurrentCulture = originalCulture ;
132+ }
133+ }
134+
135+ [ TestMethod ]
136+ public void WildcardSegment_CultureChangedToTurkishBeforeFirstMatch_MatchesLikeRegex ( )
137+ {
138+ CultureInfo originalCulture = CultureInfo . CurrentCulture ;
139+ try
140+ {
141+ CultureInfo . CurrentCulture = new CultureInfo ( "en-US" ) ;
142+ TreeNodeFilter filter = new ( "/FILE*" ) ;
143+ Regex regex = new ( "^FILE.*$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
144+
145+ // The filter's regex is created on first use, but must still use the culture the filter was created under.
146+ CultureInfo . CurrentCulture = new CultureInfo ( "tr-TR" ) ;
147+
148+ Assert . IsTrue ( regex . IsMatch ( "file1" ) ) ;
149+ Assert . IsTrue ( filter . MatchesFilter ( "/file1" , new PropertyBag ( ) ) ) ;
150+ }
151+ finally
152+ {
153+ CultureInfo . CurrentCulture = originalCulture ;
154+ }
155+ }
156+
51157 [ TestMethod ]
52158 public void EscapeSequences_SupportsWildcard ( )
53159 {
0 commit comments