Merge pull request #201 from QuickJack/master
[mono.git] / mcs / class / corlib / Test / System.Text / StringBuilderTest.cs
index 474ee48de0911b18df17b04d54ccb573a028e34d..441171be03a84c6e9d3a800bebd527840fd29e6b 100644 (file)
-// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-\r
-//\r
-// StringBuilderTest.dll - NUnit Test Cases for the System.Text.StringBuilder class\r
-// \r
-// Author: Marcin Szczepanski (marcins@zipworld.com.au)\r
-//\r
-// NOTES: I've also run all these tests against the MS implementation of \r
-// System.Text.StringBuilder to confirm that they return the same results\r
-// and they do.\r
-//\r
-// TODO: Add tests for the AppendFormat methods once the AppendFormat methods\r
-// are implemented in the StringBuilder class itself\r
-//\r
-// TODO: Potentially add more variations on Insert / Append tests for all the\r
-// possible types.  I don't really think that's necessary as they all\r
-// pretty much just do .ToString().ToCharArray() and then use the Append / Insert\r
-// CharArray function.  The ToString() bit for each type should be in the unit\r
-// tests for those types, and the unit test for ToCharArray should be in the \r
-// string test type.  If someone wants to add those tests here for completness \r
-// (and some double checking) then feel free :)\r
-//\r
-\r
-using NUnit.Framework;\r
-using System.Text;\r
-using System;\r
-\r
-namespace MonoTests.System.Text {\r
-\r
-       [TestFixture]\r
-       public class StringBuilderTest : Assertion {\r
-\r
-               private StringBuilder sb;\r
-\r
-               public void TestConstructor1() \r
-               {\r
-                       // check the parameterless ctor\r
-                       sb = new StringBuilder();\r
-                       AssertEquals(String.Empty, sb.ToString());\r
-                       AssertEquals(0, sb.Length);\r
-                       AssertEquals(16, sb.Capacity);\r
-               }\r
-\r
-               public void TestConstructor2() \r
-               {\r
-                       // check ctor that specifies the capacity\r
-                       sb = new StringBuilder(10);\r
-                       AssertEquals(String.Empty, sb.ToString());\r
-                       AssertEquals(0, sb.Length);\r
-                       // check that capacity is not less than default\r
-                       AssertEquals(10, sb.Capacity);\r
-\r
-                       sb = new StringBuilder(42);\r
-                       AssertEquals(String.Empty, sb.ToString());\r
-                       AssertEquals(0, sb.Length);\r
-                       // check that capacity is set\r
-                       AssertEquals(42, sb.Capacity);\r
-               }\r
-               \r
-               public void TestConstructor3() {\r
-                       // check ctor that specifies the capacity & maxCapacity\r
-                       sb = new StringBuilder(444, 1234);\r
-                       AssertEquals(String.Empty, sb.ToString());\r
-                       AssertEquals(0, sb.Length);\r
-                       AssertEquals(444, sb.Capacity);\r
-                       AssertEquals(1234, sb.MaxCapacity);\r
-               }\r
-\r
-               public void TestConstructor4() \r
-               {\r
-                       // check for exception in ctor that specifies the capacity & maxCapacity\r
-                       try {\r
-                               sb = new StringBuilder(9999, 15);\r
-                       }\r
-                       catch (ArgumentOutOfRangeException) {\r
-                               return;\r
-                       }\r
-                       // if we didn't catch an exception, then we have a problem Houston.\r
-                       NUnit.Framework.Assertion.Fail("Capacity exeeds MaxCapacity");\r
-               }\r
-\r
-       public void TestConstructor5() {\r
-               String someString = null;\r
-               sb = new StringBuilder(someString);\r
-               AssertEquals("Should be empty string", String.Empty, sb.ToString());\r
-       }\r
-\r
-       public void TestConstructor6() {\r
-               // check for exception in ctor that prevents startIndex less than zero\r
-               try {\r
-                       String someString = "someString";\r
-                       sb = new StringBuilder(someString, -1, 3, 18);\r
-               }\r
-               catch (ArgumentOutOfRangeException) {\r
-                       return;\r
-               }\r
-               // if we didn't catch an exception, then we have a problem Houston.\r
-               NUnit.Framework.Assertion.Fail("StartIndex not allowed to be less than zero.");\r
-       }\r
-\r
-       public void TestConstructor7() {\r
-               // check for exception in ctor that prevents length less than zero\r
-               try {\r
-                       String someString = "someString";\r
-                       sb = new StringBuilder(someString, 2, -222, 18);\r
-               }\r
-               catch (ArgumentOutOfRangeException) {\r
-                       return;\r
-               }\r
-               // if we didn't catch an exception, then we have a problem Houston.\r
-               NUnit.Framework.Assertion.Fail("Length not allowed to be less than zero.");\r
-       }\r
-\r
-       public void TestConstructor8() {\r
-               // check for exception in ctor that ensures substring is contained in given string\r
-               // check that startIndex is not too big\r
-               try {\r
-                       String someString = "someString";\r
-                       sb = new StringBuilder(someString, 10000, 4, 18);\r
-               }\r
-               catch (ArgumentOutOfRangeException) {\r
-                       return;\r
-               }\r
-               // if we didn't catch an exception, then we have a problem Houston.\r
-               NUnit.Framework.Assertion.Fail("StartIndex and length must refer to a location within the string.");\r
-       }\r
-\r
-       public void TestConstructor9() {\r
-               // check for exception in ctor that ensures substring is contained in given string\r
-               // check that length doesn't go beyond end of string\r
-               try {\r
-                       String someString = "someString";\r
-                       sb = new StringBuilder(someString, 4, 4000, 18);\r
-               }\r
-               catch (ArgumentOutOfRangeException) {\r
-                       return;\r
-               }\r
-               // if we didn't catch an exception, then we have a problem Houston.\r
-               NUnit.Framework.Assertion.Fail("StartIndex and length must refer to a location within the string.");\r
-       }\r
-\r
-       public void TestConstructor10() {\r
-               // check that substring is taken properly and made into a StringBuilder\r
-               String someString = "someString";\r
-               sb = new StringBuilder(someString, 4, 6, 18);\r
-               string expected = "String";\r
-               AssertEquals( expected, sb.ToString());\r
-       }\r
-\r
-       [ExpectedException(typeof(ArgumentOutOfRangeException))]\r
-       public void TestConstructor11 () {\r
-               new StringBuilder (-1);\r
-       }\r
-               \r
-       public void TestAppend() {\r
-                StringBuilder sb = new StringBuilder( "Foo" );\r
-                sb.Append( "Two" );\r
-                string expected = "FooTwo";\r
-                AssertEquals( expected, sb.ToString() );\r
-        }\r
-\r
-        public void TestInsert() {\r
-                StringBuilder sb = new StringBuilder();\r
-\r
-                AssertEquals( String.Empty, sb.ToString() ); \r
-                        /* Test empty StringBuilder conforms to spec */\r
-\r
-                sb.Insert( 0, "Foo" ); /* Test insert at start of empty string */\r
-\r
-                AssertEquals( "Foo", sb.ToString() );\r
-\r
-                sb.Insert( 1, "!!" ); /* Test insert not at start of string */\r
-\r
-                AssertEquals( "F!!oo", sb.ToString() );\r
-\r
-                sb.Insert( 5, ".." ); /* Test insert at end of string */\r
-\r
-                AssertEquals( "F!!oo..", sb.ToString() );\r
-        \r
-                sb.Insert( 0, 1234 ); /* Test insert of a number (at start of string) */\r
-                \r
-                               // FIX: Why does this test fail?\r
-                //AssertEquals( "1234F!!oo..", sb.ToString() );\r
-                \r
-                sb.Insert( 5, 1.5 ); /* Test insert of a decimal (and end of string) */\r
-                \r
-                               // FIX: Why does this test fail?\r
-                               //AssertEquals( "1234F1.5!!oo..", sb.ToString() );\r
-\r
-                sb.Insert( 4, 'A' ); /* Test char insert in middle of string */\r
-\r
-                               // FIX: Why does this test fail?\r
-                               //AssertEquals( "1234AF1.5!!oo..", sb.ToString() );\r
-\r
-        }\r
-\r
-        public void TestReplace() {\r
-                StringBuilder sb = new StringBuilder( "Foobarbaz" );\r
-\r
-                sb.Replace( "bar", "!!!" );             /* Test same length replace in middle of string */\r
-                \r
-                AssertEquals( "Foo!!!baz", sb.ToString() );\r
-\r
-                sb.Replace( "Foo", "ABcD" );            /* Test longer replace at start of string */\r
-\r
-                AssertEquals( "ABcD!!!baz", sb.ToString() );\r
-\r
-                sb.Replace( "baz", "00" );              /* Test shorter replace at end of string */\r
-                        \r
-                AssertEquals( "ABcD!!!00", sb.ToString() );\r
-\r
-                sb.Replace( sb.ToString(), null );      /* Test string clear as in spec */\r
-\r
-                AssertEquals( String.Empty, sb.ToString() );\r
-\r
-                /*           |         10        20        30\r
-                /*         |0123456789012345678901234567890| */\r
-                sb.Append( "abc this is testing abc the abc abc partial replace abc" );\r
-\r
-                sb.Replace( "abc", "!!!", 0, 31 ); /* Partial replace at start of string */\r
-\r
-                AssertEquals( "!!! this is testing !!! the !!! abc partial replace abc", sb.ToString() );\r
-\r
-                sb.Replace( "testing", "", 0, 15 ); /* Test replace across boundary */\r
-\r
-                AssertEquals( "!!! this is testing !!! the !!! abc partial replace abc", sb.ToString() );\r
-\r
-                sb.Replace( "!!!", "" ); /* Test replace with empty string */\r
-\r
-                AssertEquals(" this is testing  the  abc partial replace abc", sb.ToString() );\r
-        }\r
-\r
-        public void TestAppendFormat() {\r
-        }\r
-\r
-       [Test]\r
-       public void MoreReplace ()\r
-       {\r
-               StringBuilder sb = new StringBuilder ();\r
-               sb.Append ("First");\r
-               sb.Append ("Second");\r
-               sb.Append ("Third");\r
-               sb.Replace ("Second", "Gone", 2, sb.Length-2);\r
-               AssertEquals ("#01", "FirstGoneThird", sb.ToString ());\r
-\r
-               sb.Length = 0;\r
-               sb.Append ("This, is, a, list");\r
-               sb.Replace (",", "comma-separated", 11, sb.Length-11);\r
-               AssertEquals ("#02", "This, is, acomma-separated list", sb.ToString ());\r
-       }\r
-\r
-       [Test]\r
-       public void Insert0 ()\r
-       {\r
-               StringBuilder sb = new StringBuilder();\r
-               sb.Append("testtesttest");\r
-               sb.Insert(0, '^');\r
-               AssertEquals ("#01", "^testtesttest", sb.ToString ());\r
-       }\r
-\r
-       [Test]\r
-       public void AppendToEmpty ()\r
-       {\r
-               StringBuilder sb = new StringBuilder();\r
-               char [] ca = new char [] { 'c' };\r
-               sb.Append (ca);\r
-               AssertEquals ("#01", "c", sb.ToString ());\r
-       }\r
-\r
-\r
-       [Test]\r
-       public void TestRemove ()\r
-       {\r
-               StringBuilder b = new StringBuilder ();\r
-               b.Append ("Hello, I am a StringBuilder");\r
-               b.Remove (0, 7);  // Should remove "Hello, "\r
-               AssertEquals ("#01", "I am a StringBuilder", b.ToString ());\r
-       }\r
-\r
-       [Test]\r
-       public void Insert1 ()\r
-       {\r
-               StringBuilder sb = new StringBuilder();\r
-               sb.Insert(0, "aa");\r
-               AssertEquals ("#01", "aa", sb.ToString ());\r
-\r
-               char [] charArr = new char [] { 'b', 'c', 'd' };\r
-               sb.Insert(1, charArr, 1, 1);\r
-               AssertEquals ("#02", "aca", sb.ToString ());\r
-\r
-               sb.Insert (1, null, 0, 0);\r
-               AssertEquals ("#03", "aca", sb.ToString ());\r
-               \r
-               try {\r
-                       sb.Insert (1, null, 1, 1);\r
-                       Assertion.Fail ("#04: Value must not be null if startIndex and charCount > 0");\r
-               } catch (ArgumentNullException) {}\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void Constructor_StartIndexOverflow () \r
-       {\r
-               new StringBuilder ("Mono", Int32.MaxValue, 1, 0);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void Constructor_LengthOverflow () \r
-       {\r
-               new StringBuilder ("Mono", 1, Int32.MaxValue, 0);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void ToString_StartIndexOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.ToString (Int32.MaxValue, 1);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void ToString_LengthOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.ToString (1, Int32.MaxValue);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void Remove_StartIndexOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Remove (Int32.MaxValue, 1);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void Remove_LengthOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Remove (1, Int32.MaxValue);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void ReplaceChar_StartIndexOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Replace ('o', '0', Int32.MaxValue, 1);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void ReplaceChar_CountOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Replace ('0', '0', 1, Int32.MaxValue);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void ReplaceString_StartIndexOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Replace ("o", "0", Int32.MaxValue, 1);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void ReplaceString_CountOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Replace ("o", "0", 1, Int32.MaxValue);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void AppendCharArray_StartIndexOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Append (new char[2], Int32.MaxValue, 1);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void AppendCharArray_CharCountOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Append (new char[2], 1, Int32.MaxValue);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void AppendString_StartIndexOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Append ("!", Int32.MaxValue, 1);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void AppendString_CountOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Append ("!", 1, Int32.MaxValue);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void InsertCharArray_StartIndexOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Insert (0, new char[2], Int32.MaxValue, 1);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void InsertCharArray_CharCountOverflow () \r
-       {\r
-               StringBuilder sb = new StringBuilder ("Mono");\r
-               sb.Insert (0, new char[2], 1, Int32.MaxValue);\r
-       }\r
-\r
-       [Test]\r
-       [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
-       public void MaxCapacity_Overflow1 ()\r
-       {\r
-               StringBuilder sb = new StringBuilder (2, 3);\r
-               sb.Append ("Mono");\r
-       }\r
-\r
-       [Test]\r
-       public void MaxCapacity_Overflow2 ()\r
-       {\r
-               StringBuilder sb = new StringBuilder (2, 3);\r
-               try {\r
-                       sb.Append ("Mono");\r
-               } catch (ArgumentOutOfRangeException) {\r
-               }\r
-\r
-               AssertEquals (2, sb.Capacity);\r
-               AssertEquals (3, sb.MaxCapacity);\r
-       }\r
-\r
-       [Test]\r
-       public void CapacityFromString ()\r
-       {\r
-               StringBuilder sb = new StringBuilder ("hola");\r
-               AssertEquals ("#01", 16, sb.Capacity);\r
-\r
-               sb = new StringBuilder ("01234567890123456789");\r
-               AssertEquals ("#02", 32, sb.Capacity);\r
-       }\r
-}\r
-\r
-}\r
+// -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+//
+// StringBuilderTest.dll - NUnit Test Cases for the System.Text.StringBuilder class
+// 
+// Author: Marcin Szczepanski (marcins@zipworld.com.au)
+//
+// NOTES: I've also run all these tests against the MS implementation of 
+// System.Text.StringBuilder to confirm that they return the same results
+// and they do.
+//
+// TODO: Add tests for the AppendFormat methods once the AppendFormat methods
+// are implemented in the StringBuilder class itself
+//
+// TODO: Potentially add more variations on Insert / Append tests for all the
+// possible types.  I don't really think that's necessary as they all
+// pretty much just do .ToString().ToCharArray() and then use the Append / Insert
+// CharArray function.  The ToString() bit for each type should be in the unit
+// tests for those types, and the unit test for ToCharArray should be in the 
+// string test type.  If someone wants to add those tests here for completness 
+// (and some double checking) then feel free :)
+//
+
+using NUnit.Framework;
+using System.Text;
+using System;
+
+namespace MonoTests.System.Text {
+
+       [TestFixture]
+       public class StringBuilderTest  {
+
+               private StringBuilder sb;
+
+               [Test]
+               public void TestConstructor1() 
+               {
+                       // check the parameterless ctor
+                       sb = new StringBuilder();
+                       Assert.AreEqual(String.Empty, sb.ToString());
+                       Assert.AreEqual(0, sb.Length);
+                       Assert.AreEqual(16, sb.Capacity);
+               }
+
+               [Test]
+               public void TestConstructor2() 
+               {
+                       // check ctor that specifies the capacity
+                       sb = new StringBuilder(10);
+                       Assert.AreEqual(String.Empty, sb.ToString());
+                       Assert.AreEqual(0, sb.Length);
+                       // check that capacity is not less than default
+                       Assert.AreEqual(10, sb.Capacity);
+
+                       sb = new StringBuilder(42);
+                       Assert.AreEqual(String.Empty, sb.ToString());
+                       Assert.AreEqual(0, sb.Length);
+                       // check that capacity is set
+                       Assert.AreEqual(42, sb.Capacity);
+               }
+
+               [Test]          
+               public void TestConstructor3() {
+                       // check ctor that specifies the capacity & maxCapacity
+                       sb = new StringBuilder(444, 1234);
+                       Assert.AreEqual(String.Empty, sb.ToString());
+                       Assert.AreEqual(0, sb.Length);
+                       Assert.AreEqual(444, sb.Capacity);
+                       Assert.AreEqual(1234, sb.MaxCapacity);
+               }
+
+               [Test]
+               public void TestConstructor4() 
+               {
+                       // check for exception in ctor that specifies the capacity & maxCapacity
+                       try {
+                               sb = new StringBuilder(9999, 15);
+                       }
+                       catch (ArgumentOutOfRangeException) {
+                               return;
+                       }
+                       // if we didn't catch an exception, then we have a problem Houston.
+                       NUnit.Framework.Assertion.Fail("Capacity exceeds MaxCapacity");
+               }
+
+               [Test]
+       public void TestConstructor5() {
+               String someString = null;
+               sb = new StringBuilder(someString);
+               Assert.AreEqual(String.Empty, sb.ToString(), "Should be empty string");
+       }
+
+               [Test]
+       public void TestConstructor6() {
+               // check for exception in ctor that prevents startIndex less than zero
+               try {
+                       String someString = "someString";
+                       sb = new StringBuilder(someString, -1, 3, 18);
+               }
+               catch (ArgumentOutOfRangeException) {
+                       return;
+               }
+               // if we didn't catch an exception, then we have a problem Houston.
+               NUnit.Framework.Assertion.Fail("StartIndex not allowed to be less than zero.");
+       }
+
+               [Test]
+       public void TestConstructor7() {
+               // check for exception in ctor that prevents length less than zero
+               try {
+                       String someString = "someString";
+                       sb = new StringBuilder(someString, 2, -222, 18);
+               }
+               catch (ArgumentOutOfRangeException) {
+                       return;
+               }
+               // if we didn't catch an exception, then we have a problem Houston.
+               NUnit.Framework.Assertion.Fail("Length not allowed to be less than zero.");
+       }
+
+               [Test]
+       public void TestConstructor8() {
+               // check for exception in ctor that ensures substring is contained in given string
+               // check that startIndex is not too big
+               try {
+                       String someString = "someString";
+                       sb = new StringBuilder(someString, 10000, 4, 18);
+               }
+               catch (ArgumentOutOfRangeException) {
+                       return;
+               }
+               // if we didn't catch an exception, then we have a problem Houston.
+               NUnit.Framework.Assertion.Fail("StartIndex and length must refer to a location within the string.");
+       }
+
+               [Test]
+       public void TestConstructor9() {
+               // check for exception in ctor that ensures substring is contained in given string
+               // check that length doesn't go beyond end of string
+               try {
+                       String someString = "someString";
+                       sb = new StringBuilder(someString, 4, 4000, 18);
+               }
+               catch (ArgumentOutOfRangeException) {
+                       return;
+               }
+               // if we didn't catch an exception, then we have a problem Houston.
+               NUnit.Framework.Assertion.Fail("StartIndex and length must refer to a location within the string.");
+       }
+
+               [Test]
+       public void TestConstructor10() {
+               // check that substring is taken properly and made into a StringBuilder
+               String someString = "someString";
+               sb = new StringBuilder(someString, 4, 6, 18);
+               string expected = "String";
+               Assert.AreEqual( expected, sb.ToString());
+       }
+
+               [Test]
+       [ExpectedException(typeof(ArgumentOutOfRangeException))]
+       public void TestConstructor11 () {
+               new StringBuilder (-1);
+       }
+
+               [Test]          
+       public void TestAppend() {
+                StringBuilder sb = new StringBuilder( "Foo" );
+                sb.Append( "Two" );
+                string expected = "FooTwo";
+                Assert.AreEqual( expected, sb.ToString() );
+        }
+
+               [Test]
+        public void TestInsert() {
+                StringBuilder sb = new StringBuilder();
+
+                Assert.AreEqual( String.Empty, sb.ToString() ); 
+                        /* Test empty StringBuilder conforms to spec */
+
+                sb.Insert( 0, "Foo" ); /* Test insert at start of empty string */
+
+                Assert.AreEqual( "Foo", sb.ToString() );
+
+                sb.Insert( 1, "!!" ); /* Test insert not at start of string */
+
+                Assert.AreEqual( "F!!oo", sb.ToString() );
+
+                sb.Insert( 5, ".." ); /* Test insert at end of string */
+
+                Assert.AreEqual( "F!!oo..", sb.ToString() );
+        
+                sb.Insert( 0, 1234 ); /* Test insert of a number (at start of string) */
+                
+                               // FIX: Why does this test fail?
+                //Assert.AreEqual( "1234F!!oo..", sb.ToString() );
+                
+                sb.Insert( 5, 1.5 ); /* Test insert of a decimal (and end of string) */
+                
+                               // FIX: Why does this test fail?
+                               //Assert.AreEqual( "1234F1.5!!oo..", sb.ToString() );
+
+                sb.Insert( 4, 'A' ); /* Test char insert in middle of string */
+
+                               // FIX: Why does this test fail?
+                               //Assert.AreEqual( "1234AF1.5!!oo..", sb.ToString() );
+
+        }
+
+               [Test]
+        public void TestReplace() {
+                StringBuilder sb = new StringBuilder( "Foobarbaz" );
+
+                sb.Replace( "bar", "!!!" );             /* Test same length replace in middle of string */
+                
+                Assert.AreEqual( "Foo!!!baz", sb.ToString() );
+
+                sb.Replace( "Foo", "ABcD" );            /* Test longer replace at start of string */
+
+                Assert.AreEqual( "ABcD!!!baz", sb.ToString() );
+
+                sb.Replace( "baz", "00" );              /* Test shorter replace at end of string */
+                        
+                Assert.AreEqual( "ABcD!!!00", sb.ToString() );
+
+                sb.Replace( sb.ToString(), null );      /* Test string clear as in spec */
+
+                Assert.AreEqual( String.Empty, sb.ToString() );
+
+                /*           |         10        20        30
+                /*         |0123456789012345678901234567890| */
+                sb.Append( "abc this is testing abc the abc abc partial replace abc" );
+
+                sb.Replace( "abc", "!!!", 0, 31 ); /* Partial replace at start of string */
+
+                Assert.AreEqual( "!!! this is testing !!! the !!! abc partial replace abc", sb.ToString() );
+
+                sb.Replace( "testing", "", 0, 15 ); /* Test replace across boundary */
+
+                Assert.AreEqual( "!!! this is testing !!! the !!! abc partial replace abc", sb.ToString() );
+
+                sb.Replace( "!!!", "" ); /* Test replace with empty string */
+
+                Assert.AreEqual(sb.ToString() , " this is testing  the  abc partial replace abc");
+        }
+
+               [Test]
+        public void TestAppendFormat() {
+        }
+
+       [Test]
+       public void MoreReplace ()
+       {
+               StringBuilder sb = new StringBuilder ();
+               sb.Append ("First");
+               sb.Append ("Second");
+               sb.Append ("Third");
+               sb.Replace ("Second", "Gone", 2, sb.Length-2);
+               Assert.AreEqual ("FirstGoneThird", sb.ToString (), "#01");
+
+               sb.Length = 0;
+               sb.Append ("This, is, a, list");
+               sb.Replace (",", "comma-separated", 11, sb.Length-11);
+               Assert.AreEqual ("This, is, acomma-separated list", sb.ToString (), "#02");
+       }
+
+       [Test]
+       public void Insert0 ()
+       {
+               StringBuilder sb = new StringBuilder();
+               sb.Append("testtesttest");
+               sb.Insert(0, '^');
+               Assert.AreEqual ("^testtesttest", sb.ToString (), "#01");
+       }
+
+       [Test]
+       public void AppendToEmpty ()
+       {
+               StringBuilder sb = new StringBuilder();
+               char [] ca = new char [] { 'c' };
+               sb.Append (ca);
+               Assert.AreEqual ("c", sb.ToString (), "#01");
+       }
+
+
+       [Test]
+       public void TestRemove ()
+       {
+               StringBuilder b = new StringBuilder ();
+               b.Append ("Hello, I am a StringBuilder");
+               b.Remove (0, 7);  // Should remove "Hello, "
+               Assert.AreEqual ("I am a StringBuilder", b.ToString (), "#01");
+       }
+
+       [Test]
+       public void Insert1 ()
+       {
+               StringBuilder sb = new StringBuilder();
+               sb.Insert(0, "aa");
+               Assert.AreEqual ("aa", sb.ToString (), "#01");
+
+               char [] charArr = new char [] { 'b', 'c', 'd' };
+               sb.Insert(1, charArr, 1, 1);
+               Assert.AreEqual ("aca", sb.ToString (), "#02");
+
+               sb.Insert (1, null, 0, 0);
+               Assert.AreEqual ("aca", sb.ToString (), "#03");
+               
+               try {
+                       sb.Insert (1, null, 1, 1);
+                       Assertion.Fail ("#04: Value must not be null if startIndex and charCount > 0");
+               } catch (ArgumentNullException) {}
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void Constructor_StartIndexOverflow () 
+       {
+               new StringBuilder ("Mono", Int32.MaxValue, 1, 0);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void Constructor_LengthOverflow () 
+       {
+               new StringBuilder ("Mono", 1, Int32.MaxValue, 0);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void ToString_StartIndexOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.ToString (Int32.MaxValue, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void ToString_LengthOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.ToString (1, Int32.MaxValue);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void Remove_StartIndexOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Remove (Int32.MaxValue, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void Remove_LengthOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Remove (1, Int32.MaxValue);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void ReplaceChar_StartIndexOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Replace ('o', '0', Int32.MaxValue, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void ReplaceChar_CountOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Replace ('0', '0', 1, Int32.MaxValue);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void ReplaceString_StartIndexOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Replace ("o", "0", Int32.MaxValue, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void ReplaceString_CountOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Replace ("o", "0", 1, Int32.MaxValue);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void AppendCharArray_StartIndexOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Append (new char[2], Int32.MaxValue, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void AppendCharArray_CharCountOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Append (new char[2], 1, Int32.MaxValue);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void AppendString_StartIndexOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Append ("!", Int32.MaxValue, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void AppendString_CountOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Append ("!", 1, Int32.MaxValue);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void InsertCharArray_StartIndexOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Insert (0, new char[2], Int32.MaxValue, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void InsertCharArray_CharCountOverflow () 
+       {
+               StringBuilder sb = new StringBuilder ("Mono");
+               sb.Insert (0, new char[2], 1, Int32.MaxValue);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void MaxCapacity_Overflow1 ()
+       {
+               StringBuilder sb = new StringBuilder (2, 3);
+               sb.Append ("Mono");
+       }
+
+       [Test]
+       public void MaxCapacity_Overflow2 ()
+       {
+               StringBuilder sb = new StringBuilder (2, 3);
+               try {
+                       sb.Append ("Mono");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               Assert.AreEqual (2, sb.Capacity);
+               Assert.AreEqual (3, sb.MaxCapacity);
+       }
+       
+       [Test]
+#if ONLY_1_1
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       [Category ("NotWorking")] // Mono follows 2.0 behaviour in this case
+#endif
+       public void MaxCapacity_Overflow3 ()
+       {
+               //
+               // When the capacity (4) gets doubled, it is greater than the
+               // max capacity. This makes sure that before throwing an exception
+               // we first attempt to go for a smaller size.
+               //
+               new StringBuilder(4, 7).Append ("foo").Append ("bar");
+               new StringBuilder(4, 6).Append ("foo").Append ("bar");
+               // this throws ArgumentOutOfRangeException on MS 1.1 SP1
+       }
+
+       [Test]
+       public void CapacityFromString ()
+       {
+               StringBuilder sb = new StringBuilder ("hola").Append ("lala");
+               Assert.AreEqual ("holalala", sb.ToString (), "#01");
+       }
+
+       [Test]
+       public void ReplaceWithLargerString ()
+       {
+               StringBuilder sb = new StringBuilder ("ABCDE");
+               Assert.AreEqual ("ABCDE", sb.ToString (), "#1");
+               sb.Replace ("ABC", "abcaa", 0, 3);
+               Assert.AreEqual ("abcaaDE", sb.ToString (), "#2");
+       }
+
+       [Test]
+       public void MaxCapacity_Overflow4 ()
+       {
+               StringBuilder sb = new StringBuilder (2, 3);
+               Assert.AreEqual (2, sb.Capacity);
+               Assert.AreEqual (3, sb.MaxCapacity);
+               try {
+                       sb.Length = 4;
+                       Assert.Fail ("#01");
+               } catch (ArgumentOutOfRangeException) {
+               }
+
+               try {
+                       sb.EnsureCapacity (5);
+                       Assert.Fail ("#02");
+               } catch (ArgumentOutOfRangeException) {
+               }
+       }
+       
+       [Test]
+       public void NullInCtor ()
+       {
+               StringBuilder sb = null;
+               try {
+                       sb = new StringBuilder (null, 10);
+               } catch (Exception e) {
+                       Assert.Fail ("Should not throw #01");
+               }
+
+               Assert.IsTrue (sb.Length == 0);
+       }
+
+       [Test]
+       public void SetLength ()
+       {
+               StringBuilder sb = new StringBuilder ("Text");
+               Assert.AreEqual (4, sb.Length, "#1");
+               Assert.AreEqual ("Text", sb.ToString (), "#2");
+               sb.Length = 8;
+               Assert.AreEqual (8, sb.Length, "#3");
+               Assert.AreEqual ("Text\0\0\0\0", sb.ToString (), "#4");
+       }
+
+
+#if NET_4_0 || MOONLIGHT || MOBILE
+       [Test]
+       public void ClearMethod () {
+               StringBuilder sb = new StringBuilder ("Text");
+               sb.Clear ();
+               Assert.AreEqual (0, sb.Length, "#1");
+               Assert.AreEqual (String.Empty, sb.ToString (), "#2");
+       }
+#endif
+
+}
+
+}