* GroupTest.cs: Improved test for null argument check.
authorGert Driesen <drieseng@users.sourceforge.net>
Thu, 1 Nov 2007 21:17:50 +0000 (21:17 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Thu, 1 Nov 2007 21:17:50 +0000 (21:17 -0000)
* MatchTest.cs: Improved tests for null argument checks. Added and
fixed replacement tests.
* RegexMatchTest.cs: Marked tests that do not pass on MS as NotDotNet.
Fixed expected result for trial 5.
* RegexResultTests.cs: Fixed Assert.
* Match.cs: Do not throw NotSupportedException on zero-length
replacement argument.

svn path=/trunk/mcs/; revision=88685

mcs/class/System/System.Text.RegularExpressions/ChangeLog
mcs/class/System/System.Text.RegularExpressions/Match.cs
mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
mcs/class/System/Test/System.Text.RegularExpressions/GroupTest.cs
mcs/class/System/Test/System.Text.RegularExpressions/MatchTest.cs
mcs/class/System/Test/System.Text.RegularExpressions/RegexMatchTests.cs
mcs/class/System/Test/System.Text.RegularExpressions/RegexResultTests.cs

index ac9b092113a0ad6e62180af39fe30b94fb2530c7..8c17077e16e8deb14e8db5d909b05060dbfce5f9 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-01  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * Match.cs: Do not throw NotSupportedException on zero-length
+       replacement argument.
+
 2007-10-29 Arina Itkes <arinai@mainsoft.com>
 
        * Regex.cs: Moving creation of Regex machine to ctor.
index feb5548d42dd8bcc215ba5aa45713cb8b66e8cbc..a9147b96d1a7835706c7d830daebb5cd3c9ef480 100644 (file)
@@ -66,8 +66,6 @@ namespace System.Text.RegularExpressions {
                {
                        if (replacement == null)
                                throw new ArgumentNullException ("replacement");
-                       if (replacement.Length == 0)
-                               throw new NotSupportedException ();
                        if (machine == null)
                                throw new NotSupportedException ("Result cannot be called on failed Match.");
 
index 11cd87a18498a1c6052923b4d72df2ff94872b27..824a0a2f0487053325a5814e64a630174a7153ee 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-01  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * GroupTest.cs: Improved test for null argument check.
+       * MatchTest.cs: Improved tests for null argument checks. Added and
+       fixed replacement tests.
+       * RegexMatchTest.cs: Marked tests that do not pass on MS as NotDotNet.
+       Fixed expected result for trial 5.
+       * RegexResultTests.cs: Fixed Assert.
+
 2007-10-29 Arina Itkes <arinai@mainsoft.com>
 
        * RegexReplace.cs RegxMatchTests.cs RegexResultTests.cs
index 021b98e4890c540cf489261b979dbc0194a00be2..51885287e5e46f31a6e6f953c327f129360158da 100644 (file)
@@ -31,16 +31,24 @@ using NUnit.Framework;
 using System;
 using System.Text.RegularExpressions;
 
-namespace MonoTests.System.Text.RegularExpressions {
-
+namespace MonoTests.System.Text.RegularExpressions
+{
        [TestFixture]
-       public class GroupTest {
-
+       public class GroupTest
+       {
                [Test]
-               [ExpectedException (typeof (ArgumentNullException))]
-               public void Synchronized_Null ()
+               public void Synchronized_Inner_Null ()
                {
-                       Group.Synchronized (null);
+                       try {
+                               Group.Synchronized (null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("inner", ex.ParamName, "#6");
+                       }
                }
 
                [Test]
@@ -48,7 +56,7 @@ namespace MonoTests.System.Text.RegularExpressions {
                {
                        Group eg = Match.Empty.Groups[0];
                        Group sg = Match.Synchronized (eg);
-                       Assert.IsTrue (Object.ReferenceEquals (eg, sg), "Synchronized");
+                       Assert.AreSame (eg, sg, "Synchronized");
                }
        }
 }
index 1f2354878f80bb29d166830f6c45bfd068877570..c8601805d0645d0044d93be2528b3fd587021093 100644 (file)
@@ -37,10 +37,18 @@ namespace MonoTests.System.Text.RegularExpressions
        public class MatchTest
        {
                [Test]
-               [ExpectedException (typeof (ArgumentNullException))]
-               public void Synchronized_Null ()
+               public void Synchronized_Inner_Null ()
                {
-                       Match.Synchronized (null);
+                       try {
+                               Match.Synchronized (null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("inner", ex.ParamName, "#6");
+                       }
                }
 
                [Test]
@@ -48,21 +56,45 @@ namespace MonoTests.System.Text.RegularExpressions
                {
                        Match em = Match.Empty;
                        Match sm = Match.Synchronized (em);
-                       Assert.IsTrue (Object.ReferenceEquals (em, sm), "Synchronized");
+                       Assert.AreSame (em, sm, "Synchronized");
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentNullException))]
-               public void Result_Null ()
+               public void Result_Replacement_Null ()
                {
-                       Match.Empty.Result (null);
+                       try {
+                               Match.Empty.Result (null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNotNull (ex.ParamName, "#5");
+                               Assert.AreEqual ("replacement", ex.ParamName, "#6");
+                       }
                }
 
                [Test]
-               [ExpectedException (typeof (NotSupportedException))]
-               public void Result_Empty ()
+               public void Result_Replacement_Empty ()
                {
-                       Match.Empty.Result (String.Empty);
+                       Regex email = new Regex ("(?<user>[^@]+)@(?<domain>.+)");
+                       Match m = email.Match ("mono@go-mono.com");
+                       string exp = m.Result (string.Empty);
+                       Assert.AreEqual (string.Empty, exp);
+               }
+
+               [Test]
+               public void Result_Match_Empty ()
+               {
+                       try {
+                               Match.Empty.Result ("whatever");
+                               Assert.Fail ("#1");
+                       } catch (NotSupportedException ex) {
+                               // Result cannot be called on failed Match
+                               Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                       }
                }
        }
 }
index 90b99a3a7750aa4be0ce265d3a02008bef550098..fa60eb67e3aaa180345a932604d41430e18793c6 100644 (file)
@@ -27,7 +27,7 @@ namespace MonoTests.System.Text.RegularExpressions
                        + " Group[10]=(9,2)"
                        + " Group[11]=(11,1)"
                        ),
-                       new RegexTrial (@"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", RegexOptions.ExplicitCapture, "F2345678910LL", "Fail"),//5
+                       new RegexTrial (@"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", RegexOptions.ExplicitCapture, "F2345678910LL", "Fail."),//5
                        new RegexTrial (@"(F)(2)(3)(4)(5)(6)(?<S>7)(8)(9)(10)(L)\1", RegexOptions.None, "F2345678910L71", "Fail."),//6
                        new RegexTrial (@"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", RegexOptions.None, "F2345678910LF1", "Fail."),//7
                        new RegexTrial (@"(F)(2)(3)(4)(5)(6)(?<S>7)(8)(9)(10)(L)\11", RegexOptions.None, "F2345678910L71", "Pass."//8
@@ -150,64 +150,139 @@ namespace MonoTests.System.Text.RegularExpressions
                        new RegexTrial (@"(?>a*).", RegexOptions.ExplicitCapture, "aaaa", "Fail."),//52
                };
 
-               [Test]  public void RegexJvmTrial0000 () { trials [0].Execute (); }
-               [Test]  public void RegexJvmTrial0001 () { trials [1].Execute (); }
+               [Test]
+               public void RegexJvmTrial0000 ()
+               {
+                       trials [0].Execute ();
+               }
+
+               [Test]
+               public void RegexJvmTrial0001 ()
+               {
+                       trials [1].Execute ();
+               }
 
                [Test]
+               [Category ("NotDotNet")]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0002 () { trials [2].Execute (); }
+               public void RegexJvmTrial0002 ()
+               {
+                       trials [2].Execute ();
+               }
+
+               [Test]
+               public void RegexJvmTrial0003 ()
+               {
+                       trials [3].Execute ();
+               }
 
-               [Test]  public void RegexJvmTrial0003 () { trials [3].Execute (); }
-               [Test]  public void RegexJvmTrial0004 () { trials [4].Execute (); }
+               [Test]
+               public void RegexJvmTrial0004 ()
+               {
+                       trials [4].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0005 () { trials [5].Execute (); }
+               public void RegexJvmTrial0005 ()
+               {
+                       trials [5].Execute ();
+               }
 
-               [Test]  public void RegexJvmTrial0006 () { trials [6].Execute (); }
-               [Test]  public void RegexJvmTrial0007 () { trials [7].Execute (); }
+               [Test]
+               public void RegexJvmTrial0006 ()
+               {
+                       trials [6].Execute ();
+               }
+
+               [Test]
+               public void RegexJvmTrial0007 ()
+               {
+                       trials [7].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0008 () { trials [8].Execute (); }
+               [Category ("NotDotNet")]
+               public void RegexJvmTrial0008 ()
+               {
+                       trials [8].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0009 () { trials [9].Execute (); }
+               [Category ("NotDotNet")]
+               public void RegexJvmTrial0009 ()
+               {
+                       trials [9].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0010 () { trials [10].Execute (); }
+               public void RegexJvmTrial0010 ()
+               {
+                       trials [10].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0011 () { trials [11].Execute (); }
+               public void RegexJvmTrial0011 ()
+               {
+                       trials [11].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0012 () { trials [12].Execute (); }
+               public void RegexJvmTrial0012 ()
+               {
+                       trials [12].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0013 () { trials [13].Execute (); }
+               [Category ("NotDotNet")]
+               public void RegexJvmTrial0013 ()
+               {
+                       trials [13].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0014 () { trials [14].Execute (); }
+               [Category ("NotDotNet")]
+               public void RegexJvmTrial0014 ()
+               {
+                       trials [14].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0015 () { trials [15].Execute (); }
+               [Category ("NotDotNet")]
+               public void RegexJvmTrial0015 ()
+               {
+                       trials [15].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0016 () { trials [16].Execute (); }
+               [Category ("NotDotNet")]
+               public void RegexJvmTrial0016 ()
+               {
+                       trials [16].Execute ();
+               }
 
-               [Test]  public void RegexJvmTrial0017 () { trials [17].Execute (); }
+               [Test]
+               public void RegexJvmTrial0017 ()
+               {
+                       trials [17].Execute ();
+               }
 
                [Test]
                [Category ("NotWorking")]
-               public void RegexJvmTrial0018 () { trials [18].Execute (); }
+               [Category ("NotDotNet")]
+               public void RegexJvmTrial0018 ()
+               {
+                       trials [18].Execute ();
+               }
                
                [Test]  public void RegexJvmTrial0019 () { trials [19].Execute (); }
                [Test]  public void RegexJvmTrial0020 () { trials [20].Execute (); }
index beae5a6b6418b4f34435996834a7618bf8ed24c5..e73e7bf72c1e5be1dd1948cca2cce5f901830903 100644 (file)
@@ -27,8 +27,8 @@ namespace MonoTests.System.Text.RegularExpressions
                                catch (Exception e) {
                                        result = "Error.";
                                }
-                               Assert.AreEqual (result, expected, "rr#: {1} ~ s,{2},{3},",
-                               original, pattern, replacement);
+                               Assert.AreEqual (expected, result, "rr#: {0} ~ s,{1},{2},",
+                                       original, pattern, replacement);
 
                        }
                }