// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
-// (c) 2003 Novell, Inc. (http://www.novell.com)
+// (c) Copyright 2003,2004 Novell, Inc. (http://www.novell.com)
//
using NUnit.Framework;
using System;
+using System.Text;
using System.Text.RegularExpressions;
namespace MonoTests.System.Text.RegularExpressions
AssertEquals ("BR #01", false, m.Success);
}
+ [Test]
+ public void WhiteSpaceGroupped () // bug 71077
+ {
+ string s = "\n";
+ string p = @"[\s\S]"; // =Category.Any
+
+ AssertEquals ("WSG#1", true, Regex.IsMatch (s, p));
+ }
+
[Test]
public void RangeIgnoreCase() // bug 45976
{
AssertEquals ("MM #06", "\\", match.Groups[1].Value);
AssertEquals ("MM #07", "", match.Groups[2].Value);
- AssertEquals ("MM #08", @"d:\Temp\SomeDir\SomeDir\", match.Groups[3].Value);
+ AssertEquals ("MM #08", @"d:\Temp\SomeDir\SomeDir\", // fool emacs: "
+ match.Groups[3].Value);
AssertEquals ("MM #09", "bla.xml", match.Groups[4].Value);
}
+
+ [Test]
+ public void SameNameGroups () // First problem in fixing bug #56000
+ {
+ string rex = "link\\s*rel\\s*=\\s*[\"']?alternate[\"']?\\s*";
+ rex += "type\\s*=\\s*[\"']?text/xml[\"']?\\s*href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^']*)'|(?<1>\\S+))";
+ Regex rob = new Regex (rex, RegexOptions.IgnoreCase);
+ }
+
+ [Test]
+ public void UndefinedGroup () // bug 52890
+ {
+ Regex regex = new Regex( "[A-Za-z_0-9]" );
+ Match m = regex.Match( "123456789abc" );
+ Group g = m.Groups["not_defined"];
+ AssertNotNull ("#0", g);
+ AssertEquals ("#1", 0, g.Index);
+ AssertEquals ("#2", 0, g.Length);
+ AssertEquals ("#3", "", g.Value);
+ Assert ("#4", !g.Success);
+ AssertNotNull ("#5", g.Captures);
+ AssertEquals ("#6", 0, g.Captures.Count);
+ }
+
+ [Test]
+ public void Quantifiers1 ()
+ {
+ Regex re = new Regex ("[\\w\\W]{8,32}");
+ Match m = re.Match (new string ('1', 7));
+ AssertEquals ("#01", false, m.Success);
+ }
+
+ [Test]
+ public void Quantifiers2 ()
+ {
+ Regex re = new Regex ("[\\w\\W]{8,32}");
+ Match m = re.Match (new string ('1', 8));
+ AssertEquals ("#01", true, m.Success);
+ }
+
+ [Test]
+ public void Quantifiers3 ()
+ {
+ Regex re = new Regex ("[\\w\\W]{8,32}");
+ Match m = re.Match (new string ('1', 16));
+ AssertEquals ("#01", true, m.Success);
+ }
+
+ [Test]
+ public void Quantifiers4 ()
+ {
+ Regex re = new Regex ("[\\w\\W]{8,32}");
+ Match m = re.Match (new string ('1', 32));
+ AssertEquals ("#01", true, m.Success);
+ }
+
+ [Test]
+ public void Quantifiers5 ()
+ {
+ Regex re = new Regex ("[\\w\\W]{8,32}");
+ Match m = re.Match (new string ('1', 33));
+ AssertEquals ("#01", true, m.Success);
+ }
+
+ [Test]
+ public void CategoryAndNegated () // Was a regression after first attemp to fix 59150.
+ {
+ string text = "<?xml version=\"1.0\"?>";
+ Regex re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
+ text = re.Replace (text, "{blue:<$1}{maroon:$2}{blue:$3>}");
+ AssertEquals ("#01", "{blue:<}{maroon:?xml version=\"1.0\"?}{blue:>}", text);
+ }
+
+ [Test]
+ public void BackSpace ()
+ {
+ string text = "Go, \bNo\bGo" ;
+ Regex re = new Regex(@"\b[\b]");
+ text = re.Replace(text, " ");
+ AssertEquals("#01", "Go, \bNo Go", text);
+ }
+
+ [Test]
+ public void ReplaceNegOneAndStartat ()
+ {
+ string text = "abcdeeee";
+ Regex re = new Regex("e+");
+ text = re.Replace(text, "e", -1, 4);
+ AssertEquals("#01", "abcde", text);
+ }
+
+ [Test]
+ //[Ignore] You may want to ignore this if the bugs gets back
+ public void SplitInfiniteLoop () // bug 57274
+ {
+ string ss = "a b c d e";
+ string [] words = Regex.Split (ss, "[ \t\n\r]*");
+ AssertEquals ("#01Length", 11, words.Length);
+ AssertEquals ("#00", "", words [0]);
+ AssertEquals ("#01", "a", words [1]);
+ AssertEquals ("#02", "", words [2]);
+ AssertEquals ("#03", "b", words [3]);
+ AssertEquals ("#04", "", words [4]);
+ AssertEquals ("#05", "c", words [5]);
+ AssertEquals ("#06", "", words [6]);
+ AssertEquals ("#07", "d", words [7]);
+ AssertEquals ("#08", "", words [8]);
+ AssertEquals ("#09", "e", words [9]);
+ AssertEquals ("#10", "", words [10]);
+
+ }
+
+ [Test]
+ public void CaseAndSearch () // bug 69065
+ {
+ string test1 = @"\f!E ZWEITBAD :REGLER-PARAMETER 20.10.2004 SEITE 1";
+ string test2 = @" REGLER-PARAMETER ";
+ string test3 = @"REGLER-PARAMETER ";
+ Regex x = new Regex ("REGLER-PARAMETER",RegexOptions.IgnoreCase|RegexOptions.Compiled);
+
+ Match m = x.Match (test1);
+ AssertEquals ("#01", true, m.Success);
+
+ m = x.Match (test2);
+ AssertEquals ("#02", true, m.Success);
+
+ m = x.Match (test3);
+ AssertEquals ("#03", true, m.Success);
+ }
+
+ [Test]
+ public void QuantifiersParseError () // bug 69193
+ {
+ Regex x = new Regex ("{1,a}");
+ x = new Regex ("{a,1}");
+ x = new Regex ("{a}");
+ x = new Regex ("{,a}");
+ }
+
+ [Test]
+ public void NameLookupInEmptyMatch () // bug 74753
+ {
+ Regex regTime = new Regex (
+ @"(?<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})");
+
+ Match mTime = regTime.Match("");
+ AssertEquals ("#01", "", mTime.Groups["hour"].Value);
+ AssertEquals ("#02", "", mTime.Groups["minute"].Value);
+ AssertEquals ("#03", "", mTime.Groups["second"].Value);
+ AssertEquals ("#04", "", mTime.Groups["ampm"].Value);
+
+ mTime = regTime.Match("12:00 pm");
+ AssertEquals ("#05", "12", mTime.Groups["hour"].Value);
+ AssertEquals ("#06", "00", mTime.Groups["minute"].Value);
+ AssertEquals ("#07", "", mTime.Groups["second"].Value);
+ AssertEquals ("#08", "pm", mTime.Groups["ampm"].Value);
+ }
+
+ [Test]
+ public void HangingHyphens ()
+ {
+ // bug 77626
+ Assert ("#01", Regex.IsMatch ("mT1[", @"m[0-9A-Za-z_-]+\["));
+ Assert ("#02", Regex.IsMatch ("mT1[", @"m[-0-9A-Za-z_]+\["));
+
+ Assert ("#03", Regex.IsMatch ("-a;", @"[--a]{3}"));
+ Assert ("#04", Regex.IsMatch ("-&,", @"[&--]{3}"));
+
+ Assert ("#05", Regex.IsMatch ("abcz-", @"[a-c-z]{5}"));
+ Assert ("#05b", !Regex.IsMatch ("defghijklmnopqrstuvwxy", @"[a-c-z]"));
+
+ Assert ("#06", Regex.IsMatch ("abcxyz-", @"[a-c-x-z]{7}"));
+ Assert ("#06b", !Regex.IsMatch ("defghijklmnopqrstuvw", @"[a-c-x-z]"));
+
+ Assert ("#07", Regex.IsMatch (" \tz-", @"[\s-z]{4}"));
+ Assert ("#07b", !Regex.IsMatch ("abcdefghijklmnopqrstuvwxy", @"[\s-z]"));
+ }
+
+ [Test, ExpectedException (typeof (ArgumentException))]
+ public void HangingHyphen1 ()
+ {
+ bool b = Regex.IsMatch ("foobar", @"[a-\s]");
+ }
+
+ [Test]
+ public void Bug77487 ()
+ {
+ Assert ("#01", Regex.IsMatch ("a a", "^(a[^a]*)*a$"));
+ Assert ("#02", Regex.IsMatch ("a a", "^(a *)*a$"));
+ Assert ("#03", Regex.IsMatch ("a a", "(a[^a]*)+a"));
+ Assert ("#04", Regex.IsMatch ("a a", "(a *)+a"));
+ }
+
+ [Test]
+ public void Bug69269 ()
+ {
+ string s = "CREATE aa\faa; CREATE bb\nbb; CREATE cc\rcc; CREATE dd\tdd; CREATE ee\vee;";
+ AssertEquals ("#01", 5, Regex.Matches(s, @"CREATE[\s\S]+?;").Count);
+ AssertEquals ("#02", 5, Regex.Matches(s, @"CREATE[ \f\n\r\t\v\S]+?;").Count);
+ }
+
+ [Test]
+ public void Bug76345 ()
+ {
+ Match m;
+ string s1 = "'asdf'";
+ string s2 = "'as,'df'";
+
+ m = new Regex("'.*?'").Match(s1); Assert ("#01", m.Success); AssertEquals ("#01v", s1, m.Value);
+ m = new Regex("'[^,].*?'").Match(s1); Assert ("#02", m.Success); AssertEquals ("#02v", s1, m.Value);
+ m = new Regex("'.*?[^,]'").Match(s1); Assert ("#03", m.Success); AssertEquals ("#03v", s1, m.Value);
+ m = new Regex("'.*?[^,]'").Match(s2); Assert ("#04", m.Success); AssertEquals ("#04v", s2, m.Value);
+ }
+
+ [Test]
+ public void Bug78007 ()
+ {
+ string test = "head><html>";
+ string pattern = @"\Ahead>\<html\>";
+ Regex r = new Regex (pattern);
+ Match m = r.Match (test);
+ Assert ("#01", m.Success);
+ AssertEquals ("#01i", 0, m.Index);
+ AssertEquals ("#01l", 14, m.Length);
+
+ m = m.NextMatch ();
+ Assert ("#02", !m.Success);
+ }
+
+ [Test]
+ public void CharClassWithIgnoreCase ()
+ {
+ string str = "Foobar qux";
+ Regex re = new Regex (@"[a-z\s]*", RegexOptions.IgnoreCase);
+ Match m = re.Match (str);
+ AssertEquals ("#01", str, m.Value);
+ }
+
+ void Kill65535_1 (int length)
+ {
+ StringBuilder sb = new StringBuilder ("x");
+ sb.Append ('a', length);
+ sb.Append ('y');
+ string teststring = sb.ToString ();
+ Regex regex = new Regex (@"xa*y");
+ Match m = regex.Match (teststring);
+ Assert ("#01 " + length, m.Success);
+ AssertEquals ("#02 " + length, m.Index, 0);
+ AssertEquals ("#03 " + length, m.Length, teststring.Length);
+ }
+
+ void Kill65535_2 (int length)
+ {
+ StringBuilder sb = new StringBuilder ("xaaaax");
+ sb.Append ('a', length);
+ sb.Append ('y');
+ string teststring = sb.ToString ();
+ Regex regex = new Regex (@"x.*y");
+ Match m = regex.Match(teststring);
+ Assert ("#01 " + length, m.Success);
+ AssertEquals ("#02 " + length, m.Index, 0);
+ AssertEquals ("#03 " + length, m.Length, teststring.Length);
+ }
+
+
+ [Test] // Based on bug #78278
+ public void No65535Limit ()
+ {
+ Kill65535_1 (65535);
+ Kill65535_1 (65536);
+ Kill65535_1 (131071);
+ Kill65535_1 (131072);
+
+ Kill65535_2 (65530);
+ Kill65535_2 (65531);
+ Kill65535_2 (131066);
+ Kill65535_2 (131067);
+ }
}
}
-