using NUnit.Framework;
using System;
+using System.Text;
using System.Text.RegularExpressions;
namespace MonoTests.System.Text.RegularExpressions
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);
}
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
{
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);
+ }
}
}
-