Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.Text.RegularExpressions / RegexBugs.cs
1 //
2 // MonoTests.System.Text.RegularExpressions misc. test cases
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (c) Copyright 2003,2004 Novell, Inc. (http://www.novell.com)
8 //
9
10 using System;
11 using System.Text;
12 using System.Text.RegularExpressions;
13
14 using NUnit.Framework;
15
16 namespace MonoTests.System.Text.RegularExpressions
17 {
18         [TestFixture]
19         public class RegexBugs
20         {
21                 [Test] // bug xamarin#3866
22                 public void BugXamarin3866 ()
23                 {
24                         Assert.AreEqual (new Regex(@"(?<A>a)+(?<-A>b)+(?(A)(?!))b").Match("aaaaaabbb").ToString (), "aabbb");
25                 }
26
27                 [Test]
28                 public void BugXamarin2663 ()
29                 {
30                         var r = new Regex ("^(S|SW)?$"); 
31                         Assert.AreEqual (r.Match ("SW").ToString (), "SW");
32                 }
33
34                 [Test]
35                 public void BugXamarin4523 ()
36                 {
37                         Assert.AreEqual (new Regex("A(?i)b(?-i)C").Match("ABC").ToString (), "ABC");
38                 }
39
40                 [Test]
41                 public void BugXamarin7587 ()
42                 {
43                         var pattern = @"(^)a";
44                         var regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
45                                                 
46                         var match = regex.Match("  a", 2, 1);
47                         Assert.AreEqual (match.Success, true);
48                         Assert.AreEqual (match.Index, 2);
49                 }
50
51                 [Test]
52                 public void BugXamarin12612 ()
53                 {
54                         const string r_Header = @"citrd";
55
56                         // Terminals
57                         const string r_begin = @"^";
58                         const string r_end = @"$";
59                         const string r_open = @"\[";
60                         const string r_close = @"\]";
61                         const string r_letter = @"[a-zA-Z]";
62                         const string r_non_letter = @"[^a-zA-Z]";
63                         const string r_alphaNumericChar = @"[a-zA-Z0-9_]";
64                         const string r_space = @"(//)";
65
66                         // Simple Composition
67                         const string r_alphaNumericString = r_alphaNumericChar + @"+";
68
69                         const string r_alphaNumericSpaceString = r_alphaNumericChar
70                                 + @"("
71                                 + @"(" + r_alphaNumericChar + @"|" + r_space + @")*"
72                                 + r_alphaNumericChar
73                                 + @")?";
74
75                         const string r_Identifier = r_letter + r_alphaNumericChar + @"*";
76
77                         const string r_scalar = r_open  //[
78                                 + r_alphaNumericSpaceString
79                                 + r_close; //]
80
81                         const string r_array = r_open  //[
82                                 + @"("
83                                 + r_scalar
84                                 + @")+"
85                                 + r_close; //]
86
87                         const string r_data = @"(" + r_scalar + @"|" + r_array + @")";
88
89                         // Complex Compositions
90                         const string r_uncased_Header = @"(?i)" + r_Header + @"(?-i)";
91
92                         const string r_permissable_Identifier = r_Identifier
93                                 + @"(?<!"
94                                 + r_non_letter + r_uncased_Header
95                                 + @")";
96
97                         const string r_captured_Identifier = @"(?<Id>" + r_permissable_Identifier + @")";
98
99
100                         const string r_param = @"("
101                                 + @"(?<p>"
102                                 + r_permissable_Identifier
103                                 + r_data
104                                 + @")"
105                                 + @")";
106
107                         const string r_paramList = r_param + @"*";
108
109
110                         const string r_Encoder_string = r_begin
111                                 + r_uncased_Header
112                                 + r_open //[
113                                 + r_captured_Identifier
114                                 + r_close //]
115                                 + r_paramList
116                                 + r_end;
117
118
119
120
121                         Regex Decoder = new Regex(r_Encoder_string);
122
123          
124                         Assert.IsFalse(Decoder.IsMatch("citrd[bag]CITRD[1]"));
125                 }
126
127                 [Test]
128                 public void BugXamarin11616 ()
129                 {
130                         
131                         Assert.AreEqual(Regex.Match("Test", @"^[\w-[\d]]\w*$").Success, true);
132                 }
133                 
134                 [Test] // bug #51146
135                 public void SplitGroup ()
136                 {
137                         string [] splitResult = new Regex ("-").Split ("a-bcd-e-fg");
138                         string [] expected = new string [] {"a", "bcd", "e", "fg"};
139                         int length = expected.Length;
140                         Assert.AreEqual (length, splitResult.Length, "#1");
141                         for (int i = 0; i < length; i++)
142                                 Assert.AreEqual (expected [i], splitResult [i], "#2:" + i);
143                         
144                         splitResult = new Regex ("(-)").Split ("a-bcd-e-fg");
145                         expected = new string [] {"a", "-", "bcd", "-", "e", "-", "fg"};
146                         length = expected.Length;
147                         Assert.AreEqual (length, splitResult.Length, "#3");
148                         for (int i = 0; i < length; i++)
149                                 Assert.AreEqual (expected [i], splitResult [i], "#4:" + i);
150
151                         splitResult = new Regex ("(-)b(c)").Split ("a-bcd-e-fg");
152                         expected = new string [] {"a", "-", "c", "d-e-fg" };
153                         length = expected.Length;
154                         Assert.AreEqual (length, splitResult.Length, "#5");
155                         for (int i = 0; i < length; i++)
156                                 Assert.AreEqual (expected [i], splitResult [i], "#6:" + i);
157                                 
158                         splitResult = new Regex ("-").Split ("a-bcd-e-fg-");
159                         expected = new string [] {"a", "bcd", "e", "fg", ""};
160                         length = expected.Length;
161                         Assert.AreEqual (length, splitResult.Length, "#7");
162                         for (int i = 0; i < length; i++)
163                                 Assert.AreEqual (expected [i], splitResult [i], "#8:" + i);
164                 }
165
166                 [Test] // bug #42529
167                 public void MathEmptyGroup ()
168                 {
169                         string str = "Match something from here.";
170
171                         Assert.IsFalse (Regex.IsMatch(str, @"(something|dog)$"), "#1");
172                         Assert.IsTrue (Regex.IsMatch (str, @"(|something|dog)$"), "#2");
173                         Assert.IsTrue (Regex.IsMatch (str, @"(something||dog)$"), "#3");
174                         Assert.IsTrue (Regex.IsMatch (str, @"(something|dog|)$"), "#4");
175
176                         Assert.IsTrue (Regex.IsMatch (str, @"(something|dog)*"), "#5");
177                         Assert.IsTrue (Regex.IsMatch (str, @"(|something|dog)*"), "#6");
178                         Assert.IsTrue (Regex.IsMatch (str, @"(something||dog)*"), "#7");
179                         Assert.IsTrue (Regex.IsMatch (str, @"(something|dog|)*"), "#8");
180
181                         Assert.IsTrue (Regex.IsMatch (str, @"(something|dog)*$"), "#9");
182                         Assert.IsTrue (Regex.IsMatch (str, @"(|something|dog)*$"), "#10");
183                         Assert.IsTrue (Regex.IsMatch (str, @"(something||dog)*$"), "#11");
184                         Assert.IsTrue (Regex.IsMatch (str, @"(something|dog|)*$"), "#12");
185                 }
186
187                 [Test] // bug #52924
188                 public void Braces ()
189                 {
190                         Regex regVar = new Regex(@"{\w+}");
191                         Match m = regVar.Match ("{   }");
192                         Assert.IsFalse  (m.Success);
193                 }
194
195                 [Test] // bug #71077
196                 public void WhiteSpaceGroupped ()
197                 {
198                         string s = "\n";
199                         string p = @"[\s\S]";   // =Category.Any
200                         Assert.IsTrue (Regex.IsMatch (s, p));
201                 }
202
203                 [Test] // Bug #577346
204                 public void CharacterClassParse ()
205                 {
206                         var foo = new Regex("[\\177-\\377]");
207                 }
208                 
209                 [Test] // bug #45976
210                 public void RangeIgnoreCase()
211                 {
212                         string str = "AAABBBBAAA" ;
213                         Assert.IsTrue (Regex.IsMatch(str, @"[A-F]+", RegexOptions.IgnoreCase), "#A1");
214                         Assert.IsTrue (Regex.IsMatch (str, @"[a-f]+", RegexOptions.IgnoreCase), "#A2");
215                         Assert.IsTrue (Regex.IsMatch (str, @"[A-Fa-f]+", RegexOptions.IgnoreCase), "#A3");
216                         Assert.IsTrue (Regex.IsMatch (str, @"[AB]+", RegexOptions.IgnoreCase), "#A4");
217                         Assert.IsTrue (Regex.IsMatch (str, @"[A-B]+", RegexOptions.IgnoreCase), "#A5");
218
219                         str = "AaaBBBaAa" ;
220                         Assert.IsTrue (Regex.IsMatch (str, @"[A-F]+", RegexOptions.IgnoreCase), "#B1");
221                         Assert.IsTrue (Regex.IsMatch (str, @"[a-f]+", RegexOptions.IgnoreCase), "#B2");
222                         Assert.IsTrue (Regex.IsMatch (str, @"[A-Fa-f]+", RegexOptions.IgnoreCase), "#B3");
223                         Assert.IsTrue (Regex.IsMatch (str, @"[AB]+", RegexOptions.IgnoreCase), "#B4");
224                         Assert.IsTrue (Regex.IsMatch (str, @"[A-B]+", RegexOptions.IgnoreCase), "#B5");
225
226                         str = "Aaa[";
227                         Assert.IsTrue (Regex.IsMatch (str, @"[A-a]+", RegexOptions.IgnoreCase), "#C");
228
229                         str = "Ae";
230                         Assert.IsTrue (Regex.IsMatch (str, @"[A-a]+", RegexOptions.IgnoreCase), "#D");
231                 }
232
233                 [Test] // bug #54797
234                 public void Escape0 ()
235                 {
236                         Regex r = new Regex(@"^[\s\0]*$");
237                         Assert.IsTrue (r.Match(" \0").Success);
238                 }
239
240                 [Test] // bug #432172
241                 public void NoBitmap ()
242                 {
243                         Regex rx =
244                                 new Regex ("([^a-zA-Z_0-9])+", RegexOptions.Compiled);
245                         Assert.AreEqual ("--", rx.Match ("A--B-").Value);
246                 }
247                 
248                 [Test]
249                 public void MultipleMatches()
250                 {
251                         Regex regex = new Regex (@"^(?'path'.*(\\|/)|(/|\\))(?'file'.*)$");
252                         Match match = regex.Match (@"d:\Temp\SomeDir\SomeDir\bla.xml");
253
254                         Assert.AreEqual (5, match.Groups.Count, "#1");
255                         Assert.AreEqual ("1", regex.GroupNameFromNumber (1), "#2");
256                         Assert.AreEqual ("2", regex.GroupNameFromNumber (2), "#3");
257                         Assert.AreEqual ("path", regex.GroupNameFromNumber (3), "#4");
258                         Assert.AreEqual ("file", regex.GroupNameFromNumber (4), "#5");
259                         Assert.AreEqual ("\\", match.Groups [1].Value, "#6");
260                         Assert.AreEqual (string.Empty, match.Groups [2].Value, "#7");
261                         Assert.AreEqual (@"d:\Temp\SomeDir\SomeDir\", match.Groups [3].Value, "#8");
262                         Assert.AreEqual ("bla.xml", match.Groups [4].Value, "#9");
263                 }
264
265                 [Test] // bug #56000
266                 public void SameNameGroups ()
267                 {
268                         string rex = "link\\s*rel\\s*=\\s*[\"']?alternate[\"']?\\s*";
269                         rex += "type\\s*=\\s*[\"']?text/xml[\"']?\\s*href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^']*)'|(?<1>\\S+))";
270                         new Regex (rex, RegexOptions.IgnoreCase);
271                 }
272
273                 [Test] // bug #52890
274                 public void UndefinedGroup ()
275                 {
276                         Regex regex = new Regex( "[A-Za-z_0-9]" );
277                         Match m = regex.Match( "123456789abc" );
278                         Group g = m.Groups["not_defined"];
279                         Assert.IsNotNull (g, "#1");
280                         Assert.AreEqual (0, g.Index, "#2");
281                         Assert.AreEqual (0, g.Length, "#3");
282                         Assert.AreEqual (string.Empty, g.Value, "#4");
283                         Assert.IsFalse (g.Success, "#5");
284                         Assert.IsNotNull (g.Captures, "#6");
285                         Assert.AreEqual (0, g.Captures.Count, "#7");
286                 }
287
288                 [Test]
289                 public void Quantifiers1 ()
290                 {
291                         Regex re = new Regex ("[\\w\\W]{8,32}");
292                         Match m = re.Match (new string ('1', 7));
293                         Assert.IsFalse (m.Success);
294                 }
295
296                 [Test]
297                 public void Quantifiers2 ()
298                 {
299                         Regex re = new Regex ("[\\w\\W]{8,32}");
300                         Match m = re.Match (new string ('1', 8));
301                         Assert.IsTrue (m.Success);
302                 }
303
304                 [Test]
305                 public void Quantifiers3 ()
306                 {
307                         Regex re = new Regex ("[\\w\\W]{8,32}");
308                         Match m = re.Match (new string ('1', 16));
309                         Assert.IsTrue (m.Success);
310                 }
311
312                 [Test]
313                 public void Quantifiers4 ()
314                 {
315                         Regex re = new Regex ("[\\w\\W]{8,32}");
316                         Match m = re.Match (new string ('1', 32));
317                         Assert.IsTrue (m.Success);
318                 }
319
320                 [Test]
321                 public void Quantifiers5 ()
322                 {
323                         Regex re = new Regex ("[\\w\\W]{8,32}");
324                         Match m = re.Match (new string ('1', 33));
325                         Assert.IsTrue (m.Success);
326                 }
327
328                 [Test]
329                 public void CategoryAndNegated () // Was a regression after first attemp to fix 59150.
330                 {
331                         string text = "<?xml version=\"1.0\"?>";
332                         Regex re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
333                         text = re.Replace (text, "{blue:&lt;$1}{maroon:$2}{blue:$3&gt;}");
334                         Assert.AreEqual ("{blue:&lt;}{maroon:?xml version=\"1.0\"?}{blue:&gt;}", text);
335                 }
336         
337                 [Test]
338                 public void BackSpace ()
339                 {
340                         string text = "Go, \bNo\bGo" ;
341                         Regex re = new Regex(@"\b[\b]");
342                         text = re.Replace(text, " ");
343                         Assert.AreEqual ("Go, \bNo Go", text);
344                 }
345
346                 [Test]
347                 public void ReplaceNegOneAndStartat ()
348                 {
349                         string text = "abcdeeee";
350                         Regex re = new Regex("e+");
351                         text = re.Replace(text, "e", -1, 4);
352                         Assert.AreEqual ("abcde", text);
353                 }
354
355                 [Test] // bug #57274
356                 public void SplitInfiniteLoop ()
357                 {
358                         string ss = "a b c d e";
359                         string [] words = Regex.Split (ss, "[ \t\n\r]*");
360                         Assert.AreEqual (11, words.Length, "#1");
361                         Assert.AreEqual (string.Empty, words [0], "#2");
362                         Assert.AreEqual ("a", words [1], "#3");
363                         Assert.AreEqual (string.Empty, words [2], "#4");
364                         Assert.AreEqual ("b", words [3], "#5");
365                         Assert.AreEqual (string.Empty, words [4], "#6");
366                         Assert.AreEqual ("c", words [5], "#7");
367                         Assert.AreEqual (string.Empty, words [6], "#8");
368                         Assert.AreEqual ("d", words [7], "#9");
369                         Assert.AreEqual (string.Empty, words [8], "#10");
370                         Assert.AreEqual ("e", words [9], "#11");
371                         Assert.AreEqual (string.Empty, words [10], "#12");
372                 }
373
374                 [Test] // bug #69065
375                 public void CaseAndSearch ()
376                 {
377                         string test1 =  @"\f!E   ZWEITBAD :REGLER-PARAMETER 20.10.2004  SEITE   1";
378                         string test2 =  @" REGLER-PARAMETER ";
379                         string test3 =  @"REGLER-PARAMETER ";
380                         Regex x = new Regex ("REGLER-PARAMETER",RegexOptions.IgnoreCase|RegexOptions.Compiled);
381
382                         Match m = x.Match (test1);
383                         Assert.IsTrue (m.Success, "#1");
384
385                         m = x.Match (test2);
386                         Assert.IsTrue (m.Success, "#2");
387
388                         m = x.Match (test3);
389                         Assert.IsTrue (m.Success, "#3");
390                 }
391
392                 [Test] // bug #69193
393                 public void QuantifiersParseError ()
394                 {
395                         new Regex ("{1,a}");
396                         new Regex ("{a,1}");
397                         new Regex ("{a}");
398                         new Regex ("{,a}");
399                 }
400
401                 [Test] // bug #74753
402                 public void NameLookupInEmptyMatch ()
403                 {
404                         Regex regTime = new Regex (
405                                         @"(?<hour>[0-9]{1,2})([\:](?<minute>[0-9]{1,2})){0,1}([\:](?<second>[0-9]{1,2})){0,1}\s*(?<ampm>(?i:(am|pm)){0,1})");
406
407                         Match mTime = regTime.Match("");
408                         Assert.AreEqual ("", mTime.Groups["hour"].Value, "#A1");
409                         Assert.AreEqual ("", mTime.Groups ["minute"].Value, "#A2");
410                         Assert.AreEqual ("", mTime.Groups ["second"].Value, "#A3");
411                         Assert.AreEqual ("", mTime.Groups ["ampm"].Value, "#A4");
412
413                         mTime = regTime.Match("12:00 pm");
414                         Assert.AreEqual ("12", mTime.Groups ["hour"].Value, "#B1");
415                         Assert.AreEqual ("00", mTime.Groups ["minute"].Value, "#B2");
416                         Assert.AreEqual ("", mTime.Groups ["second"].Value, "#B3");
417                         Assert.AreEqual ("pm", mTime.Groups ["ampm"].Value, "#B4");
418                 }
419
420                 [Test] // bug #77626
421                 public void HangingHyphens ()
422                 {
423                         Assert.IsTrue (Regex.IsMatch ("mT1[", @"m[0-9A-Za-z_-]+\["), "#A1");
424                         Assert.IsTrue (Regex.IsMatch ("mT1[", @"m[-0-9A-Za-z_]+\["), "#A2");
425
426                         Assert.IsTrue (Regex.IsMatch ("-a;", @"[--a]{3}"), "#B1");
427                         Assert.IsTrue (Regex.IsMatch ("-&,", @"[&--]{3}"), "#B2");
428
429                         Assert.IsTrue (Regex.IsMatch ("abcz-", @"[a-c-z]{5}"), "#C1");
430                         Assert.IsFalse (Regex.IsMatch ("defghijklmnopqrstuvwxy", @"[a-c-z]"), "#C2");
431
432                         Assert.IsTrue (Regex.IsMatch ("abcxyz-", @"[a-c-x-z]{7}"), "#D1");
433                         Assert.IsFalse (Regex.IsMatch ("defghijklmnopqrstuvw", @"[a-c-x-z]"), "#D2");
434
435                         Assert.IsTrue (Regex.IsMatch (" \tz-", @"[\s-z]{4}"), "#E1");
436                         Assert.IsFalse (Regex.IsMatch ("abcdefghijklmnopqrstuvwxy", @"[\s-z]"), "#E2");
437                 }
438
439                 [Test, ExpectedException (typeof (ArgumentException))]
440                 public void HangingHyphen1 ()
441                 {
442                         Regex.IsMatch ("foobar", @"[a-\s]");
443                 }
444
445                 [Test]
446                 public void Bug313642 ()
447                 {
448                         Regex r = new Regex ("(?<a>c)");
449                         Match m = r.Match ("a");
450                         Assert.AreEqual (1, m.Groups.Count, "#1");
451                         Assert.AreEqual (0, m.Groups [0].Captures.Count, "#2");
452                         Assert.AreEqual (0, m.Groups [0].Index, "#3");
453                         Assert.AreEqual (0, m.Groups [0].Length, "#4");
454                         Assert.IsFalse (m.Groups [0].Success, "#5");
455                         Assert.AreEqual (string.Empty, m.Groups [0].Value, "#6");
456                 }
457
458                 [Test]
459                 public void Bug77487 ()
460                 {
461                         Assert.IsTrue (Regex.IsMatch ("a a", "^(a[^a]*)*a$"), "#1");
462                         Assert.IsTrue (Regex.IsMatch ("a a", "^(a *)*a$"), "#2");
463                         Assert.IsTrue (Regex.IsMatch ("a a", "(a[^a]*)+a"), "#3");
464                         Assert.IsTrue (Regex.IsMatch ("a a", "(a *)+a"), "#4");
465                 }
466
467                 [Test]
468                 public void Bug69269 ()
469                 {
470                         string s = "CREATE aa\faa; CREATE bb\nbb; CREATE cc\rcc; CREATE dd\tdd; CREATE ee\vee;";
471                         Assert.AreEqual (5, Regex.Matches(s, @"CREATE[\s\S]+?;").Count, "#1");
472                         Assert.AreEqual (5, Regex.Matches (s, @"CREATE[ \f\n\r\t\v\S]+?;").Count, "#2");
473                 }
474
475                 [Test]
476                 public void Bug76345 ()
477                 {
478                         Match m;
479                         string s1 = "'asdf'";
480                         string s2 = "'as,'df'";
481
482                         m = new Regex("'.*?'").Match(s1);
483                         Assert.IsTrue (m.Success, "#A1");
484                         Assert.AreEqual (s1, m.Value, "#A2");
485
486                         m = new Regex("'[^,].*?'").Match(s1);
487                         Assert.IsTrue (m.Success, "#B1");
488                         Assert.AreEqual (s1, m.Value, "#B2");
489
490                         m = new Regex("'.*?[^,]'").Match(s1);
491                         Assert.IsTrue (m.Success, "#C1");
492                         Assert.AreEqual (s1, m.Value, "#C2");
493
494                         m = new Regex("'.*?[^,]'").Match(s2);
495                         Assert.IsTrue (m.Success, "#D1");
496                         Assert.AreEqual (s2, m.Value, "#D2");
497                 }
498
499                 [Test]
500                 public void Bug78007 ()
501                 {
502                         string test = "head&gt;<html>";
503                         string pattern = @"\Ahead&gt;\<html\>";
504                         Regex r = new Regex (pattern);
505                         Match m = r.Match (test);
506                         Assert.IsTrue (m.Success, "#A1");
507                         Assert.AreEqual (0, m.Index, "#A2");
508                         Assert.AreEqual (14, m.Length, "#A3");
509
510                         m = m.NextMatch ();
511                         Assert.IsFalse (m.Success, "#B");
512                 }
513
514                 [Test]
515                 public void Bug439947 ()
516                 {
517                         Regex r;
518                         r = new Regex ("(?<=^|/)[^/]*\\.cs$", RegexOptions.None);
519                         Assert.IsTrue (r.IsMatch ("z/text2.cs"));
520
521                         r = new Regex ("(?<=^|/)[^/]*\\.cs$", RegexOptions.Compiled);
522                         Assert.IsTrue (r.IsMatch ("z/text2.cs"));
523                 }
524
525                 [Test]
526                 public void bug443841 ()
527                 {
528                         string numberString = @"[0-9]+";
529                         string doubleString = string.Format (@" *[+-]? *{0}(\.{0})?([eE][+-]?{0})? *",
530                                 numberString);
531                         string vector1To3String = string.Format (@"{0}(,{0}(,{0})?)?",
532                                 doubleString);
533                         Regex r;
534                         MatchCollection matches;
535                         
536                         r = new Regex (string.Format ("^{0}$", vector1To3String));
537                         Assert.IsTrue (r.IsMatch ("1"), "#A1");
538                         matches = r.Matches ("1");
539                         Assert.AreEqual (1, matches.Count, "#A2");
540                         Assert.AreEqual ("1", matches [0].Value, "#A3");
541
542                         r = new Regex (string.Format ("^{0}$", vector1To3String),
543                                 RegexOptions.Compiled);
544                         Assert.IsTrue (r.IsMatch ("1"), "#B1");
545                         matches = r.Matches ("1");
546                         Assert.AreEqual (1, matches.Count, "#B2");
547                         Assert.AreEqual ("1", matches [0].Value, "#B3");
548                 }
549
550                 [Test]
551                 public void CharClassWithIgnoreCase ()
552                 {
553                         string str = "Foobar qux";
554                         Regex re = new Regex (@"[a-z\s]*", RegexOptions.IgnoreCase);
555                         Match m = re.Match (str);
556                         Assert.AreEqual (str, m.Value);
557                 }
558
559                 [Test] // bug #78278
560                 public void No65535Limit ()
561                 {
562                         Kill65535_1 (65535);
563                         Kill65535_1 (65536);
564                         Kill65535_1 (131071);
565                         Kill65535_1 (131072);
566
567                         Kill65535_2 (65530);
568                         Kill65535_2 (65531);
569                         Kill65535_2 (131066);
570                         Kill65535_2 (131067);
571                 }
572
573                 [Test]
574                 public void GroupNumbers ()
575                 {
576                         GroupNumbers_1 ("a", 1);
577                         GroupNumbers_1 ("(a)", 2);
578                         GroupNumbers_1 ("(a)(b)", 3);
579                         GroupNumbers_1 ("(a)|(b)", 3);
580                         GroupNumbers_1 ("((a)(b))(c)", 5);
581                 }
582
583                 [Test]
584                 public void Trials ()
585                 {
586                         foreach (RegexTrial trial in trials)
587                                 trial.Execute ();
588                 }
589
590                 [Test]
591                 public void Bug80554_0 ()
592                 {
593                         bug80554_trials [0].Execute ();
594                 }
595
596                 [Test]
597                 public void Bug80554_1 ()
598                 {
599                         bug80554_trials [1].Execute ();
600                 }
601
602                 [Test]
603                 public void Bug80554_2 ()
604                 {
605                         bug80554_trials [2].Execute ();
606                 }
607
608                 [Test]
609                 public void Bug80554_3 ()
610                 {
611                         bug80554_trials [3].Execute ();
612                 }
613
614                 [Test]
615                 public void Bug432172 ()
616                 {
617                         new Regex ("^(else|elif|except|finally)([^a-zA-Z_0-9]).*", RegexOptions.Compiled);
618                 }
619
620
621                 [Test]
622                 public void Bug610587_RepetitionOfPositionAssertion ()
623                 {
624                         Assert.AreEqual ("888", Regex.Match("888", "^*8.*").Value);
625                 }
626
627                 void Kill65535_1 (int length)
628                 {
629                         StringBuilder sb = new StringBuilder ("x");
630                         sb.Append ('a', length);
631                         sb.Append ('y');
632                         string teststring = sb.ToString ();
633                         Regex regex = new Regex (@"xa*y");
634                         Match m = regex.Match (teststring);
635                         Assert.IsTrue (m.Success, "#1:" + length);
636                         Assert.AreEqual (0, m.Index, "#2:" + length);
637                         Assert.AreEqual (teststring.Length, m.Length, "#3:" + length);
638                 }
639
640                 void Kill65535_2 (int length)
641                 {
642                         StringBuilder sb = new StringBuilder ("xaaaax");
643                         sb.Append ('a', length);
644                         sb.Append ('y');
645                         string teststring = sb.ToString ();
646                         Regex regex = new Regex (@"x.*y");
647                         Match m = regex.Match(teststring);
648                         Assert.IsTrue (m.Success, "#1:" + length);
649                         Assert.AreEqual (0, m.Index, "#2:" + length);
650                         Assert.AreEqual (teststring.Length, m.Length, "#3:" + length);
651                 }
652                 
653                 void GroupNumbers_1 (string s, int n)
654                 {
655                         Regex r = new Regex (s);
656                         int [] grps = r.GetGroupNumbers ();
657                         Assert.AreEqual (n, grps.Length, "#1:" + r);
658
659                         int sum = 0;
660                         for (int i = 0; i < grps.Length; ++i) {
661                                 sum += grps [i];
662                                 // group numbers are unique
663                                 for (int j = 0; j < i; ++j)
664                                         Assert.IsTrue (grps [i] != grps [j], "#2:" + r + " (" + i + "," + j + ")");
665                         }
666                         // no gaps in group numbering
667                         Assert.AreEqual ((n * (n - 1)) / 2, sum, "#3:" + r);
668                 }
669
670
671                 static string bug80554_s = @"(?(static)|(.*))(static)";
672                 static RegexTrial[] bug80554_trials = {
673                         new RegexTrial (bug80554_s, RegexOptions.None, "static", "Pass. Group[0]=(0,6) Group[1]= Group[2]=(0,6)"),
674                         new RegexTrial (bug80554_s, RegexOptions.None, "hydrostatic", "Pass. Group[0]=(0,11) Group[1]=(0,5) Group[2]=(5,6)"),
675                         new RegexTrial (bug80554_s, RegexOptions.None, "statics", "Pass. Group[0]=(0,6) Group[1]= Group[2]=(0,6)"),
676                         new RegexTrial (bug80554_s, RegexOptions.None, "dynamic", "Fail.")
677                 };
678
679                 static RegexTrial[] trials = {
680                         new RegexTrial (@"^[^.\d]*(\d+)(?:\D+(\d+))?", RegexOptions.None, "MD 9.18", "Pass. Group[0]=(0,7) Group[1]=(3,1) Group[2]=(5,2)"),
681             new RegexTrial (@"(.*:|.*)(DirName)", RegexOptions.Compiled, "/home/homedir/DirName", "Pass. Group[0]=(0,21) Group[1]=(0,14) Group[2]=(14,7)")
682             };
683         }
684 }