2 // MonoTests.System.Text.RegularExpressions misc. test cases
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (c) Copyright 2003,2004 Novell, Inc. (http://www.novell.com)
12 using System
.Text
.RegularExpressions
;
14 using NUnit
.Framework
;
16 namespace MonoTests
.System
.Text
.RegularExpressions
19 public class RegexBugs
21 [Test
] // bug xamarin#3866
22 public void BugXamarin3866 ()
24 Assert
.AreEqual (new Regex(@"(?<A>a)+(?<-A>b)+(?(A)(?!))b").Match("aaaaaabbb").ToString (), "aabbb");
28 public void BugXamarin2663 ()
30 var r
= new Regex ("^(S|SW)?$");
31 Assert
.AreEqual (r
.Match ("SW").ToString (), "SW");
35 public void BugXamarin4523 ()
37 Assert
.AreEqual (new Regex("A(?i)b(?-i)C").Match("ABC").ToString (), "ABC");
41 public void BugXamarin7587 ()
43 var pattern
= @"(^)a";
44 var regex
= new Regex(pattern
, RegexOptions
.IgnoreCase
| RegexOptions
.Singleline
);
46 var match
= regex
.Match(" a", 2, 1);
47 Assert
.AreEqual (match
.Success
, true);
48 Assert
.AreEqual (match
.Index
, 2);
52 public void BugXamarin12612 ()
54 const string r_Header
= @"citrd";
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
= @"(//)";
67 const string r_alphaNumericString
= r_alphaNumericChar
+ @"+";
69 const string r_alphaNumericSpaceString
= r_alphaNumericChar
71 + @"(" + r_alphaNumericChar
+ @"|" + r_space
+ @")*"
75 const string r_Identifier
= r_letter
+ r_alphaNumericChar
+ @"*";
77 const string r_scalar
= r_open
//[
78 + r_alphaNumericSpaceString
81 const string r_array
= r_open
//[
87 const string r_data
= @"(" + r_scalar
+ @"|" + r_array
+ @")";
89 // Complex Compositions
90 const string r_uncased_Header
= @"(?i)" + r_Header
+ @"(?-i)";
92 const string r_permissable_Identifier
= r_Identifier
94 + r_non_letter
+ r_uncased_Header
97 const string r_captured_Identifier
= @"(?<Id>" + r_permissable_Identifier
+ @")";
100 const string r_param
= @"("
102 + r_permissable_Identifier
107 const string r_paramList
= r_param
+ @"*";
110 const string r_Encoder_string
= r_begin
113 + r_captured_Identifier
121 Regex Decoder
= new Regex(r_Encoder_string
);
124 Assert
.IsFalse(Decoder
.IsMatch("citrd[bag]CITRD[1]"));
128 public void BugXamarin11616 ()
131 Assert
.AreEqual(Regex
.Match("Test", @"^[\w-[\d]]\w*$").Success
, true);
135 public void SplitGroup ()
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
);
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
);
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
);
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
);
167 public void MathEmptyGroup ()
169 string str
= "Match something from here.";
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");
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");
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");
188 public void Braces ()
190 Regex regVar
= new Regex(@"{\w+}");
191 Match m
= regVar
.Match ("{ }");
192 Assert
.IsFalse (m
.Success
);
196 public void WhiteSpaceGroupped ()
199 string p
= @"[\s\S]"; // =Category.Any
200 Assert
.IsTrue (Regex
.IsMatch (s
, p
));
203 [Test
] // Bug #577346
204 public void CharacterClassParse ()
206 var foo
= new Regex("[\\177-\\377]");
210 public void RangeIgnoreCase()
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");
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");
227 Assert
.IsTrue (Regex
.IsMatch (str
, @"[A-a]+", RegexOptions
.IgnoreCase
), "#C");
230 Assert
.IsTrue (Regex
.IsMatch (str
, @"[A-a]+", RegexOptions
.IgnoreCase
), "#D");
234 public void Escape0 ()
236 Regex r
= new Regex(@"^[\s\0]*$");
237 Assert
.IsTrue (r
.Match(" \0").Success
);
240 [Test
] // bug #432172
241 public void NoBitmap ()
244 new Regex ("([^a-zA-Z_0-9])+", RegexOptions
.Compiled
);
245 Assert
.AreEqual ("--", rx
.Match ("A--B-").Value
);
249 public void MultipleMatches()
251 Regex regex
= new Regex (@"^(?'path'.*(\\|/)|(/|\\))(?'file'.*)$");
252 Match match
= regex
.Match (@"d:\Temp\SomeDir\SomeDir\bla.xml");
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");
266 public void SameNameGroups ()
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
);
274 public void UndefinedGroup ()
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");
289 public void Quantifiers1 ()
291 Regex re
= new Regex ("[\\w\\W]{8,32}");
292 Match m
= re
.Match (new string ('1', 7));
293 Assert
.IsFalse (m
.Success
);
297 public void Quantifiers2 ()
299 Regex re
= new Regex ("[\\w\\W]{8,32}");
300 Match m
= re
.Match (new string ('1', 8));
301 Assert
.IsTrue (m
.Success
);
305 public void Quantifiers3 ()
307 Regex re
= new Regex ("[\\w\\W]{8,32}");
308 Match m
= re
.Match (new string ('1', 16));
309 Assert
.IsTrue (m
.Success
);
313 public void Quantifiers4 ()
315 Regex re
= new Regex ("[\\w\\W]{8,32}");
316 Match m
= re
.Match (new string ('1', 32));
317 Assert
.IsTrue (m
.Success
);
321 public void Quantifiers5 ()
323 Regex re
= new Regex ("[\\w\\W]{8,32}");
324 Match m
= re
.Match (new string ('1', 33));
325 Assert
.IsTrue (m
.Success
);
329 public void CategoryAndNegated () // Was a regression after first attemp to fix 59150.
331 string text
= "<?xml version=\"1.0\"?>";
332 Regex re
= new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
333 text
= re
.Replace (text
, "{blue:<$1}{maroon:$2}{blue:$3>}");
334 Assert
.AreEqual ("{blue:<}{maroon:?xml version=\"1.0\"?}{blue:>}", text
);
338 public void BackSpace ()
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
);
347 public void ReplaceNegOneAndStartat ()
349 string text
= "abcdeeee";
350 Regex re
= new Regex("e+");
351 text
= re
.Replace(text
, "e", -1, 4);
352 Assert
.AreEqual ("abcde", text
);
356 public void SplitInfiniteLoop ()
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");
375 public void CaseAndSearch ()
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
);
382 Match m
= x
.Match (test1
);
383 Assert
.IsTrue (m
.Success
, "#1");
386 Assert
.IsTrue (m
.Success
, "#2");
389 Assert
.IsTrue (m
.Success
, "#3");
393 public void QuantifiersParseError ()
402 public void NameLookupInEmptyMatch ()
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})");
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");
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");
421 public void HangingHyphens ()
423 Assert
.IsTrue (Regex
.IsMatch ("mT1[", @"m[0-9A-Za-z_-]+\["), "#A1");
424 Assert
.IsTrue (Regex
.IsMatch ("mT1[", @"m[-0-9A-Za-z_]+\["), "#A2");
426 Assert
.IsTrue (Regex
.IsMatch ("-a;", @"[--a]{3}"), "#B1");
427 Assert
.IsTrue (Regex
.IsMatch ("-&,", @"[&--]{3}"), "#B2");
429 Assert
.IsTrue (Regex
.IsMatch ("abcz-", @"[a-c-z]{5}"), "#C1");
430 Assert
.IsFalse (Regex
.IsMatch ("defghijklmnopqrstuvwxy", @"[a-c-z]"), "#C2");
432 Assert
.IsTrue (Regex
.IsMatch ("abcxyz-", @"[a-c-x-z]{7}"), "#D1");
433 Assert
.IsFalse (Regex
.IsMatch ("defghijklmnopqrstuvw", @"[a-c-x-z]"), "#D2");
435 Assert
.IsTrue (Regex
.IsMatch (" \tz-", @"[\s-z]{4}"), "#E1");
436 Assert
.IsFalse (Regex
.IsMatch ("abcdefghijklmnopqrstuvwxy", @"[\s-z]"), "#E2");
439 [Test
, ExpectedException (typeof (ArgumentException
))]
440 public void HangingHyphen1 ()
442 Regex
.IsMatch ("foobar", @"[a-\s]");
446 public void Bug313642 ()
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");
459 public void Bug77487 ()
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");
468 public void Bug69269 ()
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");
476 public void Bug76345 ()
479 string s1
= "'asdf'";
480 string s2
= "'as,'df'";
482 m
= new Regex("'.*?'").Match(s1
);
483 Assert
.IsTrue (m
.Success
, "#A1");
484 Assert
.AreEqual (s1
, m
.Value
, "#A2");
486 m
= new Regex("'[^,].*?'").Match(s1
);
487 Assert
.IsTrue (m
.Success
, "#B1");
488 Assert
.AreEqual (s1
, m
.Value
, "#B2");
490 m
= new Regex("'.*?[^,]'").Match(s1
);
491 Assert
.IsTrue (m
.Success
, "#C1");
492 Assert
.AreEqual (s1
, m
.Value
, "#C2");
494 m
= new Regex("'.*?[^,]'").Match(s2
);
495 Assert
.IsTrue (m
.Success
, "#D1");
496 Assert
.AreEqual (s2
, m
.Value
, "#D2");
500 public void Bug78007 ()
502 string test
= "head><html>";
503 string pattern
= @"\Ahead>\<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");
511 Assert
.IsFalse (m
.Success
, "#B");
515 public void Bug439947 ()
518 r
= new Regex ("(?<=^|/)[^/]*\\.cs$", RegexOptions
.None
);
519 Assert
.IsTrue (r
.IsMatch ("z/text2.cs"));
521 r
= new Regex ("(?<=^|/)[^/]*\\.cs$", RegexOptions
.Compiled
);
522 Assert
.IsTrue (r
.IsMatch ("z/text2.cs"));
526 public void bug443841 ()
528 string numberString
= @"[0-9]+";
529 string doubleString
= string.Format (@" *[+-]? *{0}(\.{0})?([eE][+-]?{0})? *",
531 string vector1To3String
= string.Format (@"{0}(,{0}(,{0})?)?",
534 MatchCollection matches
;
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");
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");
551 public void CharClassWithIgnoreCase ()
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
);
560 public void No65535Limit ()
564 Kill65535_1 (131071);
565 Kill65535_1 (131072);
569 Kill65535_2 (131066);
570 Kill65535_2 (131067);
574 public void GroupNumbers ()
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);
584 public void Trials ()
586 foreach (RegexTrial trial
in trials
)
591 public void Bug80554_0 ()
593 bug80554_trials
[0].Execute ();
597 public void Bug80554_1 ()
599 bug80554_trials
[1].Execute ();
603 public void Bug80554_2 ()
605 bug80554_trials
[2].Execute ();
609 public void Bug80554_3 ()
611 bug80554_trials
[3].Execute ();
615 public void Bug432172 ()
617 new Regex ("^(else|elif|except|finally)([^a-zA-Z_0-9]).*", RegexOptions
.Compiled
);
622 public void Bug610587_RepetitionOfPositionAssertion ()
624 Assert
.AreEqual ("888", Regex
.Match("888", "^*8.*").Value
);
627 void Kill65535_1 (int length
)
629 StringBuilder sb
= new StringBuilder ("x");
630 sb
.Append ('a', length
);
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
);
640 void Kill65535_2 (int length
)
642 StringBuilder sb
= new StringBuilder ("xaaaax");
643 sb
.Append ('a', length
);
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
);
653 void GroupNumbers_1 (string s
, int n
)
655 Regex r
= new Regex (s
);
656 int [] grps
= r
.GetGroupNumbers ();
657 Assert
.AreEqual (n
, grps
.Length
, "#1:" + r
);
660 for (int i
= 0; i
< grps
.Length
; ++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
+ ")");
666 // no gaps in group numbering
667 Assert
.AreEqual ((n
* (n
- 1)) / 2, sum
, "#3:" + r
);
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.")
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)")