Add unit test for AggregateException.GetBaseException that works on .net but is broke...
[mono.git] / mcs / class / corlib / Test / System / StringTest.cs
1 // StringTest.cs - NUnit Test Cases for the System.String class
2 //
3 // Authors:
4 //   Jeffrey Stedfast <fejj@ximian.com>
5 //   David Brandt <bucky@keystreams.com>
6 //   Kornel Pal <http://www.kornelpal.hu/>
7 //
8 // (C) Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2006 Kornel Pal
10 // Copyright (C) 2006 Novell (http://www.novell.com)
11 //
12
13 using System;
14 using System.Text;
15 using System.Globalization;
16 using System.Reflection;
17 using System.Threading;
18
19 using NUnit.Framework;
20
21 namespace MonoTests.System
22 {
23
24 [TestFixture]
25 public class StringTest
26 {
27         class NullFormatter : IFormatProvider, ICustomFormatter
28         {
29                 public string Format (string format, object arg, IFormatProvider provider)
30                 {
31                         return null;
32                 }
33
34                 public object GetFormat (Type formatType)
35                 {
36                         return this;
37                 }
38         }
39
40
41         private CultureInfo orgCulture;
42
43         [SetUp]
44         public void SetUp ()
45         {
46                 // save current culture
47                 orgCulture = CultureInfo.CurrentCulture;
48         }
49
50         [TearDown]
51         public void TearDown ()
52         {
53                 // restore original culture
54                 Thread.CurrentThread.CurrentCulture = orgCulture;
55         }
56
57
58 #if !TARGET_JVM
59         [Test] // ctor (Char [])
60         public unsafe void Constructor2 ()
61         {
62                 Assert.AreEqual (String.Empty, new String ((char[]) null), "#1");
63                 Assert.AreEqual (String.Empty, new String (new Char [0]), "#2");
64                 Assert.AreEqual ("A", new String (new Char [1] {'A'}), "#3");
65         }
66 #endif
67
68         [Test] // ctor (Char, Int32)
69         public void Constructor4 ()
70         {
71                 Assert.AreEqual (string.Empty, new String ('A', 0));
72                 Assert.AreEqual (new String ('A', 3), "AAA");
73         }
74
75         [Test] // ctor (Char, Int32)
76         public void Constructor4_Count_Negative ()
77         {
78                 try {
79                         new String ('A', -1);
80                         Assert.Fail ("#1");
81                 } catch (ArgumentOutOfRangeException ex) {
82                         // 'count' must be non-negative
83                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
84                         Assert.IsNull (ex.InnerException, "#3");
85                         Assert.IsNotNull (ex.Message, "#4");
86                         Assert.AreEqual ("count", ex.ParamName, "#5");
87                 }
88         }
89
90         [Test] // ctor (Char [], Int32, Int32)
91         public void Constructor6 ()
92         {
93                 char [] arr = new char [3] { 'A', 'B', 'C' };
94                 Assert.AreEqual ("ABC", new String (arr, 0, arr.Length), "#1");
95                 Assert.AreEqual ("BC", new String (arr, 1, 2), "#2");
96                 Assert.AreEqual (string.Empty, new String (arr, 2, 0), "#3");
97         }
98
99         [Test] // ctor (Char [], Int32, Int32)
100         public void Constructor6_Length_Negative ()
101         {
102                 char [] arr = new char [3] { 'A', 'B', 'C' };
103
104                 try {
105                         new String (arr, 0, -1);
106                         Assert.Fail ("#1");
107                 } catch (ArgumentOutOfRangeException ex) {
108                         // Length cannot be less than zero
109                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
110                         Assert.IsNull (ex.InnerException, "#3");
111                         Assert.IsNotNull (ex.Message, "#4");
112                         Assert.AreEqual ("length", ex.ParamName, "#5");
113                 }
114         }
115
116         [Test] // ctor (Char [], Int32, Int32)
117         public void Constructor6_Length_Overflow ()
118         {
119                 char [] arr = new char [3] { 'A', 'B', 'C' };
120
121                 try {
122                         new String (arr, 1, 3);
123                         Assert.Fail ("#1");
124                 } catch (ArgumentOutOfRangeException ex) {
125                         // Index was out of range. Must be non-negative and
126                         // less than the size of the collection
127                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
128                         Assert.IsNull (ex.InnerException, "#3");
129                         Assert.IsNotNull (ex.Message, "#4");
130                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
131                 }
132         }
133
134         [Test] // ctor (Char [], Int32, Int32)
135         public void Constructor6_StartIndex_Negative ()
136         {
137                 char [] arr = new char [3] { 'A', 'B', 'C' };
138
139                 try {
140                         new String (arr, -1, 0);
141                         Assert.Fail ("#1");
142                 } catch (ArgumentOutOfRangeException ex) {
143                         // StartIndex cannot be less than zero
144                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
145                         Assert.IsNull (ex.InnerException, "#3");
146                         Assert.IsNotNull (ex.Message, "#4");
147                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
148                 }
149         }
150
151         [Test] // ctor (Char [], Int32, Int32)
152         public void Constructor6_Value_Null ()
153         {
154                 try {
155                         new String ((char []) null, 0, 0);
156                         Assert.Fail ("#1");
157                 } catch (ArgumentNullException ex) {
158                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
159                         Assert.IsNull (ex.InnerException, "#3");
160                         Assert.IsNotNull (ex.Message, "#4");
161                         Assert.AreEqual ("value", ex.ParamName, "#5");
162                 }
163         }
164
165 #if !TARGET_JVM
166         [Test]
167         public unsafe void CharPtrConstructor ()
168         {
169                 Assert.AreEqual (String.Empty, new String ((char*) null), "char*");
170                 Assert.AreEqual (String.Empty, new String ((char*) null, 0, 0), "char*,int,int");
171         }
172
173         [Test]
174         public unsafe void TestSbytePtrConstructorASCII ()
175         {
176                 Encoding encoding = Encoding.ASCII;
177                 String s = "ASCII*\0";
178                 byte[] bytes = encoding.GetBytes (s);
179
180                 fixed (byte* bytePtr = bytes)
181                         Assert.AreEqual (s, new String ((sbyte*) bytePtr, 0, bytes.Length, encoding));
182         }
183
184         [Test]
185         public unsafe void TestSbytePtrConstructorDefault ()
186         {
187                 Encoding encoding = Encoding.Default;
188                 byte [] bytes = new byte [256];
189                 
190                 for (int i = 0; i < 255; i++)
191                         bytes [i] = (byte) (i + 1);
192                 bytes [255] = (byte) 0;
193
194                 // Ensure that bytes are valid for Encoding.Default
195                 bytes = encoding.GetBytes (encoding.GetChars (bytes));
196                 String s = encoding.GetString(bytes);
197
198                 // Ensure null terminated array
199                 bytes [bytes.Length - 1] = (byte) 0;
200
201                 fixed (byte* bytePtr = bytes) 
202                 {
203                         Assert.AreEqual (s.Substring (0, s.Length - 1), new String ((sbyte*) bytePtr));
204                         Assert.AreEqual (s, new String ((sbyte*) bytePtr, 0, bytes.Length));
205                         Assert.AreEqual (s, new String ((sbyte*) bytePtr, 0, bytes.Length, null));
206                         Assert.AreEqual (s, new String ((sbyte*) bytePtr, 0, bytes.Length, encoding));
207                 }
208         }
209
210         [Test] // ctor (SByte*)
211         public unsafe void Constructor3_Value_Null ()
212         {
213                 Assert.AreEqual (String.Empty, new String ((sbyte*) null));
214         }
215
216         [Test] // ctor (SByte*)
217         [Ignore ("invalid test")]
218         public unsafe void Constructor3_Value_Invalid ()
219         {
220                 try {
221                         new String ((sbyte*) (-1));
222                         Assert.Fail ("#1");
223                 } catch (ArgumentOutOfRangeException ex) {
224                         // Pointer startIndex and length do not refer to a
225                         // valid string
226                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
227                         Assert.IsNull (ex.InnerException, "#3");
228                         Assert.IsNotNull (ex.Message, "#4");
229                         Assert.AreEqual ("ptr", ex.ParamName, "#5");
230                 }
231         }
232
233         [Test] // ctor (SByte*, Int32, Int32)
234         public unsafe void Constructor7_Length_Negative ()
235         {
236                 try {
237                         new String ((sbyte*) null, 0, -1);
238                         Assert.Fail ("#1");
239                 } catch (ArgumentOutOfRangeException ex) {
240                         // Length cannot be less than zero
241                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
242                         Assert.IsNull (ex.InnerException, "#3");
243                         Assert.IsNotNull (ex.Message, "#4");
244                         Assert.AreEqual ("length", ex.ParamName, "#5");
245                 }
246         }
247
248         [Test] // ctor (SByte*, Int32, Int32)
249         public unsafe void Constructor7_StartIndex_Negative ()
250         {
251                 try {
252                         new String ((sbyte*) null, -1, 0);
253                         Assert.Fail ("#1");
254                 } catch (ArgumentOutOfRangeException ex) {
255                         // StartIndex cannot be less than zero
256                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
257                         Assert.IsNull (ex.InnerException, "#3");
258                         Assert.IsNotNull (ex.Message, "#4");
259                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
260                 }
261         }
262
263         [Test]
264         public unsafe void Constructor7_StartIndex_Overflow ()
265         {
266                 try {
267                         new String ((sbyte*) (-1), 1, 0);
268                         Assert.Fail ("#A1");
269                 } catch (ArgumentOutOfRangeException ex) {
270                         // Pointer startIndex and length do not refer to a
271                         // valid string
272                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
273                         Assert.IsNull (ex.InnerException, "#A3");
274                         Assert.IsNotNull (ex.Message, "#A4");
275                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
276                 }
277
278                 try {
279                         new String ((sbyte*) (-1), 1, 1);
280                         Assert.Fail ("#B1");
281                 } catch (ArgumentOutOfRangeException ex) {
282                         // Pointer startIndex and length do not refer to a
283                         // valid string
284                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
285                         Assert.IsNull (ex.InnerException, "#B3");
286                         Assert.IsNotNull (ex.Message, "#B4");
287                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
288                 }
289         }
290
291         [Test] // ctor (SByte*, Int32, Int32)
292         [Ignore ("invalid test")]
293         public unsafe void Constructor7_Value_Invalid ()
294         {
295                 try {
296                         new String ((sbyte*) (-1), 0, 1);
297                         Assert.Fail ("#1");
298                 } catch (ArgumentOutOfRangeException ex) {
299                         // Pointer startIndex and length do not refer to a
300                         // valid string
301                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
302                         Assert.IsNull (ex.InnerException, "#3");
303                         Assert.IsNotNull (ex.Message, "#4");
304                         Assert.AreEqual ("ptr", ex.ParamName, "#5");
305                 }
306         }
307
308         [Test] // ctor (SByte*, Int32, Int32)
309         public unsafe void Constructor7_Value_Null ()
310         {
311                 try {
312                         new String ((sbyte*) null, 0, 0);
313                         Assert.Fail ("#A1");
314                 } catch (ArgumentNullException ex) {
315                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
316                         Assert.IsNull (ex.InnerException, "#A3");
317                         Assert.IsNotNull (ex.Message, "#A4");
318                         Assert.AreEqual ("value", ex.ParamName, "#A5");
319                 }
320
321                 try {
322                         new String ((sbyte*) null, 0, 1);
323                         Assert.Fail ("#B1");
324                 } catch (ArgumentNullException ex) {
325                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
326                         Assert.IsNull (ex.InnerException, "#B3");
327                         Assert.IsNotNull (ex.Message, "#B4");
328                         Assert.AreEqual ("value", ex.ParamName, "#B5");
329                 }
330
331                 try {
332                         new String ((sbyte*) null, 1, 0);
333                         Assert.Fail ("#C1");
334                 } catch (ArgumentNullException ex) {
335                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
336                         Assert.IsNull (ex.InnerException, "#C3");
337                         Assert.IsNotNull (ex.Message, "#C4");
338                         Assert.AreEqual ("value", ex.ParamName, "#C5");
339                 }
340         }
341
342         [Test] // ctor (SByte*, Int32, Int32, Encoding)
343         public unsafe void Constructor8_Length_Negative ()
344         {
345                 try {
346                         new String ((sbyte*) null, 0, -1, null);
347                         Assert.Fail ("#A1");
348                 } catch (ArgumentOutOfRangeException ex) {
349                         // Length cannot be less than zero
350                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
351                         Assert.IsNull (ex.InnerException, "#A3");
352                         Assert.IsNotNull (ex.Message, "#A4");
353                         Assert.AreEqual ("length", ex.ParamName, "#A5");
354                 }
355
356                 try {
357                         new String ((sbyte*) null, 0, -1, Encoding.Default);
358                         Assert.Fail ("#B1");
359                 } catch (ArgumentOutOfRangeException ex) {
360                         // Non-negative number required
361                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
362                         Assert.IsNull (ex.InnerException, "#B3");
363                         Assert.IsNotNull (ex.Message, "#B4");
364                         Assert.AreEqual ("length", ex.ParamName, "#B5");
365                 }
366         }
367
368         [Test] // ctor (SByte*, Int32, Int32, Encoding)
369         public unsafe void Constructor8_StartIndex_Negative ()
370         {
371                 try {
372                         new String ((sbyte*) null, -1, 0, null);
373                         Assert.Fail ("#A1");
374                 } catch (ArgumentOutOfRangeException ex) {
375                         // StartIndex cannot be less than zero
376                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
377                         Assert.IsNull (ex.InnerException, "#A3");
378                         Assert.IsNotNull (ex.Message, "#A4");
379                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
380                 }
381
382                 try {
383                         new String ((sbyte*) null, -1, 0, Encoding.Default);
384                         Assert.Fail ("#B1");
385                 } catch (ArgumentOutOfRangeException ex) {
386                         // StartIndex cannot be less than zero
387                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
388                         Assert.IsNull (ex.InnerException, "#B3");
389                         Assert.IsNotNull (ex.Message, "#B4");
390                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
391                 }
392         }
393
394         [Test]
395         public unsafe void Constructor8_StartIndex_Overflow ()
396         {
397                 try {
398                         new String ((sbyte*) (-1), 1, 0, null);
399                         Assert.Fail ("#A1");
400                 } catch (ArgumentOutOfRangeException ex) {
401                         // Pointer startIndex and length do not refer to a
402                         // valid string
403                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
404                         Assert.IsNull (ex.InnerException, "#A3");
405                         Assert.IsNotNull (ex.Message, "#A4");
406                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
407                 }
408
409                 try {
410                         new String ((sbyte*) (-1), 1, 1, null);
411                         Assert.Fail ("#B1");
412                 } catch (ArgumentOutOfRangeException ex) {
413                         // Pointer startIndex and length do not refer to a
414                         // valid string
415                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
416                         Assert.IsNull (ex.InnerException, "#B3");
417                         Assert.IsNotNull (ex.Message, "#B4");
418                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
419                 }
420
421                 try {
422                         new String ((sbyte*) (-1), 1, 0, Encoding.Default);
423                         Assert.Fail ("#C1");
424                 } catch (ArgumentOutOfRangeException ex) {
425                         // Pointer startIndex and length do not refer to a
426                         // valid string
427                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
428                         Assert.IsNull (ex.InnerException, "#C3");
429                         Assert.IsNotNull (ex.Message, "#C4");
430                         Assert.AreEqual ("startIndex", ex.ParamName, "#C5");
431                 }
432
433                 try {
434                         new String ((sbyte*) (-1), 1, 1, Encoding.Default);
435                         Assert.Fail ("#D1");
436                 } catch (ArgumentOutOfRangeException ex) {
437                         // Pointer startIndex and length do not refer to a
438                         // valid string
439                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#D2");
440                         Assert.IsNull (ex.InnerException, "#D3");
441                         Assert.IsNotNull (ex.Message, "#D4");
442                         Assert.AreEqual ("startIndex", ex.ParamName, "#D5");
443                 }
444         }
445
446         [Test] // ctor (SByte*, Int32, Int32, Encoding)
447         [Ignore ("invalid test")]
448         public unsafe void Constructor8_Value_Invalid ()
449         {
450                 try {
451                         new String ((sbyte*) (-1), 0, 1, null);
452                         Assert.Fail ("#1");
453                 } catch (ArgumentOutOfRangeException ex) {
454                         // Pointer startIndex and length do not refer to a
455                         // valid string
456                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
457                         Assert.IsNull (ex.InnerException, "#3");
458                         Assert.IsNotNull (ex.Message, "#4");
459                         Assert.AreEqual ("ptr", ex.ParamName, "#5");
460                 }
461         }
462
463         [Test]
464         [Ignore ("Runtime throws NullReferenceException instead of AccessViolationException")]
465         [ExpectedException (typeof (AccessViolationException))]
466         public unsafe void Constructor8_Value_Invalid2 ()
467         {
468                 new String ((sbyte*) (-1), 0, 1, Encoding.Default);
469         }
470
471         [Test] // ctor (SByte*, Int32, Int32, Encoding)
472         public unsafe void Constructor8_Value_Null ()
473         {
474                 try {
475                         new String ((sbyte*) null, 0, 0, null);
476                         Assert.Fail ("#A1");
477                 } catch (ArgumentNullException ex) {
478                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
479                         Assert.IsNull (ex.InnerException, "#A3");
480                         Assert.IsNotNull (ex.Message, "#A4");
481                         Assert.AreEqual ("value", ex.ParamName, "#A5");
482                 }
483
484                 try {
485                         new String ((sbyte*) null, 0, 1, null);
486                         Assert.Fail ("#B1");
487                 } catch (ArgumentNullException ex) {
488                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
489                         Assert.IsNull (ex.InnerException, "#B3");
490                         Assert.IsNotNull (ex.Message, "#B4");
491                         Assert.AreEqual ("value", ex.ParamName, "#B5");
492                 }
493
494                 try {
495                         new String ((sbyte*) null, 1, 0, null);
496                         Assert.Fail ("#C1");
497                 } catch (ArgumentNullException ex) {
498                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
499                         Assert.IsNull (ex.InnerException, "#C3");
500                         Assert.IsNotNull (ex.Message, "#C4");
501                         Assert.AreEqual ("value", ex.ParamName, "#C5");
502                 }
503
504                 Assert.AreEqual (String.Empty, new String ((sbyte*) null, 0, 0, Encoding.Default), "#D");
505
506                 try {
507                         new String ((sbyte*) null, 0, 1, Encoding.Default);
508                         Assert.Fail ("#E1");
509                 } catch (ArgumentOutOfRangeException ex) {
510                         // Pointer startIndex and length do not refer to a
511                         // valid string
512                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#E2");
513                         Assert.IsNull (ex.InnerException, "#E3");
514                         Assert.IsNotNull (ex.Message, "#E4");
515                         //Assert.AreEqual ("value", ex.ParamName, "#E5");
516                 }
517
518                 Assert.AreEqual (String.Empty, new String ((sbyte*) null, 1, 0, Encoding.Default), "#F");
519         }
520 #endif
521         [Test]
522         public void Length ()
523         {
524                 string str = "test string";
525
526                 Assert.AreEqual (11, str.Length, "wrong length");
527         }
528
529         [Test]
530         public void Clone ()
531         {
532                 string s1 = "oRiGiNal";
533                 Assert.AreEqual (s1, s1.Clone (), "#A1");
534                 Assert.AreSame (s1, s1.Clone (), "#A2");
535
536                 string s2 = new DateTime (2000, 6, 3).ToString ();
537                 Assert.AreEqual (s2, s2.Clone (), "#B1");
538                 Assert.AreSame (s2, s2.Clone (), "#B2");
539         }
540
541         [Test] // bug #316666
542         public void CompareNotWorking ()
543         {
544                 Assert.AreEqual (String.Compare ("A", "a"), 1, "A03");
545                 Assert.AreEqual (String.Compare ("a", "A"), -1, "A04");
546         }
547
548         [Test]
549         public void CompareNotWorking2 ()
550         {
551                 string needle = "ab";
552                 string haystack = "abbcbacab";
553                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, 0, 2, false), "basic substring check #9");
554                 for (int i = 1; i <= (haystack.Length - needle.Length); i++) {
555                         if (i != 7) {
556                                 Assert.AreEqual (-1, String.Compare(needle, 0, haystack, i, 2, false), "loop substring check #8/" + i);
557                         }
558                 }
559         }
560
561         [Test]
562         public void Compare ()
563         {
564                 string lesser = "abc";
565                 string medium = "abcd";
566                 string greater = "xyz";
567                 string caps = "ABC";
568
569                 Assert.AreEqual (0, String.Compare (null, null));
570                 Assert.AreEqual (1, String.Compare (lesser, null));
571
572                 Assert.IsTrue (String.Compare (lesser, greater) < 0);
573                 Assert.IsTrue (String.Compare (greater, lesser) > 0);
574                 Assert.IsTrue (String.Compare (lesser, lesser) == 0);
575                 Assert.IsTrue (String.Compare (lesser, medium) < 0);
576
577                 Assert.IsTrue (String.Compare (lesser, caps, true) == 0);
578                 Assert.IsTrue (String.Compare (lesser, caps, false) != 0);
579                 Assert.AreEqual (String.Compare ("a", "b"), -1, "A01");
580                 Assert.AreEqual (String.Compare ("b", "a"), 1, "A02");
581
582
583                 // TODO - test with CultureInfo
584
585                 string needle = "ab";
586                 string haystack = "abbcbacab";
587                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, 0, 2), "basic substring check #1");
588                 Assert.AreEqual (-1, String.Compare(needle, 0, haystack, 0, 3), "basic substring check #2");
589                 Assert.AreEqual (0, String.Compare("ab", 0, "ab", 0, 2), "basic substring check #3");
590                 Assert.AreEqual (0, String.Compare("ab", 0, "ab", 0, 3), "basic substring check #4");
591                 Assert.AreEqual (0, String.Compare("abc", 0, "ab", 0, 2), "basic substring check #5");
592                 Assert.AreEqual (1, String.Compare("abc", 0, "ab", 0, 5), "basic substring check #6");
593                 Assert.AreEqual (-1, String.Compare("ab", 0, "abc", 0, 5), "basic substring check #7");
594
595                 for (int i = 1; i <= (haystack.Length - needle.Length); i++) {
596                         if (i != 7) {
597                                 Assert.IsTrue (String.Compare(needle, 0, haystack, i, 2) != 0, "loop substring check #1/" + i);
598                                 Assert.IsTrue (String.Compare(needle, 0, haystack, i, 3) != 0, "loop substring check #2/" + i);
599                         } else {
600                                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, i, 2), "loop substring check #3/" + i);
601                                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, i, 3), "loop substring check #4/" + i);
602                         }
603                 }
604
605                 needle = "AB";
606                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, 0, 2, true), "basic substring check #8");
607                 for (int i = 1; i <= (haystack.Length - needle.Length); i++) {
608                         if (i != 7) {
609                                 Assert.IsTrue (String.Compare(needle, 0, haystack, i, 2, true) != 0, "loop substring check #5/" + i);
610                                 Assert.IsTrue (String.Compare(needle, 0, haystack, i, 2, false) != 0, "loop substring check #6/" + i);
611                         } else {
612                                 Assert.AreEqual (0, String.Compare(needle, 0, haystack, i, 2, true), "loop substring check #7/" + i);
613                         }
614                 }
615
616                 Assert.AreEqual (0, String.Compare (needle, 0, haystack, 0, 0), "Compare with 0 length");
617
618                 // TODO - extended format call with CultureInfo
619         }
620
621         [Test]
622         public void CompareOrdinal ()
623         {
624                 string lesser = "abc";
625                 string medium = "abcd";
626                 string greater = "xyz";
627
628                 Assert.AreEqual (0, String.CompareOrdinal (null, null));
629                 Assert.AreEqual (1, String.CompareOrdinal (lesser, null));
630
631                 Assert.IsTrue (String.CompareOrdinal (lesser, greater) < 0, "#1");
632                 Assert.IsTrue (String.CompareOrdinal (greater, lesser) > 0, "#2");
633                 Assert.IsTrue (String.CompareOrdinal (lesser, lesser) == 0, "#3");
634                 Assert.IsTrue (String.CompareOrdinal (lesser, medium) < 0, "#4");
635
636                 string needle = "ab";
637                 string haystack = "abbcbacab";
638                 Assert.AreEqual (0, String.CompareOrdinal(needle, 0, haystack, 0, 2), "basic substring check");
639                 Assert.AreEqual (-1, String.CompareOrdinal(needle, 0, haystack, 0, 3), "basic substring miss");
640                 for (int i = 1; i <= (haystack.Length - needle.Length); i++) {
641                         if (i != 7) {
642                                 Assert.IsTrue (String.CompareOrdinal(needle, 0, haystack, i, 2) != 0, "loop substring check " + i);
643                                 Assert.IsTrue (String.CompareOrdinal(needle, 0, haystack, i, 3) != 0, "loop substring check " + i);
644                         } else {
645                                 Assert.AreEqual (0, String.CompareOrdinal(needle, 0, haystack, i, 2), "loop substring check " + i);
646                                 Assert.AreEqual (0, String.CompareOrdinal(needle, 0, haystack, i, 3), "loop substring check " + i);
647                         }
648                 }
649         }
650
651         [Test]
652         public void CompareOrdinalWithOffset ()
653         {
654                 string ab1 = "ab";
655                 string ab2 = "a" + new string ('b', 1);
656                 
657                 Assert.IsTrue (string.CompareOrdinal (ab1, 0, ab1, 1, 1) < 0, "#1");
658                 Assert.IsTrue (string.CompareOrdinal (ab2, 0, ab1, 1, 1) < 0, "#2");
659         }
660
661         [Test]
662         public void CompareOrdinalSubstringWithNull ()
663         {
664                 string lesser = "abc";
665                 string greater = "xyz";
666
667                 Assert.AreEqual (0, string.CompareOrdinal (null, 0, null, 0, 0), "substring both null");
668                 Assert.AreEqual (-1, string.CompareOrdinal (null, 0, greater, 0, 0), "substring strA null");
669                 Assert.AreEqual (-1, string.CompareOrdinal (null, 4, greater, 0, 0), "substring strA null; indexA greater than strA.Length");
670                 Assert.AreEqual (-1, string.CompareOrdinal (null, 0, greater, 4, 0), "substring strA null; indexB greater than strB.Length");
671                 Assert.AreEqual (-1, string.CompareOrdinal (null, -1, greater, -1, -1), "substring strA null; indexA, indexB, length negative");
672                 Assert.AreEqual (1, string.CompareOrdinal (lesser, 0, null, 0, 0), "substring strB null");
673                 Assert.AreEqual (1, string.CompareOrdinal (lesser, 4, null, 0, 0), "substring strB null; indexA greater than strA.Length");
674                 Assert.AreEqual (1, string.CompareOrdinal (lesser, 0, null, 4, 0), "substring strB null; indexB greater than strB.Length");
675                 Assert.AreEqual (1, string.CompareOrdinal (lesser, -1, null, -1, -1), "substring strB null; indexA, indexB, length negative");
676         }
677
678         [Test]
679         public void CompareTo ()
680         {
681                 string lower = "abc";
682                 string greater = "xyz";
683                 string lesser = "abc";
684                 
685                 Assert.IsTrue (lower.CompareTo (greater) < 0);
686                 Assert.IsTrue (lower.CompareTo (lower) == 0);
687                 Assert.IsTrue (greater.CompareTo (lesser) > 0);
688         }
689         
690         class WeirdToString
691         {
692                 public override string ToString ()
693                 {
694                         return null;
695                 }
696         }
697
698         [Test]
699         public void Concat ()
700         {
701                 string string1 = "string1";
702                 string string2 = "string2";
703                 string concat = "string1string2";
704
705                 Assert.IsTrue (String.Concat (string1, string2) == concat);
706                 
707                 Assert.AreEqual (string1, String.Concat (string1, null));
708                 Assert.AreEqual (string1, String.Concat (null, string1));
709                 Assert.AreEqual (string.Empty, String.Concat (null, null));
710                 
711                 WeirdToString wts = new WeirdToString ();
712                 Assert.AreEqual (string1, String.Concat (string1, wts));
713                 Assert.AreEqual (string1, String.Concat (wts, string1));
714                 Assert.AreEqual (string.Empty, String.Concat (wts, wts));
715                 string [] allstr = new string []{ string1, null, string2, concat };
716                 object [] allobj = new object []{ string1, null, string2, concat };
717                 string astr = String.Concat (allstr);
718                 Assert.AreEqual ("string1string2string1string2", astr);
719                 string ostr = String.Concat (allobj);
720                 Assert.AreEqual (astr, ostr);
721         }
722
723         [Test]
724         public void Copy ()
725         {
726                 string s1 = "original";
727                 string s2 = String.Copy(s1);
728                 Assert.AreEqual (s1, s2, "#1");
729                 Assert.IsTrue (!object.ReferenceEquals (s1, s2), "#2");
730         }
731
732         [Test]
733         public void Copy_Str_Null ()
734         {
735                 try {
736                         String.Copy ((string) null);
737                         Assert.Fail ("#1");
738                 } catch (ArgumentNullException ex) {
739                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
740                         Assert.IsNull (ex.InnerException, "#3");
741                         Assert.IsNotNull (ex.Message, "#4");
742                         Assert.AreEqual ("str", ex.ParamName, "#5");
743                 }
744         }
745
746         [Test]
747         public void CopyTo ()
748         {
749                 string s1 = "original";
750                 char[] c1 = new char[s1.Length];
751                 string s2 = new String(c1);
752                 Assert.IsTrue (!s1.Equals(s2), "#1");
753                 for (int i = 0; i < s1.Length; i++) {
754                         s1.CopyTo(i, c1, i, 1);
755                 }
756                 s2 = new String(c1);
757                 Assert.AreEqual (s1, s2, "#2");
758         }
759
760         [Test]
761         public void CopyTo_Count_Negative ()
762         {
763                 char [] dest = new char [4];
764                 try {
765                         "Mono".CopyTo (0, dest, 0, -1);
766                         Assert.Fail ("#1");
767                 } catch (ArgumentOutOfRangeException ex) {
768                         // Count cannot be less than zero
769                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
770                         Assert.IsNull (ex.InnerException, "#3");
771                         Assert.IsNotNull (ex.Message, "#4");
772                         Assert.AreEqual ("count", ex.ParamName, "#5");
773                 }
774         }
775
776         [Test]
777         public void CopyTo_Count_Overflow ()
778         {
779                 char [] dest = new char [4];
780                 try {
781                         "Mono".CopyTo (0, dest, 0, Int32.MaxValue);
782                         Assert.Fail ("#1");
783                 } catch (ArgumentOutOfRangeException ex) {
784                         // Index and count must refer to a location within the
785                         // string
786                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
787                         Assert.IsNull (ex.InnerException, "#3");
788                         Assert.IsNotNull (ex.Message, "#4");
789                         Assert.AreEqual ("sourceIndex", ex.ParamName, "#5");
790                 }
791         }
792
793         [Test]
794         public void CopyTo_Destination_Null ()
795         {
796                 string s = "original";
797
798                 try {
799                         s.CopyTo (0, (char []) null, 0, s.Length);
800                         Assert.Fail ("#1");
801                 } catch (ArgumentNullException ex) {
802                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
803                         Assert.IsNull (ex.InnerException, "#3");
804                         Assert.IsNotNull (ex.Message, "#4");
805                         Assert.AreEqual ("destination", ex.ParamName, "#5");
806                 }
807         }
808
809         [Test]
810         public void CopyTo_DestinationIndex_Negative ()
811         {
812                 char [] dest = new char [4];
813                 try {
814                         "Mono".CopyTo (0, dest, -1, 4);
815                         Assert.Fail ("#1");
816                 } catch (ArgumentOutOfRangeException ex) {
817                         // Index and count must refer to a location within the
818                         // string
819                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
820                         Assert.IsNull (ex.InnerException, "#3");
821                         Assert.IsNotNull (ex.Message, "#4");
822                         Assert.AreEqual ("destinationIndex", ex.ParamName, "#5");
823                 }
824         }
825
826         [Test]
827         public void CopyTo_DestinationIndex_Overflow ()
828         {
829                 char [] dest = new char [4];
830                 try {
831                         "Mono".CopyTo (0, dest, Int32.MaxValue, 4);
832                         Assert.Fail ("#1");
833                 } catch (ArgumentOutOfRangeException ex) {
834                         // Index and count must refer to a location within the
835                         // string
836                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
837                         Assert.IsNull (ex.InnerException, "#3");
838                         Assert.IsNotNull (ex.Message, "#4");
839                         Assert.AreEqual ("destinationIndex", ex.ParamName, "#5");
840                 }
841         }
842
843         [Test]
844         public void CopyTo_SourceIndex_Negative ()
845         {
846                 char [] dest = new char [4];
847                 try {
848                         "Mono".CopyTo (-1, dest, 0, 4);
849                         Assert.Fail ("#1");
850                 } catch (ArgumentOutOfRangeException ex) {
851                         // Index was out of range. Must be non-negative and
852                         // less than the size of the collection
853                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
854                         Assert.IsNull (ex.InnerException, "#3");
855                         Assert.IsNotNull (ex.Message, "#4");
856                         Assert.AreEqual ("sourceIndex", ex.ParamName, "#5");
857                 }
858         }
859
860         [Test]
861         public void CopyTo_SourceIndex_Overflow ()
862         {
863                 char[] dest = new char [4];
864                 try {
865                         "Mono".CopyTo (Int32.MaxValue, dest, 0, 4);
866                         Assert.Fail ("#1");
867                 } catch (ArgumentOutOfRangeException ex) {
868                         // Index and count must refer to a location within the
869                         // string
870                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
871                         Assert.IsNull (ex.InnerException, "#3");
872                         Assert.IsNotNull (ex.Message, "#4");
873                         Assert.AreEqual ("sourceIndex", ex.ParamName, "#5");
874                 }
875         }
876
877         [Test] // EndsWith (String)
878         public void EndsWith1 ()
879         {
880                 string s;
881
882                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
883                 s = "AbC";
884
885                 Assert.IsTrue (s.EndsWith ("bC"), "#A1");
886                 Assert.IsTrue (!s.EndsWith ("bc"), "#A1");
887                 Assert.IsTrue (!s.EndsWith ("dc"), "#A2");
888                 Assert.IsTrue (!s.EndsWith ("LAbC"), "#A3");
889                 Assert.IsTrue (s.EndsWith (string.Empty), "#A4");
890                 Assert.IsTrue (!s.EndsWith ("Ab"), "#A5");
891                 Assert.IsTrue (!s.EndsWith ("Abc"), "#A6");
892                 Assert.IsTrue (s.EndsWith ("AbC"), "#A7");
893
894                 s = "Tai";
895
896                 Assert.IsTrue (s.EndsWith ("ai"), "#B1");
897                 Assert.IsTrue (!s.EndsWith ("AI"), "#B2");
898                 Assert.IsTrue (!s.EndsWith ("LTai"), "#B3");
899                 Assert.IsTrue (s.EndsWith (string.Empty), "#B4");
900                 Assert.IsTrue (!s.EndsWith ("Ta"), "#B5");
901                 Assert.IsTrue (!s.EndsWith ("tai"), "#B6");
902                 Assert.IsTrue (s.EndsWith ("Tai"), "#B7");
903
904                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
905
906                 Assert.IsTrue (s.EndsWith ("ai"), "#C1");
907                 Assert.IsTrue (!s.EndsWith ("AI"), "#C2");
908                 Assert.IsTrue (!s.EndsWith ("LTai"), "#C3");
909                 Assert.IsTrue (s.EndsWith (string.Empty), "#C4");
910                 Assert.IsTrue (!s.EndsWith ("Ta"), "#C5");
911                 Assert.IsTrue (!s.EndsWith ("tai"), "#C6");
912                 Assert.IsTrue (s.EndsWith ("Tai"), "#C7");
913         }
914
915         [Test] // EndsWith (String)
916         public void EndsWith1_Value_Null ()
917         {
918                 try {
919                         "ABC".EndsWith ((string) null);
920                         Assert.Fail ("#1");
921                 } catch (ArgumentNullException ex) {
922                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
923                         Assert.IsNull (ex.InnerException, "#3");
924                         Assert.IsNotNull (ex.Message, "#4");
925                         Assert.AreEqual ("value", ex.ParamName, "#5");
926                 }
927         }
928
929         [Test] // EndsWith (String, StringComparison)
930         public void EndsWith2_ComparisonType_Invalid ()
931         {
932                 try {
933                         "ABC".EndsWith ("C", (StringComparison) 80);
934                         Assert.Fail ("#1");
935                 } catch (ArgumentException ex) {
936                         // The string comparison type passed in is currently
937                         // not supported
938                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
939                         Assert.IsNull (ex.InnerException, "#3");
940                         Assert.IsNotNull (ex.Message, "#4");
941                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
942                 }
943         }
944
945         [Test] // EndsWith (String, StringComparison)
946         public void EndsWith2_Value_Null ()
947         {
948                 try {
949                         "ABC".EndsWith ((string) null, StringComparison.CurrentCulture);
950                         Assert.Fail ("#1");
951                 } catch (ArgumentNullException ex) {
952                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
953                         Assert.IsNull (ex.InnerException, "#3");
954                         Assert.IsNotNull (ex.Message, "#4");
955                         Assert.AreEqual ("value", ex.ParamName, "#5");
956                 }
957         }
958
959         [Test] // EndsWith (String, Boolean, CultureInfo)
960         public void EndsWith3 ()
961         {
962                 string s;
963                 bool ignorecase;
964                 CultureInfo culture;
965
966                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
967                 s = "AbC";
968                 culture = null;
969
970                 ignorecase = false;
971                 Assert.IsTrue (!s.EndsWith ("bc", ignorecase, culture), "#A1");
972                 Assert.IsTrue (!s.EndsWith ("dc", ignorecase, culture), "#A2");
973                 Assert.IsTrue (!s.EndsWith ("LAbC", ignorecase, culture), "#A3");
974                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#A4");
975                 Assert.IsTrue (!s.EndsWith ("Ab", ignorecase, culture), "#A5");
976                 Assert.IsTrue (!s.EndsWith ("Abc", ignorecase, culture), "#A6");
977                 Assert.IsTrue (s.EndsWith ("AbC", ignorecase, culture), "#A7");
978
979                 ignorecase = true;
980                 Assert.IsTrue (s.EndsWith ("bc", ignorecase, culture), "#B1");
981                 Assert.IsTrue (!s.EndsWith ("dc", ignorecase, culture), "#B2");
982                 Assert.IsTrue (!s.EndsWith ("LAbC", ignorecase, culture), "#B3");
983                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#B4");
984                 Assert.IsTrue (!s.EndsWith ("Ab", ignorecase, culture), "#B5");
985                 Assert.IsTrue (s.EndsWith ("Abc", ignorecase, culture), "#B6");
986                 Assert.IsTrue (s.EndsWith ("AbC", ignorecase, culture), "#B7");
987
988                 s = "Tai";
989                 culture = null;
990
991                 ignorecase = false;
992                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#C1");
993                 Assert.IsTrue (!s.EndsWith ("AI", ignorecase, culture), "#C2");
994                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#C3");
995                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#C4");
996                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#C5");
997                 Assert.IsTrue (!s.EndsWith ("tai", ignorecase, culture), "#C6");
998                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#C7");
999
1000                 ignorecase = true;
1001                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#D1");
1002                 Assert.IsTrue (!s.EndsWith ("AI", ignorecase, culture), "#D2");
1003                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#D3");
1004                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#D4");
1005                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#D5");
1006                 Assert.IsTrue (s.EndsWith ("tai", ignorecase, culture), "#D6");
1007                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#D7");
1008
1009                 s = "Tai";
1010                 culture = new CultureInfo ("en-US");
1011
1012                 ignorecase = false;
1013                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#E1");
1014                 Assert.IsTrue (!s.EndsWith ("AI", ignorecase, culture), "#E2");
1015                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#E3");
1016                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#E4");
1017                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#E5");
1018                 Assert.IsTrue (!s.EndsWith ("tai", ignorecase, culture), "#E6");
1019                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#E7");
1020
1021                 ignorecase = true;
1022                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#F1");
1023                 Assert.IsTrue (s.EndsWith ("AI", ignorecase, culture), "#F2");
1024                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#F3");
1025                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#F4");
1026                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#F5");
1027                 Assert.IsTrue (s.EndsWith ("tai", ignorecase, culture), "#F6");
1028                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#F7");
1029
1030                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
1031                 culture = null;
1032
1033                 ignorecase = false;
1034                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#G1");
1035                 Assert.IsTrue (!s.EndsWith ("AI", ignorecase, culture), "#G2");
1036                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#G3");
1037                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#G4");
1038                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#G5");
1039                 Assert.IsTrue (!s.EndsWith ("tai", ignorecase, culture), "#G6");
1040                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#G7");
1041
1042                 ignorecase = true;
1043                 Assert.IsTrue (s.EndsWith ("ai", ignorecase, culture), "#H1");
1044                 Assert.IsTrue (s.EndsWith ("AI", ignorecase, culture), "#H2");
1045                 Assert.IsTrue (!s.EndsWith ("LTai", ignorecase, culture), "#H3");
1046                 Assert.IsTrue (s.EndsWith (string.Empty, ignorecase, culture), "#H4");
1047                 Assert.IsTrue (!s.EndsWith ("Ta", ignorecase, culture), "#H5");
1048                 Assert.IsTrue (s.EndsWith ("tai", ignorecase, culture), "#H6");
1049                 Assert.IsTrue (s.EndsWith ("Tai", ignorecase, culture), "#H7");
1050         }
1051
1052         [Test] // EndsWith (String, Boolean, CultureInfo)
1053         public void EndsWith3_Value_Null ()
1054         {
1055                 try {
1056                         "ABC".EndsWith ((string) null, true, null);
1057                         Assert.Fail ("#1");
1058                 } catch (ArgumentNullException ex) {
1059                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1060                         Assert.IsNull (ex.InnerException, "#3");
1061                         Assert.IsNotNull (ex.Message, "#4");
1062                         Assert.AreEqual ("value", ex.ParamName, "#5");
1063                 }
1064         }
1065
1066         [Test]
1067         public void TestEquals ()
1068         {
1069                 string s1 = "original";
1070                 string yes = "original";
1071                 object y = yes;
1072                 string no = "copy";
1073                 string s1s1 = s1 + s1;
1074
1075                 Assert.IsTrue (!s1.Equals (null), "No match for null");
1076                 Assert.IsTrue (s1.Equals (y), "Should match object");
1077                 Assert.IsTrue (s1.Equals (yes), "Should match");
1078                 Assert.IsTrue (!s1.Equals (no), "Shouldn't match");
1079
1080                 Assert.IsTrue (String.Equals (null, null), "Static nulls should match");
1081                 Assert.IsTrue (String.Equals (s1, yes), "Should match");
1082                 Assert.IsTrue (!String.Equals (s1, no), "Shouldn't match");
1083
1084                 Assert.AreEqual (false, s1s1.Equals (y), "Equals (object)");
1085         }
1086
1087         [Test]
1088         public void TestFormat ()
1089         {
1090                 Assert.AreEqual (string.Empty, String.Format (string.Empty, 0), "Empty format string.");
1091                 Assert.AreEqual ("100", String.Format ("{0}", 100), "Single argument.");
1092                 Assert.AreEqual ("X   37X", String.Format ("X{0,5}X", 37), "Single argument, right justified.");
1093                 Assert.AreEqual ("X37   X", String.Format ("X{0,-5}X", 37), "Single argument, left justified.");
1094                 Assert.AreEqual ("  7d", String.Format ("{0, 4:x}", 125), "Whitespace in specifier");
1095                 Assert.AreEqual ("The 3 wise men.", String.Format ("The {0} wise {1}.", 3, "men"), "Two arguments.");
1096                 Assert.AreEqual ("do re me fa so.", String.Format ("{0} re {1} fa {2}.", "do", "me", "so"), "Three arguments.");
1097                 Assert.AreEqual ("###00c0ffee#", String.Format ("###{0:x8}#", 0xc0ffee), "Formatted argument.");
1098                 Assert.AreEqual ("#  033#", String.Format ("#{0,5:x3}#", 0x33), "Formatted argument, right justified.");
1099                 Assert.AreEqual ("#033  #", String.Format ("#{0,-5:x3}#", 0x33), "Formatted argument, left justified.");
1100                 Assert.AreEqual ("typedef struct _MonoObject { ... } MonoObject;", String.Format ("typedef struct _{0} {{ ... }} MonoObject;", "MonoObject"), "Escaped bracket");
1101                 Assert.AreEqual ("Could not find file \"a/b\"", String.Format ("Could not find file \"{0}\"", "a/b"), "With Slash");
1102                 Assert.AreEqual ("Could not find file \"a\\b\"", String.Format ("Could not find file \"{0}\"", "a\\b"), "With BackSlash");
1103         }
1104
1105         [Test] // Format (String, Object)
1106         public void Format1_Format_Null ()
1107         {
1108                 try {
1109                         String.Format (null, 1);
1110                         Assert.Fail ("#1");
1111                 } catch (ArgumentNullException ex) {
1112                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1113                         Assert.IsNull (ex.InnerException, "#3");
1114                         Assert.IsNotNull (ex.Message, "#4");
1115                         Assert.AreEqual ("format", ex.ParamName, "#5");
1116                 }
1117         }
1118
1119         [Test] // Format (String, Object [])
1120         public void Format2_Format_Null ()
1121         {
1122                 try {
1123                         String.Format (null, new object [] { 2 });
1124                         Assert.Fail ("#1");
1125                 } catch (ArgumentNullException ex) {
1126                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1127                         Assert.IsNull (ex.InnerException, "#3");
1128                         Assert.IsNotNull (ex.Message, "#4");
1129                         Assert.AreEqual ("format", ex.ParamName, "#5");
1130                 }
1131         }
1132
1133         [Test] // Format (String, Object [])
1134         public void Format2_Args_Null ()
1135         {
1136                 try {
1137                         String.Format ("text", (object []) null);
1138                         Assert.Fail ("#1");
1139                 } catch (ArgumentNullException ex) {
1140                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1141                         Assert.IsNull (ex.InnerException, "#3");
1142                         Assert.IsNotNull (ex.Message, "#4");
1143                         Assert.AreEqual ("args", ex.ParamName, "#5");
1144                 }
1145         }
1146
1147         [Test] // Format (IFormatProvider, String, Object [])
1148         public void Format3_Format_Null ()
1149         {
1150                 try {
1151                         String.Format (CultureInfo.InvariantCulture, null,
1152                                 new object [] { 3 });
1153                         Assert.Fail ("#1");
1154                 } catch (ArgumentNullException ex) {
1155                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1156                         Assert.IsNull (ex.InnerException, "#3");
1157                         Assert.IsNotNull (ex.Message, "#4");
1158                         Assert.AreEqual ("format", ex.ParamName, "#5");
1159                 }
1160         }
1161
1162         [Test] // Format (IFormatProvider, String, Object [])
1163         public void Format3_Args_Null ()
1164         {
1165                 try {
1166                         String.Format (CultureInfo.InvariantCulture, "text",
1167                                 (object []) null);
1168                         Assert.Fail ("#1");
1169                 } catch (ArgumentNullException ex) {
1170                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1171                         Assert.IsNull (ex.InnerException, "#3");
1172                         Assert.IsNotNull (ex.Message, "#4");
1173                         Assert.AreEqual ("args", ex.ParamName, "#5");
1174                 }
1175         }
1176
1177         [Test] // Format (String, Object, Object)
1178         public void Format4_Format_Null ()
1179         {
1180                 try {
1181                         String.Format (null, 4, 5);
1182                         Assert.Fail ("#1");
1183                 } catch (ArgumentNullException ex) {
1184                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1185                         Assert.IsNull (ex.InnerException, "#3");
1186                         Assert.IsNotNull (ex.Message, "#4");
1187                         Assert.AreEqual ("format", ex.ParamName, "#5");
1188                 }
1189         }
1190
1191         [Test] // Format (String, Object, Object, Object)
1192         public void Format5_Format_Null ()
1193         {
1194                 try {
1195                         String.Format (null, 4, 5, 6);
1196                         Assert.Fail ("#1");
1197                 } catch (ArgumentNullException ex) {
1198                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1199                         Assert.IsNull (ex.InnerException, "#3");
1200                         Assert.IsNotNull (ex.Message, "#4");
1201                         Assert.AreEqual ("format", ex.ParamName, "#5");
1202                 }
1203         }
1204
1205         [Test]
1206         public void Format ()
1207         {
1208                 var s = String.Format (new NullFormatter (), "{0:}", "test");
1209                 Assert.AreEqual ("test", s);
1210         }
1211
1212         [Test]
1213         public void TestGetEnumerator ()
1214         {
1215                 string s1 = "original";
1216                 char[] c1 = new char[s1.Length];
1217                 string s2 = new String(c1);
1218                 Assert.IsTrue (!s1.Equals(s2), "pre-enumerated string should not match");
1219                 CharEnumerator en = s1.GetEnumerator();
1220                 Assert.IsNotNull (en, "null enumerator");
1221                 
1222                 for (int i = 0; i < s1.Length; i++) {
1223                         en.MoveNext();
1224                         c1[i] = en.Current;
1225                 }
1226                 s2 = new String(c1);
1227                 Assert.AreEqual (s1, s2, "enumerated string should match");
1228         }
1229
1230         [Test]
1231         public void TestGetHashCode ()
1232         {
1233                 string s1 = "original";
1234                 // TODO - weak test, currently.  Just verifies determinicity.
1235                 Assert.AreEqual (s1.GetHashCode(), s1.GetHashCode(), "same string, same hash code");
1236         }
1237
1238         [Test]
1239         public void TestGetType ()
1240         {
1241                 string s1 = "original";
1242                 Assert.AreEqual ("System.String", s1.GetType().ToString(), "String type");
1243         }
1244
1245         [Test]
1246         public void TestGetTypeCode ()
1247         {
1248                 string s1 = "original";
1249                 Assert.IsTrue (s1.GetTypeCode().Equals(TypeCode.String));
1250         }
1251
1252         [Test]
1253         public void IndexOf ()
1254         {
1255                 string s1 = "original";
1256
1257                 try {
1258                         s1.IndexOf ('q', s1.Length + 1);
1259                         Assert.Fail ("#A1");
1260                 } catch (ArgumentOutOfRangeException ex) {
1261                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
1262                         Assert.IsNull (ex.InnerException, "#A3");
1263                         Assert.IsNotNull (ex.Message, "#A4");
1264                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
1265                 }
1266
1267                 try {
1268                         s1.IndexOf ('q', s1.Length + 1, 1);
1269                         Assert.Fail ("#B1");
1270                 } catch (ArgumentOutOfRangeException ex) {
1271                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
1272                         Assert.IsNull (ex.InnerException, "#B3");
1273                         Assert.IsNotNull (ex.Message, "#B4");
1274                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
1275                 }
1276
1277                 try {
1278                         s1.IndexOf ("huh", s1.Length + 1);
1279                         Assert.Fail ("#C1");
1280                 } catch (ArgumentOutOfRangeException ex) {
1281                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
1282                         Assert.IsNull (ex.InnerException, "#C3");
1283                         Assert.IsNotNull (ex.Message, "#C4");
1284                         Assert.AreEqual ("startIndex", ex.ParamName, "#C5");
1285                 }
1286
1287                 Assert.AreEqual (1, s1.IndexOf('r'), "basic char index");
1288                 Assert.AreEqual (2, s1.IndexOf('i'), "basic char index 2");
1289                 Assert.AreEqual (-1, s1.IndexOf('q'), "basic char index - no");
1290                 
1291                 Assert.AreEqual (1, s1.IndexOf("rig"), "basic string index");
1292                 Assert.AreEqual (2, s1.IndexOf("i"), "basic string index 2");
1293                 Assert.AreEqual (0, string.Empty.IndexOf(string.Empty), "basic string index 3");
1294                 Assert.AreEqual (0, "ABC".IndexOf(string.Empty), "basic string index 4");
1295                 Assert.AreEqual (-1, s1.IndexOf("rag"), "basic string index - no");
1296
1297                 Assert.AreEqual (1, s1.IndexOf('r', 1), "stepped char index");
1298                 Assert.AreEqual (2, s1.IndexOf('i', 1), "stepped char index 2");
1299                 Assert.AreEqual (4, s1.IndexOf('i', 3), "stepped char index 3");
1300                 Assert.AreEqual (-1, s1.IndexOf('i', 5), "stepped char index 4");
1301                 Assert.AreEqual (-1, s1.IndexOf('l', s1.Length), "stepped char index 5");
1302
1303                 Assert.AreEqual (1, s1.IndexOf('r', 1, 1), "stepped limited char index");
1304                 Assert.AreEqual (-1, s1.IndexOf('r', 0, 1), "stepped limited char index");
1305                 Assert.AreEqual (2, s1.IndexOf('i', 1, 3), "stepped limited char index");
1306                 Assert.AreEqual (4, s1.IndexOf('i', 3, 3), "stepped limited char index");
1307                 Assert.AreEqual (-1, s1.IndexOf('i', 5, 3), "stepped limited char index");
1308
1309                 s1 = "original original";
1310                 Assert.AreEqual (0, s1.IndexOf("original", 0), "stepped string index 1");
1311                 Assert.AreEqual (9, s1.IndexOf("original", 1), "stepped string index 2");
1312                 Assert.AreEqual (-1, s1.IndexOf("original", 10), "stepped string index 3");
1313                 Assert.AreEqual (3, s1.IndexOf(string.Empty, 3), "stepped string index 4");
1314                 Assert.AreEqual (1, s1.IndexOf("rig", 0, 5), "stepped limited string index 1");
1315                 Assert.AreEqual (-1, s1.IndexOf("rig", 0, 3), "stepped limited string index 2");
1316                 Assert.AreEqual (10, s1.IndexOf("rig", 2, 15), "stepped limited string index 3");
1317                 Assert.AreEqual (-1, s1.IndexOf("rig", 2, 3), "stepped limited string index 4");
1318                 Assert.AreEqual (2, s1.IndexOf(string.Empty, 2, 3), "stepped limited string index 5");
1319                 
1320                 string s2 = "QBitArray::bitarr_data"; 
1321                 Assert.AreEqual (9, s2.IndexOf ("::"), "bug #62160");
1322         }
1323
1324         [Test] // IndexOf (String)
1325         public void IndexOf2_Value_Null ()
1326         {
1327                 try {
1328                         "Mono".IndexOf ((string) null);
1329                         Assert.Fail ("#1");
1330                 } catch (ArgumentNullException ex) {
1331                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1332                         Assert.IsNull (ex.InnerException, "#3");
1333                         Assert.IsNotNull (ex.Message, "#4");
1334                         Assert.AreEqual ("value", ex.ParamName, "#5");
1335                 }
1336         }
1337
1338         [Test] // IndexOf (Char, Int32)
1339         public void IndexOf3 ()
1340         {
1341                 string s = "testing123456";
1342
1343                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
1344
1345                 Assert.AreEqual (-1, s.IndexOf ('a', s.Length), "#A1");
1346                 Assert.AreEqual (-1, s.IndexOf ('6', s.Length), "#A2");
1347                 Assert.AreEqual (-1, s.IndexOf ('t', s.Length), "#A3");
1348                 Assert.AreEqual (-1, s.IndexOf ('T', s.Length), "#A4");
1349                 Assert.AreEqual (-1, s.IndexOf ('i', s.Length), "#A5");
1350                 Assert.AreEqual (-1, s.IndexOf ('I', s.Length), "#A6");
1351                 Assert.AreEqual (-1, s.IndexOf ('q', s.Length), "#A7");
1352                 Assert.AreEqual (-1, s.IndexOf ('3', s.Length), "#A8");
1353
1354                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
1355
1356                 Assert.AreEqual (-1, s.IndexOf ('a', s.Length), "#B1");
1357                 Assert.AreEqual (-1, s.IndexOf ('6', s.Length), "#B2");
1358                 Assert.AreEqual (-1, s.IndexOf ('t', s.Length), "#B3");
1359                 Assert.AreEqual (-1, s.IndexOf ('T', s.Length), "#B4");
1360                 Assert.AreEqual (-1, s.IndexOf ('i', s.Length), "#B5");
1361                 Assert.AreEqual (-1, s.IndexOf ('I', s.Length), "#B6");
1362                 Assert.AreEqual (-1, s.IndexOf ('q', s.Length), "#B7");
1363                 Assert.AreEqual (-1, s.IndexOf ('3', s.Length), "#B8");
1364         }
1365
1366         [Test] // IndexOf (String, Int32)
1367         public void IndexOf4 ()
1368         {
1369                 string s = "testing123456";
1370
1371                 Assert.AreEqual (-1, s.IndexOf ("IN", 3), "#1");
1372                 Assert.AreEqual (4, s.IndexOf ("in", 3), "#2");
1373                 Assert.AreEqual (-1, s.IndexOf ("in", 5), "#3");
1374                 Assert.AreEqual (7, s.IndexOf ("1", 5), "#4");
1375                 Assert.AreEqual (12, s.IndexOf ("6", 12), "#5");
1376                 Assert.AreEqual (0, s.IndexOf ("testing123456", 0), "#6");
1377                 Assert.AreEqual (-1, s.IndexOf ("testing123456", 1), "#7");
1378                 Assert.AreEqual (5, s.IndexOf (string.Empty, 5), "#8");
1379                 Assert.AreEqual (0, s.IndexOf (string.Empty, 0), "#9");
1380         }
1381
1382         [Test] // IndexOf (String, Int32)
1383         public void IndexOf4_Value_Null ()
1384         {
1385                 try {
1386                         "Mono".IndexOf ((string) null, 1);
1387                         Assert.Fail ("#1");
1388                 } catch (ArgumentNullException ex) {
1389                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1390                         Assert.IsNull (ex.InnerException, "#3");
1391                         Assert.IsNotNull (ex.Message, "#4");
1392                         Assert.AreEqual ("value", ex.ParamName, "#5");
1393                 }
1394         }
1395
1396         [Test] // IndexOf (String, StringComparison)
1397         public void IndexOf5 ()
1398         {
1399                 string s = "testing123456";
1400                 StringComparison comparison_type;
1401
1402                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
1403
1404                 comparison_type = StringComparison.CurrentCulture;
1405                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#A1");
1406                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#A2");
1407                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#A3");
1408                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#A4");
1409                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#A5");
1410                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#A6");
1411                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#A7");
1412                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#A8");
1413                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#A9");
1414
1415                 comparison_type = StringComparison.CurrentCultureIgnoreCase;
1416                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#B1");
1417                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#B2");
1418                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#B3");
1419                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#B4");
1420                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#B5");
1421                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#B6");
1422                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#B7");
1423                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#B8");
1424                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#B9");
1425
1426                 comparison_type = StringComparison.InvariantCulture;
1427                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#C1");
1428                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#C2");
1429                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#C3");
1430                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#C4");
1431                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#C5");
1432                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#C6");
1433                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#C7");
1434                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#C8");
1435                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#C9");
1436
1437                 comparison_type = StringComparison.InvariantCultureIgnoreCase;
1438                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#D1");
1439                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#D2");
1440                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#D3");
1441                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#D4");
1442                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#D5");
1443                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#D6");
1444                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#D7");
1445                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#D8");
1446                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#D9");
1447
1448                 comparison_type = StringComparison.Ordinal;
1449                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#E1");
1450                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#E2");
1451                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#E3");
1452                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#E4");
1453                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#E5");
1454                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#E6");
1455                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#E7");
1456                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#E8");
1457                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#E9");
1458
1459                 comparison_type = StringComparison.OrdinalIgnoreCase;
1460                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#F1");
1461                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#F2");
1462                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#F3");
1463                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#F4");
1464                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#F5");
1465                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#F6");
1466                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#F7");
1467                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#F8");
1468                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#F9");
1469
1470                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
1471
1472                 comparison_type = StringComparison.CurrentCulture;
1473                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#G1");
1474                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#G2");
1475                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#G3");
1476                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#G4");
1477                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#G5");
1478                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#G6");
1479                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#G7");
1480                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#G8");
1481                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#G9");
1482
1483                 comparison_type = StringComparison.CurrentCultureIgnoreCase;
1484                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#H1");
1485                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#H2");
1486                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#H3");
1487                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#H4");
1488                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#H5");
1489                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#H6");
1490                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#H7");
1491                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#H8");
1492                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#H9");
1493
1494                 comparison_type = StringComparison.InvariantCulture;
1495                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#I1");
1496                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#I2");
1497                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#I3");
1498                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#I4");
1499                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#I5");
1500                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#I6");
1501                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#I7");
1502                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#I8");
1503                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#I9");
1504
1505                 comparison_type = StringComparison.InvariantCultureIgnoreCase;
1506                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#J1");
1507                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#J2");
1508                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#J3");
1509                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#J4");
1510                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#J5");
1511                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#J6");
1512                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#J7");
1513                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#J8");
1514                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#J9");
1515
1516                 comparison_type = StringComparison.Ordinal;
1517                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#K1");
1518                 Assert.AreEqual (-1, s.IndexOf ("NG", comparison_type), "#K2");
1519                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#K3");
1520                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#K4");
1521                 Assert.AreEqual (-1, s.IndexOf ("T", comparison_type), "#K5");
1522                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#K6");
1523                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#K7");
1524                 Assert.AreEqual (-1, s.IndexOf ("TIN", comparison_type), "#K8");
1525                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#K9");
1526
1527                 comparison_type = StringComparison.OrdinalIgnoreCase;
1528                 Assert.AreEqual (7, s.IndexOf ("123", comparison_type), "#L1");
1529                 Assert.AreEqual (5, s.IndexOf ("NG", comparison_type), "#L2");
1530                 Assert.AreEqual (-1, s.IndexOf ("nga", comparison_type), "#L3");
1531                 Assert.AreEqual (0, s.IndexOf ("t", comparison_type), "#L4");
1532                 Assert.AreEqual (0, s.IndexOf ("T", comparison_type), "#L5");
1533                 Assert.AreEqual (12, s.IndexOf ("6", comparison_type), "#L6");
1534                 Assert.AreEqual (3, s.IndexOf ("tin", comparison_type), "#L7");
1535                 Assert.AreEqual (3, s.IndexOf ("TIN", comparison_type), "#L8");
1536                 Assert.AreEqual (0, s.IndexOf (string.Empty, comparison_type), "#L9");
1537
1538                 Assert.AreEqual (0, string.Empty.IndexOf (string.Empty, comparison_type), "#M");
1539         }
1540
1541         [Test] // IndexOf (String, StringComparison)
1542         public void IndexOf5_ComparisonType_Invalid ()
1543         {
1544                 try {
1545                         "Mono".IndexOf (string.Empty, (StringComparison) Int32.MinValue);
1546                         Assert.Fail ("#1");
1547                 } catch (ArgumentException ex) {
1548                         // The string comparison type passed in is currently
1549                         // not supported
1550                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1551                         Assert.IsNull (ex.InnerException, "#3");
1552                         Assert.IsNotNull (ex.Message, "#4");
1553                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
1554                 }
1555         }
1556
1557         [Test] // IndexOf (String, StringComparison)
1558         public void IndexOf5_Value_Null ()
1559         {
1560                 try {
1561                         "Mono".IndexOf ((string) null, StringComparison.Ordinal);
1562                         Assert.Fail ("#1");
1563                 } catch (ArgumentNullException ex) {
1564                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1565                         Assert.IsNull (ex.InnerException, "#3");
1566                         Assert.IsNotNull (ex.Message, "#4");
1567                         Assert.AreEqual ("value", ex.ParamName, "#5");
1568                 }
1569         }
1570
1571         [Test]
1572         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1573         public void IndexOfStringComparisonOrdinalRangeException1 ()
1574         {
1575                 "Mono".IndexOf ("no", 5, StringComparison.Ordinal);
1576         }
1577
1578         [Test]
1579         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1580         public void IndexOfStringComparisonOrdinalRangeException2 ()
1581         {
1582                 "Mono".IndexOf ("no", 1, 5, StringComparison.Ordinal);
1583         }
1584
1585         [Test]
1586         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1587         public void IndexOfStringComparisonOrdinalIgnoreCaseRangeException1 ()
1588         {
1589                 "Mono".IndexOf ("no", 5, StringComparison.OrdinalIgnoreCase);
1590         }
1591
1592         [Test]
1593         [ExpectedException (typeof (ArgumentOutOfRangeException))]
1594         public void IndexOfStringComparisonOrdinalIgnoreCaseRangeException2 ()
1595         {
1596                 "Mono".IndexOf ("no", 1, 5, StringComparison.OrdinalIgnoreCase);
1597         }
1598
1599         [Test]
1600         public void IndexOfStringComparisonCurrentCulture_Empty ()
1601         {
1602                 Assert.AreEqual (1, "Mono".IndexOf ("", 1, StringComparison.CurrentCultureIgnoreCase));
1603         }
1604
1605         [Test]
1606         public void IndexOfStringComparison ()
1607         {
1608                 string text = "testing123456";
1609                 string text2 = "123";
1610                 string text3 = "NG";
1611                 string text4 = "t";
1612                 Assert.AreEqual (7, text.IndexOf (text2, StringComparison.Ordinal), "#1-1");
1613                 Assert.AreEqual (5, text.IndexOf (text3, StringComparison.OrdinalIgnoreCase), "#2-1");
1614
1615                 Assert.AreEqual (7, text.IndexOf (text2, 0, StringComparison.Ordinal), "#1-2");
1616                 Assert.AreEqual (5, text.IndexOf (text3, 0, StringComparison.OrdinalIgnoreCase), "#2-2");
1617
1618                 Assert.AreEqual (7, text.IndexOf (text2, 1, StringComparison.Ordinal), "#1-3");
1619                 Assert.AreEqual (5, text.IndexOf (text3, 1, StringComparison.OrdinalIgnoreCase), "#2-3");
1620
1621                 Assert.AreEqual (7, text.IndexOf (text2, 6, StringComparison.Ordinal), "#1-4");
1622                 Assert.AreEqual (-1, text.IndexOf (text3, 6, StringComparison.OrdinalIgnoreCase), "#2-4");
1623
1624                 Assert.AreEqual (7, text.IndexOf (text2, 7, 3, StringComparison.Ordinal), "#1-5");
1625                 Assert.AreEqual (-1, text.IndexOf (text3, 7, 3, StringComparison.OrdinalIgnoreCase), "#2-5");
1626
1627                 Assert.AreEqual (-1, text.IndexOf (text2, 6, 0, StringComparison.Ordinal), "#1-6");
1628                 Assert.AreEqual (-1, text.IndexOf (text3, 5, 0, StringComparison.OrdinalIgnoreCase), "#2-6");
1629
1630                 Assert.AreEqual (-1, text.IndexOf (text2, 7, 1, StringComparison.Ordinal), "#1-7");
1631                 Assert.AreEqual (-1, text.IndexOf (text3, 5, 1, StringComparison.OrdinalIgnoreCase), "#2-7");
1632
1633                 Assert.AreEqual (0, text.IndexOf (text4, 0, StringComparison.Ordinal), "#3-1");
1634                 Assert.AreEqual (0, text.IndexOf (text4, 0, StringComparison.OrdinalIgnoreCase), "#3-2");
1635
1636                 Assert.AreEqual (-1, text.IndexOf (text4, 13, StringComparison.Ordinal), "#4-1");
1637                 Assert.AreEqual (-1, text.IndexOf (text4, 13, StringComparison.OrdinalIgnoreCase), "#4-2");
1638
1639                 Assert.AreEqual (-1, text.IndexOf (text4, 13, 0, StringComparison.Ordinal), "#4-1");
1640                 Assert.AreEqual (-1, text.IndexOf (text4, 13, 0, StringComparison.OrdinalIgnoreCase), "#4-2");
1641
1642                 Assert.AreEqual (12, text.IndexOf ("6", 12, 1, StringComparison.Ordinal), "#5-1");
1643                 Assert.AreEqual (12, text.IndexOf ("6", 12, 1, StringComparison.OrdinalIgnoreCase), "#5-2");
1644         }
1645
1646         [Test]
1647         public void IndexOfStringComparisonOrdinal ()
1648         {
1649                 string text = "testing123456";
1650                 Assert.AreEqual (10, text.IndexOf ("456", StringComparison.Ordinal), "#1");
1651                 Assert.AreEqual (-1, text.IndexOf ("4567", StringComparison.Ordinal), "#2");
1652                 Assert.AreEqual (0, text.IndexOf ("te", StringComparison.Ordinal), "#3");
1653                 Assert.AreEqual (2, text.IndexOf ("s", StringComparison.Ordinal), "#4");
1654                 Assert.AreEqual (-1, text.IndexOf ("ates", StringComparison.Ordinal), "#5");
1655                 Assert.AreEqual (-1, text.IndexOf ("S", StringComparison.Ordinal), "#6");
1656         }
1657
1658         [Test]
1659         public void IndexOfStringComparisonOrdinalIgnoreCase ()
1660         {
1661                 string text = "testing123456";
1662                 Assert.AreEqual (10, text.IndexOf ("456", StringComparison.OrdinalIgnoreCase), "#1");
1663                 Assert.AreEqual (-1, text.IndexOf ("4567", StringComparison.OrdinalIgnoreCase), "#2");
1664                 Assert.AreEqual (0, text.IndexOf ("te", StringComparison.OrdinalIgnoreCase), "#3");
1665                 Assert.AreEqual (2, text.IndexOf ("s", StringComparison.OrdinalIgnoreCase), "#4");
1666                 Assert.AreEqual (-1, text.IndexOf ("ates", StringComparison.OrdinalIgnoreCase), "#5");
1667                 Assert.AreEqual (2, text.IndexOf ("S", StringComparison.OrdinalIgnoreCase), "#6");
1668         }
1669
1670         [Test]
1671         public void IndexOfOrdinalCountSmallerThanValueString ()
1672         {
1673                 Assert.AreEqual (-1, "Test".IndexOf ("ST", 2, 1, StringComparison.Ordinal), "#1");
1674                 Assert.AreEqual (-1, "Test".IndexOf ("ST", 2, 1, StringComparison.OrdinalIgnoreCase), "#2");
1675                 Assert.AreEqual (-1, "Test".LastIndexOf ("ST", 2, 1, StringComparison.Ordinal), "#3");
1676                 Assert.AreEqual (-1, "Test".LastIndexOf ("ST", 2, 1, StringComparison.OrdinalIgnoreCase), "#4");
1677         }
1678
1679         [Test] // IndexOf (Char, Int32, Int32)
1680         public void IndexOf6_Count_Negative ()
1681         {
1682                 try {
1683                         "Mono".IndexOf ('o', 1, -1);
1684                         Assert.Fail ("#1");
1685                 } catch (ArgumentOutOfRangeException ex) {
1686                         // Count must be positive and count must refer to a
1687                         // location within the string/array/collection
1688                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1689                         Assert.IsNull (ex.InnerException, "#3");
1690                         Assert.IsNotNull (ex.Message, "#4");
1691                         Assert.AreEqual ("count", ex.ParamName, "#5");
1692                 }
1693         }
1694
1695         [Test] // IndexOf (Char, Int32, Int32)
1696         public void IndexOf6_Count_Overflow ()
1697         {
1698                 try {
1699                         "Mono".IndexOf ('o', 1, Int32.MaxValue);
1700                         Assert.Fail ("#1");
1701                 } catch (ArgumentOutOfRangeException ex) {
1702                         // Count must be positive and count must refer to a
1703                         // location within the string/array/collection
1704                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1705                         Assert.IsNull (ex.InnerException, "#3");
1706                         Assert.IsNotNull (ex.Message, "#4");
1707                         Assert.AreEqual ("count", ex.ParamName, "#5");
1708                 }
1709         }
1710
1711         [Test] // IndexOf (Char, Int32, Int32)
1712         public void IndexOf6_StartIndex_Negative ()
1713         {
1714                 try {
1715                         "Mono".IndexOf ('o', -1, 1);
1716                         Assert.Fail ("#1");
1717                 } catch (ArgumentOutOfRangeException ex) {
1718                         // Index was out of range. Must be non-negative and
1719                         // less than the size of the collection
1720                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1721                         Assert.IsNull (ex.InnerException, "#3");
1722                         Assert.IsNotNull (ex.Message, "#4");
1723                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
1724                 }
1725         }
1726
1727         [Test] // IndexOf (Char, Int32, Int32)
1728         public void IndexOf6_StartIndex_Overflow ()
1729         {
1730                 string s = "testing123456";
1731
1732                 try {
1733                         s.IndexOf ('o', s.Length + 1, 1);
1734                         Assert.Fail ("#1");
1735                 } catch (ArgumentOutOfRangeException ex) {
1736                         // Index was out of range. Must be non-negative and
1737                         // less than the size of the collection
1738                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1739                         Assert.IsNull (ex.InnerException, "#3");
1740                         Assert.IsNotNull (ex.Message, "#4");
1741                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
1742                 }
1743         }
1744
1745         [Test] // IndexOf (String, Int32, Int32)
1746         public void IndexOf7 ()
1747         {
1748                 string s = "testing123456test";
1749
1750                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
1751
1752                 Assert.AreEqual (-1, s.IndexOf ("123", 4, 5), "#A1");
1753                 Assert.AreEqual (7, s.IndexOf ("123", 4, 6), "#A2");
1754                 Assert.AreEqual (-1, s.IndexOf ("123", 5, 4), "#A3");
1755                 Assert.AreEqual (7, s.IndexOf ("123", 5, 5), "#A4");
1756                 Assert.AreEqual (7, s.IndexOf ("123", 0, s.Length), "#A5");
1757                 Assert.AreEqual (-1, s.IndexOf ("123", s.Length, 0), "#A6");
1758
1759                 Assert.AreEqual (-1, s.IndexOf ("tin", 2, 3), "#B1");
1760                 Assert.AreEqual (3, s.IndexOf ("tin", 3, 3), "#B2");
1761                 Assert.AreEqual (-1, s.IndexOf ("tin", 2, 2), "#B3");
1762                 Assert.AreEqual (-1, s.IndexOf ("tin", 1, 4), "#B4");
1763                 Assert.AreEqual (3, s.IndexOf ("tin", 0, s.Length), "#B5");
1764                 Assert.AreEqual (-1, s.IndexOf ("tin", s.Length, 0), "#B6");
1765
1766                 Assert.AreEqual (6, s.IndexOf ("g12", 4, 5), "#C1");
1767                 Assert.AreEqual (-1, s.IndexOf ("g12", 5, 2), "#C2");
1768                 Assert.AreEqual (-1, s.IndexOf ("g12", 5, 3), "#C3");
1769                 Assert.AreEqual (6, s.IndexOf ("g12", 6, 4), "#C4");
1770                 Assert.AreEqual (6, s.IndexOf ("g12", 0, s.Length), "#C5");
1771                 Assert.AreEqual (-1, s.IndexOf ("g12", s.Length, 0), "#C6");
1772
1773                 Assert.AreEqual (1, s.IndexOf ("est", 0, 5), "#D1");
1774                 Assert.AreEqual (-1, s.IndexOf ("est", 1, 2), "#D2");
1775                 Assert.AreEqual (-1, s.IndexOf ("est", 2, 10), "#D3");
1776                 Assert.AreEqual (14, s.IndexOf ("est", 7, 10), "#D4");
1777                 Assert.AreEqual (1, s.IndexOf ("est", 0, s.Length), "#D5");
1778                 Assert.AreEqual (-1, s.IndexOf ("est", s.Length, 0), "#D6");
1779
1780                 Assert.AreEqual (-1, s.IndexOf ("T", 0, s.Length), "#E1");
1781                 Assert.AreEqual (4, s.IndexOf ("i", 0, s.Length), "#E2");
1782                 Assert.AreEqual (-1, s.IndexOf ("I", 0, s.Length), "#E3");
1783                 Assert.AreEqual (12, s.IndexOf ("6", 0, s.Length), "#E4");
1784                 Assert.AreEqual (0, s.IndexOf ("testing123456", 0, s.Length), "#E5");
1785                 Assert.AreEqual (-1, s.IndexOf ("testing1234567", 0, s.Length), "#E6");
1786                 Assert.AreEqual (0, s.IndexOf (string.Empty, 0, 0), "#E7");
1787                 Assert.AreEqual (4, s.IndexOf (string.Empty, 4, 3), "#E8");
1788                 Assert.AreEqual (0, string.Empty.IndexOf (string.Empty, 0, 0), "#E9");
1789                 Assert.AreEqual (-1, string.Empty.IndexOf ("abc", 0, 0), "#E10");
1790
1791                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
1792
1793                 Assert.AreEqual (-1, s.IndexOf ("123", 4, 5), "#F1");
1794                 Assert.AreEqual (7, s.IndexOf ("123", 4, 6), "#F2");
1795                 Assert.AreEqual (-1, s.IndexOf ("123", 5, 4), "#F3");
1796                 Assert.AreEqual (7, s.IndexOf ("123", 5, 5), "#F4");
1797                 Assert.AreEqual (7, s.IndexOf ("123", 0, s.Length), "#F5");
1798                 Assert.AreEqual (-1, s.IndexOf ("123", s.Length, 0), "#F6");
1799
1800                 Assert.AreEqual (-1, s.IndexOf ("tin", 2, 3), "#G1");
1801                 Assert.AreEqual (3, s.IndexOf ("tin", 3, 3), "#G2");
1802                 Assert.AreEqual (-1, s.IndexOf ("tin", 2, 2), "#G3");
1803                 Assert.AreEqual (-1, s.IndexOf ("tin", 1, 4), "#G4");
1804                 Assert.AreEqual (3, s.IndexOf ("tin", 0, s.Length), "#G5");
1805                 Assert.AreEqual (-1, s.IndexOf ("tin", s.Length, 0), "#G6");
1806
1807                 Assert.AreEqual (6, s.IndexOf ("g12", 4, 5), "#H1");
1808                 Assert.AreEqual (-1, s.IndexOf ("g12", 5, 2), "#H2");
1809                 Assert.AreEqual (-1, s.IndexOf ("g12", 5, 3), "#H3");
1810                 Assert.AreEqual (6, s.IndexOf ("g12", 6, 4), "#H4");
1811                 Assert.AreEqual (6, s.IndexOf ("g12", 0, s.Length), "#H5");
1812                 Assert.AreEqual (-1, s.IndexOf ("g12", s.Length, 0), "#H6");
1813
1814                 Assert.AreEqual (1, s.IndexOf ("est", 0, 5), "#I1");
1815                 Assert.AreEqual (-1, s.IndexOf ("est", 1, 2), "#I2");
1816                 Assert.AreEqual (-1, s.IndexOf ("est", 2, 10), "#I3");
1817                 Assert.AreEqual (14, s.IndexOf ("est", 7, 10), "#I4");
1818                 Assert.AreEqual (1, s.IndexOf ("est", 0, s.Length), "#I5");
1819                 Assert.AreEqual (-1, s.IndexOf ("est", s.Length, 0), "#I6");
1820
1821                 Assert.AreEqual (-1, s.IndexOf ("T", 0, s.Length), "#J1");
1822                 Assert.AreEqual (4, s.IndexOf ("i", 0, s.Length), "#J2");
1823                 Assert.AreEqual (-1, s.IndexOf ("I", 0, s.Length), "#J3");
1824                 Assert.AreEqual (12, s.IndexOf ("6", 0, s.Length), "#J4");
1825                 Assert.AreEqual (0, s.IndexOf ("testing123456", 0, s.Length), "#J5");
1826                 Assert.AreEqual (-1, s.IndexOf ("testing1234567", 0, s.Length), "#J6");
1827                 Assert.AreEqual (0, s.IndexOf (string.Empty, 0, 0), "#J7");
1828                 Assert.AreEqual (4, s.IndexOf (string.Empty, 4, 3), "#J8");
1829                 Assert.AreEqual (0, string.Empty.IndexOf (string.Empty, 0, 0), "#J9");
1830                 Assert.AreEqual (-1, string.Empty.IndexOf ("abc", 0, 0), "#J10");
1831         }
1832
1833         [Test]
1834         public void IndexOf7_Empty ()
1835         {
1836                 Assert.AreEqual (1, "FOO".IndexOf ("", 1, 2, StringComparison.Ordinal));
1837                 Assert.AreEqual (1, "FOO".IndexOf ("", 1, 2, StringComparison.OrdinalIgnoreCase));
1838         }
1839
1840         [Test] // IndexOf (String, Int32, Int32)
1841         public void IndexOf7_Count_Negative ()
1842         {
1843                 try {
1844                         "Mono".IndexOf ("no", 1, -1);
1845                         Assert.Fail ("#1");
1846                 } catch (ArgumentOutOfRangeException ex) {
1847                         // Count must be positive and count must refer to a
1848                         // location within the string/array/collection
1849                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1850                         Assert.IsNull (ex.InnerException, "#3");
1851                         Assert.IsNotNull (ex.Message, "#4");
1852                         Assert.AreEqual ("count", ex.ParamName, "#5");
1853                 }
1854         }
1855
1856         [Test] // IndexOf (String, Int32, Int32)
1857         public void IndexOf7_Count_Overflow ()
1858         {
1859                 string s = "testing123456";
1860
1861                 try {
1862                         s.IndexOf ("no", 1, s.Length);
1863                         Assert.Fail ("#A1");
1864                 } catch (ArgumentOutOfRangeException ex) {
1865                         // Count must be positive and count must refer to a
1866                         // location within the string/array/collection
1867                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
1868                         Assert.IsNull (ex.InnerException, "#A3");
1869                         Assert.IsNotNull (ex.Message, "#A4");
1870                         Assert.AreEqual ("count", ex.ParamName, "#A5");
1871                 }
1872
1873                 try {
1874                         s.IndexOf ("no", 1, s.Length + 1);
1875                         Assert.Fail ("#B1");
1876                 } catch (ArgumentOutOfRangeException ex) {
1877                         // Count must be positive and count must refer to a
1878                         // location within the string/array/collection
1879                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
1880                         Assert.IsNull (ex.InnerException, "#B3");
1881                         Assert.IsNotNull (ex.Message, "#B4");
1882                         Assert.AreEqual ("count", ex.ParamName, "#B5");
1883                 }
1884
1885                 try {
1886                         s.IndexOf ("no", 1, int.MaxValue);
1887                         Assert.Fail ("#C1");
1888                 } catch (ArgumentOutOfRangeException ex) {
1889                         // Count must be positive and count must refer to a
1890                         // location within the string/array/collection
1891                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
1892                         Assert.IsNull (ex.InnerException, "#C3");
1893                         Assert.IsNotNull (ex.Message, "#C4");
1894                         Assert.AreEqual ("count", ex.ParamName, "#C5");
1895                 }
1896         }
1897
1898         [Test] // IndexOf (String, Int32, Int32)
1899         public void IndexOf7_StartIndex_Negative ()
1900         {
1901                 try {
1902                         "Mono".IndexOf ("no", -1, 1);
1903                         Assert.Fail ("#1");
1904                 } catch (ArgumentOutOfRangeException ex) {
1905                         // Index was out of range. Must be non-negative and
1906                         // less than the size of the collection
1907                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1908                         Assert.IsNull (ex.InnerException, "#3");
1909                         Assert.IsNotNull (ex.Message, "#4");
1910                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
1911                 }
1912         }
1913
1914         [Test] // IndexOf (String, Int32, Int32)
1915         public void IndexOf7_StartIndex_Overflow ()
1916         {
1917                 string s = "testing123456";
1918
1919                 try {
1920                         s.IndexOf ("no", s.Length + 1, 1);
1921                         Assert.Fail ("#A1");
1922                 } catch (ArgumentOutOfRangeException ex) {
1923                         // Index was out of range. Must be non-negative and
1924                         // less than the size of the collection
1925                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
1926                         Assert.IsNull (ex.InnerException, "#A3");
1927                         Assert.IsNotNull (ex.Message, "#A4");
1928                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
1929                 }
1930
1931                 try {
1932                         s.IndexOf ("no", int.MaxValue, 1);
1933                         Assert.Fail ("#B1");
1934                 } catch (ArgumentOutOfRangeException ex) {
1935                         // Index was out of range. Must be non-negative and
1936                         // less than the size of the collection
1937                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
1938                         Assert.IsNull (ex.InnerException, "#B3");
1939                         Assert.IsNotNull (ex.Message, "#B4");
1940                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
1941                 }
1942         }
1943
1944         [Test] // IndexOf (String, Int32, Int32)
1945         public void IndexOf7_Value_Null ()
1946         {
1947                 try {
1948                         "Mono".IndexOf ((string) null, 0, 1);
1949                         Assert.Fail ("#1");
1950                 } catch (ArgumentNullException ex) {
1951                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1952                         Assert.IsNull (ex.InnerException, "#3");
1953                         Assert.IsNotNull (ex.Message, "#4");
1954                         Assert.AreEqual ("value", ex.ParamName, "#5");
1955                 }
1956         }
1957
1958         [Test] // IndexOf (String, Int32, StringComparison)
1959         public void IndexOf8_ComparisonType_Invalid ()
1960         {
1961                 try {
1962                         "Mono".IndexOf (string.Empty, 1, (StringComparison) Int32.MinValue);
1963                         Assert.Fail ("#1");
1964                 } catch (ArgumentException ex) {
1965                         // The string comparison type passed in is currently
1966                         // not supported
1967                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
1968                         Assert.IsNull (ex.InnerException, "#3");
1969                         Assert.IsNotNull (ex.Message, "#4");
1970                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
1971                 }
1972         }
1973
1974         [Test] // IndexOf (String, Int32, StringComparison)
1975         public void IndexOf8_StartIndex_Negative ()
1976         {
1977                 try {
1978                         "Mono".IndexOf ("o", -1, StringComparison.Ordinal);
1979                         Assert.Fail ("#1");
1980                 } catch (ArgumentOutOfRangeException ex) {
1981                         // Index was out of range. Must be non-negative and
1982                         // less than the size of the collection
1983                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
1984                         Assert.IsNull (ex.InnerException, "#3");
1985                         Assert.IsNotNull (ex.Message, "#4");
1986                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
1987                 }
1988         }
1989
1990         [Test] // IndexOf (String, Int32, Int32, StringComparison)
1991         public void IndexOf9_ComparisonType_Invalid ()
1992         {
1993                 try {
1994                         "Mono".IndexOf (string.Empty, 0, 1, (StringComparison) Int32.MinValue);
1995                         Assert.Fail ("#1");
1996                 } catch (ArgumentException ex) {
1997                         // The string comparison type passed in is currently
1998                         // not supported
1999                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
2000                         Assert.IsNull (ex.InnerException, "#3");
2001                         Assert.IsNotNull (ex.Message, "#4");
2002                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
2003                 }
2004         }
2005
2006         [Test] // IndexOf (String, Int32, Int32, StringComparison)
2007         public void IndexOf9_Count_Negative ()
2008         {
2009                 try {
2010                         "Mono".IndexOf ("o", 1, -1, StringComparison.Ordinal);
2011                         Assert.Fail ("#1");
2012                         Assert.Fail ("#1");
2013                 } catch (ArgumentOutOfRangeException ex) {
2014                         // Count must be positive and count must refer to a
2015                         // location within the string/array/collection
2016                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2017                         Assert.IsNull (ex.InnerException, "#3");
2018                         Assert.IsNotNull (ex.Message, "#4");
2019                         Assert.AreEqual ("count", ex.ParamName, "#5");
2020                 }
2021         }
2022
2023         [Test] // IndexOf (String, Int32, Int32, StringComparison)
2024         public void IndexOf9_StartIndex_Negative ()
2025         {
2026                 try {
2027                         "Mono".IndexOf ("o", -1, 0, StringComparison.Ordinal);
2028                         Assert.Fail ("#1");
2029                 } catch (ArgumentOutOfRangeException ex) {
2030                         // Index was out of range. Must be non-negative and
2031                         // less than the size of the collection
2032                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2033                         Assert.IsNull (ex.InnerException, "#3");
2034                         Assert.IsNotNull (ex.Message, "#4");
2035                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2036                 }
2037         }
2038
2039         [Test]
2040         public void IndexOfAny1 ()
2041         {
2042                 string s = "abcdefghijklmd";
2043                 char[] c;
2044
2045                 c = new char [] {'a', 'e', 'i', 'o', 'u'};
2046                 Assert.AreEqual (0, s.IndexOfAny (c), "#1");
2047                 c = new char [] { 'd', 'z' };
2048                 Assert.AreEqual (3, s.IndexOfAny (c), "#1");
2049                 c = new char [] { 'q', 'm', 'z' };
2050                 Assert.AreEqual (12, s.IndexOfAny (c), "#2");
2051                 c = new char [0];
2052                 Assert.AreEqual (-1, s.IndexOfAny (c), "#3");
2053
2054         }
2055
2056         [Test] // IndexOfAny (Char [])
2057         public void IndexOfAny1_AnyOf_Null ()
2058         {
2059                 try {
2060                         "mono".IndexOfAny ((char []) null);
2061                         Assert.Fail ("#1");
2062                 } catch (ArgumentNullException ex) {
2063                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2064                         Assert.IsNull (ex.InnerException, "#3");
2065                         Assert.IsNotNull (ex.Message, "#4");
2066                         Assert.IsNull (ex.ParamName, "#5");
2067                 }
2068         }
2069
2070         [Test] // IndexOfAny (Char [], Int32)
2071         public void IndexOfAny2 ()
2072         {
2073                 string s = "abcdefghijklmd";
2074                 char [] c;
2075
2076                 c = new char [] { 'a', 'e', 'i', 'o', 'u' };
2077                 Assert.AreEqual (0, s.IndexOfAny (c, 0), "#A1");
2078                 Assert.AreEqual (4, s.IndexOfAny (c, 1), "#A1");
2079                 Assert.AreEqual (-1, s.IndexOfAny (c, 9), "#A2");
2080                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length), "#A3");
2081
2082                 c = new char [] { 'd', 'z' };
2083                 Assert.AreEqual (3, s.IndexOfAny (c, 0), "#B1");
2084                 Assert.AreEqual (3, s.IndexOfAny (c, 3), "#B2");
2085                 Assert.AreEqual (13, s.IndexOfAny (c, 4), "#B3");
2086                 Assert.AreEqual (13, s.IndexOfAny (c, 9), "#B4");
2087                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length), "#B5");
2088                 Assert.AreEqual (13, s.IndexOfAny (c, s.Length - 1), "#B6");
2089
2090                 c = new char [] { 'q', 'm', 'z' };
2091                 Assert.AreEqual (12, s.IndexOfAny (c, 0), "#C1");
2092                 Assert.AreEqual (12, s.IndexOfAny (c, 4), "#C2");
2093                 Assert.AreEqual (12, s.IndexOfAny (c, 12), "#C3");
2094                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length), "#C4");
2095
2096                 c = new char [0];
2097                 Assert.AreEqual (-1, s.IndexOfAny (c, 0), "#D1");
2098                 Assert.AreEqual (-1, s.IndexOfAny (c, 4), "#D2");
2099                 Assert.AreEqual (-1, s.IndexOfAny (c, 9), "#D3");
2100                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length), "#D4");
2101         }
2102
2103         [Test] // IndexOfAny (Char [], Int32)
2104         public void IndexOfAny2_AnyOf_Null ()
2105         {
2106                 try {
2107                         "mono".IndexOfAny ((char []) null, 0);
2108                         Assert.Fail ("#1");
2109                 } catch (ArgumentNullException ex) {
2110                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2111                         Assert.IsNull (ex.InnerException, "#3");
2112                         Assert.IsNotNull (ex.Message, "#4");
2113                         Assert.IsNull (ex.ParamName, "#5");
2114                 }
2115         }
2116
2117         [Test] // IndexOfAny (Char [], Int32)
2118         public void IndexOfAny2_StartIndex_Negative ()
2119         {
2120                 string s = "abcdefghijklm";
2121
2122                 try {
2123                         s.IndexOfAny (new char [1] { 'd' }, -1, 1);
2124                         Assert.Fail ("#1");
2125                 } catch (ArgumentOutOfRangeException ex) {
2126                         // Specified argument was out of the range of valid
2127                         // values
2128                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2129                         Assert.IsNull (ex.InnerException, "#3");
2130                         Assert.IsNotNull (ex.Message, "#4");
2131                         Assert.IsNull (ex.ParamName, "#5");
2132                 }
2133         }
2134
2135         [Test] // IndexOfAny (Char [], Int32, Int32)
2136         public void IndexOfAny2_StartIndex_Overflow ()
2137         {
2138                 string s = "abcdefghijklm";
2139
2140                 try {
2141                         s.IndexOfAny (new char [1] { 'd' }, s.Length + 1);
2142                         Assert.Fail ("#1");
2143                 } catch (ArgumentOutOfRangeException ex) {
2144                         // Specified argument was out of the range of valid
2145                         // values
2146                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2147                         Assert.IsNull (ex.InnerException, "#3");
2148                         Assert.IsNotNull (ex.Message, "#4");
2149                         Assert.IsNull (ex.ParamName, "#5");
2150                 }
2151         }
2152
2153         [Test] // IndexOfAny (Char [], Int32, Int32)
2154         public void IndexOfAny3 ()
2155         {
2156                 string s = "abcdefghijklmd";
2157                 char [] c;
2158
2159                 c = new char [] { 'a', 'e', 'i', 'o', 'u' };
2160                 Assert.AreEqual (0, s.IndexOfAny (c, 0, 2), "#A1");
2161                 Assert.AreEqual (-1, s.IndexOfAny (c, 1, 2), "#A2");
2162                 Assert.AreEqual (-1, s.IndexOfAny (c, 1, 3), "#A3");
2163                 Assert.AreEqual (4, s.IndexOfAny (c, 1, 4), "#A3");
2164                 Assert.AreEqual (4, s.IndexOfAny (c, 1, s.Length - 1), "#A4");
2165
2166                 c = new char [] { 'd', 'z' };
2167                 Assert.AreEqual (-1, s.IndexOfAny (c, 0, 2), "#B1");
2168                 Assert.AreEqual (-1, s.IndexOfAny (c, 1, 2), "#B2");
2169                 Assert.AreEqual (3, s.IndexOfAny (c, 1, 3), "#B3");
2170                 Assert.AreEqual (3, s.IndexOfAny (c, 0, s.Length), "#B4");
2171                 Assert.AreEqual (3, s.IndexOfAny (c, 1, s.Length - 1), "#B5");
2172                 Assert.AreEqual (-1, s.IndexOfAny (c, s.Length, 0), "#B6");
2173
2174                 c = new char [] { 'q', 'm', 'z' };
2175                 Assert.AreEqual (-1, s.IndexOfAny (c, 0, 10), "#C1");
2176                 Assert.AreEqual (12, s.IndexOfAny (c, 10, 4), "#C2");
2177                 Assert.AreEqual (-1, s.IndexOfAny (c, 1, 3), "#C3");
2178                 Assert.AreEqual (12, s.IndexOfAny (c, 0, s.Length), "#C4");
2179                 Assert.AreEqual (12, s.IndexOfAny (c, 1, s.Length - 1), "#C5");
2180
2181                 c = new char [0];
2182                 Assert.AreEqual (-1, s.IndexOfAny (c, 0, 3), "#D1");
2183                 Assert.AreEqual (-1, s.IndexOfAny (c, 4, 9), "#D2");
2184                 Assert.AreEqual (-1, s.IndexOfAny (c, 9, 5), "#D3");
2185                 Assert.AreEqual (-1, s.IndexOfAny (c, 13, 1), "#D4");
2186         }
2187
2188         [Test] // IndexOfAny (Char [], Int32, Int32)
2189         public void IndexOfAny3_AnyOf_Null ()
2190         {
2191                 try {
2192                         "mono".IndexOfAny ((char []) null, 0, 0);
2193                         Assert.Fail ("#1");
2194                 } catch (ArgumentNullException ex) {
2195                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2196                         Assert.IsNull (ex.InnerException, "#3");
2197                         Assert.IsNotNull (ex.Message, "#4");
2198                         Assert.IsNull (ex.ParamName, "#5");
2199                 }
2200         }
2201
2202         [Test] // IndexOfAny (Char [], Int32, Int32)
2203         public void IndexOfAny3_Count_Negative ()
2204         {
2205                 try {
2206                         "Mono".IndexOfAny (new char [1] { 'o' }, 1, -1);
2207                         Assert.Fail ("#1");
2208                 } catch (ArgumentOutOfRangeException ex) {
2209                         // Count must be positive and count must refer to a
2210                         // location within the string/array/collection
2211                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2212                         Assert.IsNull (ex.InnerException, "#3");
2213                         Assert.IsNotNull (ex.Message, "#4");
2214                         Assert.AreEqual ("count", ex.ParamName, "#5");
2215                 }
2216         }
2217
2218         [Test] // IndexOfAny (Char [], Int32, Int32)
2219         public void IndexOfAny3_Length_Overflow ()
2220         {
2221                 string s = "abcdefghijklm";
2222
2223                 try {
2224                         s.IndexOfAny (new char [1] { 'd' }, 1, s.Length);
2225                         Assert.Fail ("#1");
2226                 } catch (ArgumentOutOfRangeException ex) {
2227                         // Count must be positive and count must refer to a
2228                         // location within the string/array/collection
2229                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2230                         Assert.IsNull (ex.InnerException, "#3");
2231                         Assert.IsNotNull (ex.Message, "#4");
2232                         Assert.AreEqual ("count", ex.ParamName, "#5");
2233                 }
2234         }
2235
2236         [Test] // IndexOfAny (Char [], Int32, Int32)
2237         public void IndexOfAny3_StartIndex_Negative ()
2238         {
2239                 try {
2240                         "Mono".IndexOfAny (new char [1] { 'o' }, -1, 1);
2241                         Assert.Fail ("#1");
2242                 } catch (ArgumentOutOfRangeException ex) {
2243                         // Specified argument was out of the range of valid
2244                         // values
2245                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2246                         Assert.IsNull (ex.InnerException, "#3");
2247                         Assert.IsNotNull (ex.Message, "#4");
2248                         Assert.IsNull (ex.ParamName, "#5");
2249                 }
2250         }
2251
2252         [Test] // IndexOfAny (Char [], Int32, Int32)
2253         public void IndexOfAny3_StartIndex_Overflow ()
2254         {
2255                 string s = "abcdefghijklm";
2256
2257                 try {
2258                         s.IndexOfAny (new char [1] { 'o' }, s.Length + 1, 1);
2259                         Assert.Fail ("#1");
2260                 } catch (ArgumentOutOfRangeException ex) {
2261                         // Specified argument was out of the range of valid
2262                         // values
2263                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2264                         Assert.IsNull (ex.InnerException, "#3");
2265                         Assert.IsNotNull (ex.Message, "#4");
2266                         Assert.IsNull (ex.ParamName, "#5");
2267                 }
2268         }
2269
2270         [Test]
2271         public void Contains ()
2272         {
2273                 Assert.IsTrue ("ABC".Contains (string.Empty));
2274                 Assert.IsTrue ("ABC".Contains ("ABC"));
2275                 Assert.IsTrue ("ABC".Contains ("AB"));
2276                 Assert.IsTrue (!"ABC".Contains ("AD"));
2277                 Assert.IsTrue (!"encyclopædia".Contains("encyclopaedia"));
2278         }
2279
2280         [Test]
2281         public void IndexOfIsCultureAwareWhileContainsIsNot ()
2282         {
2283                 string a = "encyclopædia";
2284                 string b = "encyclopaedia";
2285                 Assert.IsFalse (a.Contains (b), "#1");
2286                 Assert.IsTrue (a.Contains ("æ"), "#1.1");
2287                 Assert.IsFalse (b.Contains ("æ"), "#1.2");
2288                 Assert.AreEqual (0, a.IndexOf (b), "#2");
2289                 Assert.AreEqual (8, a.IndexOf ('æ'), "#3");
2290                 Assert.AreEqual (-1, b.IndexOf ('æ'), "#4");
2291                 Assert.AreEqual (8, a.IndexOf ("æ"), "#5");
2292                 Assert.AreEqual (8, b.IndexOf ("æ"), "#6");
2293
2294                 Assert.AreEqual (0, CultureInfo.CurrentCulture.CompareInfo.IndexOf (a, b, 0, a.Length, CompareOptions.None), "#7");
2295                 Assert.AreEqual (-1, CultureInfo.CurrentCulture.CompareInfo.IndexOf (a, b, 0, a.Length, CompareOptions.Ordinal), "#8");
2296         }
2297
2298         [Test]
2299         public void Contains_Value_Null ()
2300         {
2301                 try {
2302                         "ABC".Contains (null);
2303                         Assert.Fail ("#1");
2304                 } catch (ArgumentNullException ex) {
2305                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2306                         Assert.IsNull (ex.InnerException, "#3");
2307                         Assert.IsNotNull (ex.Message, "#4");
2308                         Assert.AreEqual ("value", ex.ParamName, "#5");
2309                 }
2310         }
2311
2312         [Test]
2313         public void IsNullOrEmpty ()
2314         {
2315                 Assert.IsTrue (String.IsNullOrEmpty (null));
2316                 Assert.IsTrue (String.IsNullOrEmpty (String.Empty));
2317                 Assert.IsTrue (String.IsNullOrEmpty (""));
2318                 Assert.IsTrue (!String.IsNullOrEmpty ("A"));
2319                 Assert.IsTrue (!String.IsNullOrEmpty (" "));
2320                 Assert.IsTrue (!String.IsNullOrEmpty ("\t"));
2321                 Assert.IsTrue (!String.IsNullOrEmpty ("\n"));
2322         }
2323
2324         [Test]
2325         public void TestInsert ()
2326         {
2327                 string s1 = "original";
2328                 
2329                 try {
2330                         s1.Insert (0, null);
2331                         Assert.Fail ("#A1");
2332                 } catch (ArgumentNullException ex) {
2333                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
2334                         Assert.IsNull (ex.InnerException, "#A3");
2335                         Assert.IsNotNull (ex.Message, "#A4");
2336                         Assert.AreEqual ("value", ex.ParamName, "#A5");
2337                 }
2338
2339                 try {
2340                         s1.Insert (s1.Length + 1, "Hi!");
2341                         Assert.Fail ("#B1");
2342                 } catch (ArgumentOutOfRangeException ex) {
2343                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
2344                         Assert.IsNull (ex.InnerException, "#B3");
2345                         Assert.IsNotNull (ex.Message, "#B4");
2346                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
2347                 }
2348
2349                 Assert.AreEqual ("Hi!original", s1.Insert (0, "Hi!"), "#C1");
2350                 Assert.AreEqual ("originalHi!", s1.Insert (s1.Length, "Hi!"), "#C2");
2351                 Assert.AreEqual ("origHi!inal", s1.Insert (4, "Hi!"), "#C3");
2352         }
2353
2354         [Test]
2355         public void Intern ()
2356         {
2357                 string s1 = "original";
2358                 Assert.AreSame (s1, String.Intern (s1), "#A1");
2359                 Assert.AreSame (String.Intern(s1), String.Intern(s1), "#A2");
2360
2361                 string s2 = "originally";
2362                 Assert.AreSame (s2, String.Intern (s2), "#B1");
2363                 Assert.IsTrue (String.Intern(s1) != String.Intern(s2), "#B2");
2364
2365                 string s3 = new DateTime (2000, 3, 7).ToString ();
2366                 Assert.IsNull (String.IsInterned (s3), "#C1");
2367
2368                 string s4 = String.Intern (s3);
2369                 Assert.AreEqual (s3, s4, "#C2");
2370                 Assert.AreSame (s4, String.IsInterned (s4), "#C3");
2371                 Assert.AreSame (s4, String.IsInterned (new DateTime (2000, 3, 7).ToString ()), "#C4");
2372                 Assert.AreSame (s4, String.Intern (new DateTime (2000, 3, 7).ToString ()), "#C5");
2373         }
2374
2375         [Test]
2376         public void Intern_Str_Null ()
2377         {
2378                 try {
2379                         String.Intern (null);
2380                         Assert.Fail ("#1");
2381                 } catch (ArgumentNullException ex) {
2382                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2383                         Assert.IsNull (ex.InnerException, "#3");
2384                         Assert.IsNotNull (ex.Message, "#4");
2385                         Assert.AreEqual ("str", ex.ParamName, "#5");
2386                 }
2387         }
2388
2389         [Test]
2390         public void IsInterned ()
2391         {
2392                 Assert.IsNull (String.IsInterned (new DateTime (2000, 3, 6).ToString ()), "#1");
2393                 string s1 = "original";
2394                 Assert.AreSame (s1, String.IsInterned (s1), "#2");
2395         }
2396
2397         [Test]
2398         public void IsInterned_Str_Null ()
2399         {
2400                 try {
2401                         String.IsInterned (null);
2402                         Assert.Fail ("#1");
2403                 } catch (ArgumentNullException ex) {
2404                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2405                         Assert.IsNull (ex.InnerException, "#3");
2406                         Assert.IsNotNull (ex.Message, "#4");
2407                         Assert.AreEqual ("str", ex.ParamName, "#5");
2408                 }
2409         }
2410
2411         [Test]
2412         public void TestJoin ()
2413         {
2414                 try {
2415                         string s = String.Join(" ", null);
2416                         Assert.Fail ("#A1");
2417                 } catch (ArgumentNullException ex) {
2418                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
2419                         Assert.IsNull (ex.InnerException, "#A3");
2420                         Assert.IsNotNull (ex.Message, "#A4");
2421                         Assert.AreEqual ("value", ex.ParamName, "#A5");
2422                 }
2423
2424                 string[] chunks = {"this", "is", "a", "test"};
2425                 Assert.AreEqual ("this is a test", String.Join(" ", chunks), "Basic join");
2426                 Assert.AreEqual ("this.is.a.test", String.Join(".", chunks), "Basic join");
2427
2428                 Assert.AreEqual ("is a", String.Join(" ", chunks, 1, 2), "Subset join");
2429                 Assert.AreEqual ("is.a", String.Join(".", chunks, 1, 2), "Subset join");
2430                 Assert.AreEqual ("is a test", String.Join(" ", chunks, 1, 3), "Subset join");
2431
2432                 try {
2433                         string s = String.Join(" ", chunks, 2, 3);
2434                         Assert.Fail ("#C1");
2435                 } catch (ArgumentOutOfRangeException ex) {
2436                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
2437                         Assert.IsNull (ex.InnerException, "#C3");
2438                         Assert.IsNotNull (ex.Message, "#C4");
2439                         Assert.AreEqual ("startIndex", ex.ParamName, "#C5");
2440                 }
2441         }
2442
2443         [Test]
2444         public void Join_SeparatorNull ()
2445         {
2446                 string[] chunks = {"this", "is", "a", "test"};
2447                 Assert.AreEqual ("thisisatest", String.Join (null, chunks), "SeparatorNull");
2448         }
2449
2450         [Test]
2451         public void Join_ValuesNull ()
2452         {
2453                 string[] chunks1 = {null, "is", "a", null};
2454                 Assert.AreEqual (" is a ", String.Join (" ", chunks1), "SomeNull");
2455
2456                 string[] chunks2 = {null, "is", "a", null};
2457                 Assert.AreEqual ("isa", String.Join (null, chunks2), "Some+Sep=Null");
2458
2459                 string[] chunks3 = {null, null, null, null};
2460                 Assert.AreEqual ("   ", String.Join (" ", chunks3), "AllValuesNull");
2461         }
2462
2463         [Test]
2464         public void Join_AllNull ()
2465         {
2466                 string[] chunks = {null, null, null};
2467                 Assert.AreEqual (string.Empty, String.Join (null, chunks), "AllNull");
2468         }
2469
2470         [Test]
2471         public void Join_StartIndexNegative ()
2472         {
2473                 string[] values = { "Mo", "no" };
2474                 try {
2475                         String.Join ("o", values, -1, 1);
2476                         Assert.Fail ("#1");
2477                 } catch (ArgumentOutOfRangeException ex) {
2478                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2479                         Assert.IsNull (ex.InnerException, "#3");
2480                         Assert.IsNotNull (ex.Message, "#4");
2481                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2482                 }
2483         }
2484
2485         [Test]
2486         public void Join_StartIndexOverflow ()
2487         {
2488                 string[] values = { "Mo", "no" };
2489                 try {
2490                         String.Join ("o", values, Int32.MaxValue, 1);
2491                         Assert.Fail ("#1");
2492                 } catch (ArgumentOutOfRangeException ex) {
2493                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2494                         Assert.IsNull (ex.InnerException, "#3");
2495                         Assert.IsNotNull (ex.Message, "#4");
2496                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2497                 }
2498         }
2499
2500         [Test]
2501         public void Join_LengthNegative ()
2502         {
2503                 string[] values = { "Mo", "no" };
2504                 try {
2505                         String.Join ("o", values, 1, -1);
2506                         Assert.Fail ("#1");
2507                 } catch (ArgumentOutOfRangeException ex) {
2508                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2509                         Assert.IsNull (ex.InnerException, "#3");
2510                         Assert.IsNotNull (ex.Message, "#4");
2511                         Assert.AreEqual ("count", ex.ParamName, "#5");
2512                 }
2513         }
2514
2515         [Test]
2516         public void Join_LengthOverflow ()
2517         {
2518                 string[] values = { "Mo", "no" };
2519                 try {
2520                         String.Join ("o", values, 1, Int32.MaxValue);
2521                         Assert.Fail ("#1");
2522                 } catch (ArgumentOutOfRangeException ex) {
2523                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2524                         Assert.IsNull (ex.InnerException, "#3");
2525                         Assert.IsNotNull (ex.Message, "#4");
2526                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2527                 }
2528         }
2529
2530         [Test]
2531         public void LastIndexOf ()
2532         {
2533                 string s1 = "original";
2534
2535                 try {
2536                         s1.LastIndexOf ('q', -1);
2537                         Assert.Fail ("#A1");
2538                 } catch (ArgumentOutOfRangeException ex) {
2539                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
2540                         Assert.IsNull (ex.InnerException, "#A3");
2541                         Assert.IsNotNull (ex.Message, "#A4");
2542                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
2543                 }
2544
2545                 try {
2546                         s1.LastIndexOf ('q', -1, 1);
2547                         Assert.Fail ("#B1");
2548                 } catch (ArgumentOutOfRangeException ex) {
2549                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
2550                         Assert.IsNull (ex.InnerException, "#B3");
2551                         Assert.IsNotNull (ex.Message, "#B4");
2552                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
2553                 }
2554
2555                 try {
2556                         s1.LastIndexOf ("huh", s1.Length + 1);
2557                         Assert.Fail ("#C1");
2558                 } catch (ArgumentOutOfRangeException ex) {
2559                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
2560                         Assert.IsNull (ex.InnerException, "#C3");
2561                         Assert.IsNotNull (ex.Message, "#C4");
2562                         Assert.AreEqual ("startIndex", ex.ParamName, "#C5");
2563                 }
2564
2565                 try {
2566                         int i = s1.LastIndexOf ("huh", s1.Length + 1, 3);
2567                         Assert.Fail ("#D1");
2568                 } catch (ArgumentOutOfRangeException ex) {
2569                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#D2");
2570                         Assert.IsNull (ex.InnerException, "#D3");
2571                         Assert.IsNotNull (ex.Message, "#D4");
2572                         Assert.AreEqual ("startIndex", ex.ParamName, "#D5");
2573                 }
2574
2575                 try {
2576                         s1.LastIndexOf (null);
2577                         Assert.Fail ("#E1");
2578                 } catch (ArgumentNullException ex) {
2579                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#E2");
2580                         Assert.IsNull (ex.InnerException, "#E3");
2581                         Assert.IsNotNull (ex.Message, "#E4");
2582                         Assert.AreEqual ("value", ex.ParamName, "#E5");
2583                 }
2584
2585                 try {
2586                         s1.LastIndexOf (null, 0);
2587                         Assert.Fail ("#F1");
2588                 } catch (ArgumentNullException ex) {
2589                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#F2");
2590                         Assert.IsNull (ex.InnerException, "#F3");
2591                         Assert.IsNotNull (ex.Message, "#F4");
2592                         Assert.AreEqual ("value", ex.ParamName, "#F5");
2593                 }
2594
2595                 try {
2596                         s1.LastIndexOf (null, 0, 1);
2597                         Assert.Fail ("#G1");
2598                 } catch (ArgumentNullException ex) {
2599                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#G2");
2600                         Assert.IsNull (ex.InnerException, "#G3");
2601                         Assert.IsNotNull (ex.Message, "#G4");
2602                         Assert.AreEqual ("value", ex.ParamName, "#G5");
2603                 }
2604
2605                 Assert.AreEqual (1, s1.LastIndexOf('r'), "basic char index");
2606                 Assert.AreEqual (4, s1.LastIndexOf('i'), "basic char index");
2607                 Assert.AreEqual (-1, s1.LastIndexOf('q'), "basic char index - no");
2608
2609                 Assert.AreEqual (7, s1.LastIndexOf(string.Empty), "basic string index");
2610                 Assert.AreEqual (1, s1.LastIndexOf("rig"), "basic string index");
2611                 Assert.AreEqual (4, s1.LastIndexOf("i"), "basic string index");
2612                 Assert.AreEqual (-1, s1.LastIndexOf("rag"), "basic string index - no");
2613
2614                 Assert.AreEqual (1, s1.LastIndexOf('r', s1.Length-1), "stepped char index");
2615                 Assert.AreEqual (4, s1.LastIndexOf('i', s1.Length-1), "stepped char index");
2616                 Assert.AreEqual (2, s1.LastIndexOf('i', 3), "stepped char index");
2617                 Assert.AreEqual (-1, s1.LastIndexOf('i', 1), "stepped char index");
2618
2619                 Assert.AreEqual (1, s1.LastIndexOf('r', 1, 1), "stepped limited char index");
2620                 Assert.AreEqual (-1, s1.LastIndexOf('r', 0, 1), "stepped limited char index");
2621                 Assert.AreEqual (4, s1.LastIndexOf('i', 6, 3), "stepped limited char index");
2622                 Assert.AreEqual (2, s1.LastIndexOf('i', 3, 3), "stepped limited char index");
2623                 Assert.AreEqual (-1, s1.LastIndexOf('i', 1, 2), "stepped limited char index");
2624
2625                 s1 = "original original";
2626                 Assert.AreEqual (9, s1.LastIndexOf("original", s1.Length), "stepped string index #1");
2627                 Assert.AreEqual (0, s1.LastIndexOf("original", s1.Length-2), "stepped string index #2");
2628                 Assert.AreEqual (-1, s1.LastIndexOf("original", s1.Length-11), "stepped string index #3");
2629                 Assert.AreEqual (-1, s1.LastIndexOf("translator", 2), "stepped string index #4");
2630                 Assert.AreEqual (0, string.Empty.LastIndexOf(string.Empty, 0), "stepped string index #5");
2631 #if !TARGET_JVM
2632                 Assert.AreEqual (-1, string.Empty.LastIndexOf("A", -1), "stepped string index #6");
2633 #endif
2634                 Assert.AreEqual (10, s1.LastIndexOf("rig", s1.Length-1, 10), "stepped limited string index #1");
2635                 Assert.AreEqual (-1, s1.LastIndexOf("rig", s1.Length, 3), "stepped limited string index #2");
2636                 Assert.AreEqual (10, s1.LastIndexOf("rig", s1.Length-2, 15), "stepped limited string index #3");
2637                 Assert.AreEqual (-1, s1.LastIndexOf("rig", s1.Length-2, 3), "stepped limited string index #4");
2638                              
2639                 string s2 = "QBitArray::bitarr_data"; 
2640                 Assert.AreEqual (9, s2.LastIndexOf ("::"), "bug #62160");
2641
2642                 string s3 = "test123";
2643                 Assert.AreEqual (0, s3.LastIndexOf ("test123"), "bug #77412");
2644
2645                 Assert.AreEqual (0, "\u267B RT \u30FC".LastIndexOf ("\u267B RT "), "bug #605094");
2646         }
2647
2648         [Test]
2649         [ExpectedException (typeof (ArgumentException))]
2650         public void LastIndexOf_StringComparison ()
2651         {
2652                 " ".LastIndexOf (string.Empty, 0, 1, (StringComparison)Int32.MinValue);
2653         }
2654
2655         [Test]
2656         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2657         public void LastIndexOfStringComparisonOrdinalRangeException1 ()
2658         {
2659                 "Mono".LastIndexOf ("no", 5, StringComparison.Ordinal);
2660         }
2661
2662         [Test]
2663         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2664         public void LastIndexOfStringComparisonOrdinalRangeException2 () 
2665         {
2666                 "Mono".LastIndexOf ("no", 1, 3, StringComparison.Ordinal);
2667         }
2668
2669         [Test]
2670         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2671         public void LastIndexOfStringComparisonOrdinalIgnoreCaseRangeException1 ()
2672         {
2673                 "Mono".LastIndexOf ("no", 5, StringComparison.OrdinalIgnoreCase);
2674         }
2675
2676         [Test]
2677         [ExpectedException (typeof (ArgumentOutOfRangeException))]
2678         public void LastIndexOfStringComparisonOrdinalIgnoreCaseRangeException2 ()
2679         {
2680                 "Mono".LastIndexOf ("no", 1, 3, StringComparison.OrdinalIgnoreCase);
2681         }
2682
2683         [Test]
2684         public void LastIndexOfStringComparison ()
2685         {
2686                 string text = "testing123456";
2687                 string text2 = "123";
2688                 string text3 = "NG";
2689                 string text4 = "t";
2690                 Assert.AreEqual (7, text.LastIndexOf (text2, StringComparison.Ordinal), "#1-1");
2691                 Assert.AreEqual (5, text.LastIndexOf (text3, StringComparison.OrdinalIgnoreCase), "#2-1");
2692
2693                 Assert.AreEqual (7, text.LastIndexOf (text2, 12, StringComparison.Ordinal), "#1-2");
2694                 Assert.AreEqual (5, text.LastIndexOf (text3, 12, StringComparison.OrdinalIgnoreCase), "#2-2");
2695
2696                 Assert.AreEqual (-1, text.LastIndexOf (text2, 0, StringComparison.Ordinal), "#1-3");
2697                 Assert.AreEqual (-1, text.LastIndexOf (text3, 0, StringComparison.OrdinalIgnoreCase), "#2-3");
2698
2699                 Assert.AreEqual (-1, text.LastIndexOf (text2, 6, StringComparison.Ordinal), "#1-4");
2700                 Assert.AreEqual (5, text.LastIndexOf (text3, 6, StringComparison.OrdinalIgnoreCase), "#2-4");
2701
2702                 Assert.AreEqual (-1, text.LastIndexOf (text2, 7, 3, StringComparison.Ordinal), "#1-5");
2703                 Assert.AreEqual (5, text.LastIndexOf (text3, 7, 3, StringComparison.OrdinalIgnoreCase), "#2-5");
2704
2705                 Assert.AreEqual (-1, text.LastIndexOf (text2, 6, 0, StringComparison.Ordinal), "#1-6");
2706                 Assert.AreEqual (-1, text.LastIndexOf (text3, 5, 0, StringComparison.OrdinalIgnoreCase), "#2-6");
2707
2708                 Assert.AreEqual (-1, text.LastIndexOf (text2, 7, 1, StringComparison.Ordinal), "#1-7");
2709                 Assert.AreEqual (-1, text.LastIndexOf (text3, 5, 1, StringComparison.OrdinalIgnoreCase), "#2-7");
2710
2711                 Assert.AreEqual (0, text.LastIndexOf (text4, 0, StringComparison.Ordinal), "#3-1");
2712                 Assert.AreEqual (0, text.LastIndexOf (text4, 0, StringComparison.OrdinalIgnoreCase), "#3-2");
2713
2714                 Assert.AreEqual (3, text.LastIndexOf (text4, 13, StringComparison.Ordinal), "#4-1");
2715                 Assert.AreEqual (3, text.LastIndexOf (text4, 13, StringComparison.OrdinalIgnoreCase), "#4-2");
2716
2717                 Assert.AreEqual (3, text.LastIndexOf (text4, 13, 14, StringComparison.Ordinal), "#4-1");
2718                 Assert.AreEqual (3, text.LastIndexOf (text4, 13, 14, StringComparison.OrdinalIgnoreCase), "#4-2");
2719
2720                 Assert.AreEqual (0, text.LastIndexOf (text4, 1, 2, StringComparison.Ordinal), "#5-1");
2721                 Assert.AreEqual (0, text.LastIndexOf (text4, 1, 2, StringComparison.OrdinalIgnoreCase), "#5-2");
2722
2723                 Assert.AreEqual (-1, "".LastIndexOf ("FOO", StringComparison.Ordinal));
2724                 Assert.AreEqual (0, "".LastIndexOf ("", StringComparison.Ordinal));
2725         }
2726
2727         [Test]
2728         public void LastIndexOfStringComparisonOrdinal ()
2729         {
2730                 string text = "testing123456";
2731                 Assert.AreEqual (10, text.LastIndexOf ("456", StringComparison.Ordinal), "#1");
2732                 Assert.AreEqual (-1, text.LastIndexOf ("4567", StringComparison.Ordinal), "#2");
2733                 Assert.AreEqual (0, text.LastIndexOf ("te", StringComparison.Ordinal), "#3");
2734                 Assert.AreEqual (2, text.LastIndexOf ("s", StringComparison.Ordinal), "#4");
2735                 Assert.AreEqual (-1, text.LastIndexOf ("ates", StringComparison.Ordinal), "#5");
2736                 Assert.AreEqual (-1, text.LastIndexOf ("S", StringComparison.Ordinal), "#6");
2737         }
2738
2739         [Test]
2740         public void LastIndexOfStringComparisonOrdinalIgnoreCase ()
2741         {
2742                 string text = "testing123456";
2743                 Assert.AreEqual (10, text.LastIndexOf ("456", StringComparison.OrdinalIgnoreCase), "#1");
2744                 Assert.AreEqual (-1, text.LastIndexOf ("4567", StringComparison.OrdinalIgnoreCase), "#2");
2745                 Assert.AreEqual (0, text.LastIndexOf ("te", StringComparison.OrdinalIgnoreCase), "#3");
2746                 Assert.AreEqual (2, text.LastIndexOf ("s", StringComparison.OrdinalIgnoreCase), "#4");
2747                 Assert.AreEqual (-1, text.LastIndexOf ("ates", StringComparison.OrdinalIgnoreCase), "#5");
2748                 Assert.AreEqual (2, text.LastIndexOf ("S", StringComparison.OrdinalIgnoreCase), "#6");
2749         }
2750
2751         [Test]
2752         public void LastIndexOf_Char_StartIndexStringLength ()
2753         {
2754                 string s = "Mono";
2755                 try {
2756                         s.LastIndexOf ('n', s.Length, 1);
2757                         Assert.Fail ("#1");
2758                 } catch (ArgumentOutOfRangeException ex) {
2759                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2760                         Assert.IsNull (ex.InnerException, "#3");
2761                         Assert.IsNotNull (ex.Message, "#4");
2762                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2763                 }
2764                 // this works for string but not for a char
2765         }
2766
2767         [Test]
2768         public void LastIndexOf_Char_StartIndexOverflow ()
2769         {
2770                 try {
2771                         "Mono".LastIndexOf ('o', Int32.MaxValue, 1);
2772                         Assert.Fail ("#1");
2773                 } catch (ArgumentOutOfRangeException ex) {
2774                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2775                         Assert.IsNull (ex.InnerException, "#3");
2776                         Assert.IsNotNull (ex.Message, "#4");
2777                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2778                 }
2779         }
2780
2781         [Test]
2782         public void LastIndexOf_Char_LengthOverflow ()
2783         {
2784                 try {
2785                         "Mono".LastIndexOf ('o', 1, Int32.MaxValue);
2786                         Assert.Fail ("#1");
2787                 } catch (ArgumentOutOfRangeException ex) {
2788                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2789                         Assert.IsNull (ex.InnerException, "#3");
2790                         Assert.IsNotNull (ex.Message, "#4");
2791                         Assert.AreEqual ("count", ex.ParamName, "#5");
2792                 }
2793         }
2794
2795         [Test]
2796         public void LastIndexOf_String_StartIndexStringLength ()
2797         {
2798                 string s = "Mono";
2799                 Assert.AreEqual (-1, s.LastIndexOf ("n", s.Length, 1));
2800                 // this works for string but not for a char
2801         }
2802
2803         [Test]
2804         public void LastIndexOf_String_StartIndexStringLength_Plus1 ()
2805         {
2806                 string s = "Mono";
2807                 try {
2808                         s.LastIndexOf ("n", s.Length + 1, 1);
2809                         Assert.Fail ("#1");
2810                 } catch (ArgumentOutOfRangeException ex) {
2811                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2812                         Assert.IsNull (ex.InnerException, "#3");
2813                         Assert.IsNotNull (ex.Message, "#4");
2814                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2815                 }
2816         }
2817
2818         [Test]
2819         public void LastIndexOf_String_StartIndexOverflow ()
2820         {
2821                 try {
2822                         "Mono".LastIndexOf ("no", Int32.MaxValue, 1);
2823                         Assert.Fail ("#1");
2824                 } catch (ArgumentOutOfRangeException ex) {
2825                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2826                         Assert.IsNull (ex.InnerException, "#3");
2827                         Assert.IsNotNull (ex.Message, "#4");
2828                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2829                 }
2830         }
2831
2832         [Test]
2833         public void LastIndexOf_String_LengthOverflow ()
2834         {
2835                 try {
2836                         "Mono".LastIndexOf ("no", 1, Int32.MaxValue);
2837                         Assert.Fail ("#1");
2838                 } catch (ArgumentOutOfRangeException ex) {
2839                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2840                         Assert.IsNull (ex.InnerException, "#3");
2841                         Assert.IsNotNull (ex.Message, "#4");
2842                         Assert.AreEqual ("count", ex.ParamName, "#5");
2843                 }
2844         }
2845
2846         [Test]
2847         public void LastIndexOfAny ()
2848         {
2849                 string s1 = ".bcdefghijklm";
2850
2851                 try {
2852                         s1.LastIndexOfAny (null);
2853                         Assert.Fail ("#A1");
2854                 } catch (ArgumentNullException ex) {
2855                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
2856                         Assert.IsNull (ex.InnerException, "#A3");
2857                         Assert.IsNotNull (ex.Message, "#A4");
2858                         Assert.IsNull (ex.ParamName, "#A5");
2859                 }
2860
2861                 try {
2862                         s1.LastIndexOfAny (null, s1.Length);
2863                         Assert.Fail ("#B1");
2864                 } catch (ArgumentNullException ex) {
2865                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
2866                         Assert.IsNull (ex.InnerException, "#B3");
2867                         Assert.IsNotNull (ex.Message, "#B4");
2868                         Assert.IsNull (ex.ParamName, "#B5");
2869                 }
2870
2871                 try {
2872                         s1.LastIndexOfAny (null, s1.Length, 1);
2873                         Assert.Fail ("#C1");
2874                 } catch (ArgumentNullException ex) {
2875                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
2876                         Assert.IsNull (ex.InnerException, "#C3");
2877                         Assert.IsNotNull (ex.Message, "#C4");
2878                         Assert.IsNull (ex.ParamName, "#C5");
2879                 }
2880
2881                 char[] c1 = {'a', 'e', 'i', 'o', 'u'};
2882                 Assert.AreEqual (8, s1.LastIndexOfAny (c1), "#D1");
2883                 Assert.AreEqual (4, s1.LastIndexOfAny (c1, 7), "#D2");
2884                 Assert.AreEqual (-1, s1.LastIndexOfAny (c1, 3), "#D3");
2885                 Assert.AreEqual (4, s1.LastIndexOfAny (c1, s1.Length - 6, 4), "#D4");
2886                 Assert.AreEqual (-1, s1.LastIndexOfAny (c1, s1.Length - 6, 3), "#D5");
2887
2888                 try {
2889                         s1.LastIndexOfAny (c1, -1);
2890                         Assert.Fail ("#E1");
2891                 } catch (ArgumentOutOfRangeException ex) {
2892                         // Index was out of range. Must be non-negative and
2893                         // less than the size of the collection
2894                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#E2");
2895                         Assert.IsNull (ex.InnerException, "#E3");
2896                         Assert.IsNotNull (ex.Message, "#E4");
2897                         Assert.AreEqual ("startIndex", ex.ParamName, "#E5");
2898                 }
2899
2900                 try {
2901                         s1.LastIndexOfAny (c1, -1, 1);
2902                         Assert.Fail ("#F1");
2903                 } catch (ArgumentOutOfRangeException ex) {
2904                         // Index was out of range. Must be non-negative and
2905                         // less than the size of the collection
2906                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#F2");
2907                         Assert.IsNull (ex.InnerException, "#F3");
2908                         Assert.IsNotNull (ex.Message, "#F4");
2909                         Assert.AreEqual ("startIndex", ex.ParamName, "#F5");
2910                 }
2911         }
2912
2913         [Test]
2914         public void LastIndexOfAny_Length_Overflow ()
2915         {
2916                 try {
2917                         "Mono".LastIndexOfAny (new char [1] { 'o' }, 1, Int32.MaxValue);
2918                         Assert.Fail ("#1");
2919                 } catch (ArgumentOutOfRangeException ex) {
2920                         // Count must be positive and count must refer to a
2921                         // location within the string/array/collection
2922                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2923                         Assert.IsNull (ex.InnerException, "#3");
2924                         Assert.IsNotNull (ex.Message, "#4");
2925                         Assert.AreEqual ("count", ex.ParamName, "#5");
2926                 }
2927         }
2928
2929         [Test]
2930         public void LastIndexOfAny_StartIndex_Overflow ()
2931         {
2932                 try {
2933                         "Mono".LastIndexOfAny (new char [1] { 'o' }, Int32.MaxValue, 1);
2934                         Assert.Fail ("#1");
2935                 } catch (ArgumentOutOfRangeException ex) {
2936                         // Index was out of range. Must be non-negative and
2937                         // less than the size of the collection
2938                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2939                         Assert.IsNull (ex.InnerException, "#3");
2940                         Assert.IsNotNull (ex.Message, "#4");
2941                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
2942                 }
2943         }
2944
2945         [Test] // PadLeft (Int32)
2946         public void PadLeft1 ()
2947         {
2948                 string s1 = "Hi!";
2949                 string result;
2950
2951                 result = s1.PadLeft (0);
2952                 Assert.AreSame (s1, result, "#A");
2953
2954                 result = s1.PadLeft (s1.Length - 1);
2955                 Assert.AreSame (s1, result, "#B");
2956
2957                 result = s1.PadLeft (s1.Length);
2958                 Assert.AreEqual (s1, result, "#C1");
2959                 Assert.IsTrue (!object.ReferenceEquals (s1, result), "#C2");
2960
2961                 result = s1.PadLeft (s1.Length + 1);
2962                 Assert.AreEqual (" Hi!", result, "#D");
2963         }
2964
2965         [Test] // PadLeft (Int32)
2966         public void PadLeft1_TotalWidth_Negative ()
2967         {
2968                 try {
2969                         "Mono".PadLeft (-1);
2970                         Assert.Fail ("#1");
2971                 } catch (ArgumentOutOfRangeException ex) {
2972                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
2973                         Assert.IsNull (ex.InnerException, "#3");
2974                         Assert.IsNotNull (ex.Message, "#4");
2975                         Assert.AreEqual ("totalWidth", ex.ParamName, "#5");
2976                 }
2977         }
2978
2979         [Test] // PadRight (Int32)
2980         public void PadRight1 ()
2981         {
2982                 string s1 = "Hi!";
2983                 string result;
2984
2985                 result = s1.PadRight (0);
2986                 Assert.AreSame (s1, result, "#A");
2987
2988                 result = s1.PadRight (s1.Length - 1);
2989                 Assert.AreSame (s1, result, "#B");
2990
2991                 result = s1.PadRight (s1.Length);
2992                 Assert.AreEqual (s1, result, "#C1");
2993                 Assert.IsTrue (!object.ReferenceEquals (s1, result), "#C2");
2994
2995                 result = s1.PadRight (s1.Length + 1);
2996                 Assert.AreEqual ("Hi! ", result, "#D");
2997         }
2998
2999         [Test] // PadRight1 (Int32)
3000         public void PadRight1_TotalWidth_Negative ()
3001         {
3002                 try {
3003                         "Mono".PadRight (-1);
3004                         Assert.Fail ("#1");
3005                 } catch (ArgumentOutOfRangeException ex) {
3006                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3007                         Assert.IsNull (ex.InnerException, "#3");
3008                         Assert.IsNotNull (ex.Message, "#4");
3009                         Assert.AreEqual ("totalWidth", ex.ParamName, "#5");
3010                 }
3011         }
3012
3013         [Test]
3014         public void PadRight2 ()
3015         {
3016                 Assert.AreEqual ("100000000000", "1".PadRight (12, '0'), "#1");
3017                 Assert.AreEqual ("000000000000", "".PadRight (12, '0'), "#2");
3018         }
3019
3020         [Test] // Remove (Int32, Int32)
3021         public void Remove2 ()
3022         {
3023                 string s1 = "original";
3024
3025                 try {
3026                         s1.Remove (-1, 1);
3027                         Assert.Fail ("#A1");
3028                 } catch (ArgumentOutOfRangeException ex) {
3029                         // StartIndex cannot be less than zero
3030                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3031                         Assert.IsNull (ex.InnerException, "#A3");
3032                         Assert.IsNotNull (ex.Message, "#A4");
3033                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
3034                 }
3035
3036                 try {
3037                         s1.Remove (1,-1);
3038                         Assert.Fail ("#B1");
3039                 } catch (ArgumentOutOfRangeException ex) {
3040                         // Count cannot be less than zero
3041                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3042                         Assert.IsNull (ex.InnerException, "#B3");
3043                         Assert.IsNotNull (ex.Message, "#B4");
3044                         Assert.AreEqual ("count", ex.ParamName, "#B5");
3045                 }
3046
3047                 try {
3048                         s1.Remove (s1.Length, s1.Length);
3049                         Assert.Fail ("#C1");
3050                 } catch (ArgumentOutOfRangeException ex) {
3051                         // Index and count must refer to a location within the
3052                         // string
3053                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
3054                         Assert.IsNull (ex.InnerException, "#C3");
3055                         Assert.IsNotNull (ex.Message, "#C4");
3056                         Assert.AreEqual ("count", ex.ParamName, "#C5");
3057                 }
3058
3059                 Assert.AreEqual ("oinal", s1.Remove(1, 3), "#D1");
3060                 Assert.AreEqual (s1, s1.Remove (0, 0), "#D2");
3061                 Assert.IsTrue (!object.ReferenceEquals (s1, s1.Remove (0, 0)), "#D3");
3062                 Assert.AreEqual ("riginal", s1.Remove (0, 1), "#D4");
3063                 Assert.AreEqual ("origina", s1.Remove (7, 1), "#D5");
3064         }
3065
3066         [Test] // Remove (Int32, Int32)
3067         public void Remove2_Length_Overflow ()
3068         {
3069                 try {
3070                         "Mono".Remove (1, Int32.MaxValue);
3071                         Assert.Fail ("#1");
3072                 } catch (ArgumentOutOfRangeException ex) {
3073                         // Index and count must refer to a location within the
3074                         // string
3075                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3076                         Assert.IsNull (ex.InnerException, "#3");
3077                         Assert.IsNotNull (ex.Message, "#4");
3078                         Assert.AreEqual ("count", ex.ParamName, "#5");
3079                 }
3080         }
3081
3082         [Test] // Remove (Int32, Int32)
3083         public void Remove2_StartIndex_Overflow ()
3084         {
3085                 try {
3086                         "Mono".Remove (Int32.MaxValue, 1);
3087                         Assert.Fail ("#1");
3088                 } catch (ArgumentOutOfRangeException ex) {
3089                         // Index and count must refer to a location within the
3090                         // string
3091                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3092                         Assert.IsNull (ex.InnerException, "#3");
3093                         Assert.IsNotNull (ex.Message, "#4");
3094                         Assert.AreEqual ("count", ex.ParamName, "#5");
3095                 }
3096         }
3097
3098         [Test] // Remove (Int32)
3099         public void Remove1_StartIndex_Negative ()
3100         {
3101                 try {
3102                         "ABC".Remove (-1);
3103                         Assert.Fail ("#1");
3104                 } catch (ArgumentOutOfRangeException ex) {
3105                         // StartIndex cannot be less than zero
3106                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3107                         Assert.IsNull (ex.InnerException, "#3");
3108                         Assert.IsNotNull (ex.Message, "#4");
3109                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3110                 }
3111         }
3112
3113         [Test] // Remove (Int32)
3114         public void Remove1_StartIndex_Overflow ()
3115         {
3116                 try {
3117                         "ABC".Remove (3);
3118                         Assert.Fail ("#1");
3119                 } catch (ArgumentOutOfRangeException ex) {
3120                         // startIndex must be less than length of string
3121                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3122                         Assert.IsNull (ex.InnerException, "#3");
3123                         Assert.IsNotNull (ex.Message, "#4");
3124                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3125                 }
3126         }
3127
3128         [Test] // Remove (Int32)
3129         public void Remove1 ()
3130         {
3131                 string s = "ABC";
3132
3133                 Assert.AreEqual ("AB", s.Remove (2), "#1");
3134                 Assert.AreEqual (string.Empty, s.Remove (0), "#2");
3135                 Assert.AreEqual ("A", s.Remove (1), "#3");
3136         }
3137
3138         [Test]
3139         public void Replace()
3140         {
3141                 string s1 = "original";
3142
3143                 Assert.AreEqual (s1, s1.Replace('q', 's'), "non-hit char");
3144                 Assert.AreEqual ("oxiginal", s1.Replace('r', 'x'), "single char");
3145                 Assert.AreEqual ("orxgxnal", s1.Replace('i', 'x'), "double char");
3146
3147                 bool errorThrown = false;
3148                 try {
3149                         string s = s1.Replace(null, "feh");
3150                 } catch (ArgumentNullException) {
3151                         errorThrown = true;
3152                 }
3153                 Assert.IsTrue (errorThrown, "should get null arg exception");
3154
3155                 Assert.AreEqual ("ornal", s1.Replace("igi", null), "replace as remove");
3156                 Assert.AreEqual (s1, s1.Replace("spam", "eggs"), "non-hit string");
3157                 Assert.AreEqual ("orirumal", s1.Replace("gin", "rum"), "single string");
3158                 Assert.AreEqual ("oreigeinal", s1.Replace("i", "ei"), "double string");
3159
3160                 Assert.AreEqual ("ooriginal", s1.Replace("o", "oo"), "start");
3161                 Assert.AreEqual ("originall", s1.Replace("l", "ll"), "end");
3162
3163                 Assert.AreEqual ("riginal", s1.Replace("o", string.Empty), "start empty");
3164                 Assert.AreEqual ("origina", s1.Replace("l", string.Empty), "end empty");
3165
3166                 Assert.AreEqual ("original", s1.Replace("original2", "original3"), "replace bigger that original");
3167
3168                 Assert.AreEqual (":!:", "::".Replace ("::", ":!:"), "result longer");
3169
3170                 // Test overlapping matches (bug #54988)
3171                 string s2 = "...aaaaaaa.bbbbbbbbb,............ccccccc.u...";
3172                 Assert.AreEqual (s2.Replace("..", "."), "..aaaaaaa.bbbbbbbbb,......ccccccc.u..");
3173
3174                 // Test replacing null characters (bug #67395)
3175 #if !TARGET_JVM //bug #7276
3176                 Assert.AreEqual ("is this ok ?", "is \0 ok ?".Replace ("\0", "this"), "should not strip content after nullchar");
3177 #endif
3178         }
3179
3180         [Test]
3181         public void ReplaceStringBeginEndTest ()
3182         {
3183                 string s1 = "original";
3184
3185                 Assert.AreEqual ("riginal", s1.Replace ("o", ""), "#1");
3186                 Assert.AreEqual ("origina", s1.Replace ("l", ""), "#2");
3187                 Assert.AreEqual ("ariginal", s1.Replace ("o", "a"), "#3");
3188                 Assert.AreEqual ("originaa", s1.Replace ("l", "a"), "#4");
3189                 Assert.AreEqual ("aariginal", s1.Replace ("o", "aa"), "#5");
3190                 Assert.AreEqual ("originaaa", s1.Replace ("l", "aa"), "#6");
3191                 Assert.AreEqual ("original", s1.Replace ("o", "o"), "#7");
3192                 Assert.AreEqual ("original", s1.Replace ("l", "l"), "#8");
3193                 Assert.AreEqual ("original", s1.Replace ("original", "original"), "#9");
3194                 Assert.AreEqual ("", s1.Replace ("original", ""), "#10");
3195         }
3196
3197         [Test]
3198         public void ReplaceStringBeginEndTestFallback ()
3199         {
3200                 string prev = new String ('o', 300);
3201                 string s1 = prev + "riginal";
3202
3203                 Assert.AreEqual ("riginal", s1.Replace ("o", ""), "#1");
3204                 Assert.AreEqual (prev + "rigina", s1.Replace ("l", ""), "#2");
3205                 Assert.AreEqual (new String ('a', 300) + "riginal", s1.Replace ("o", "a"), "#3");
3206                 Assert.AreEqual (prev + "riginaa", s1.Replace ("l", "a"), "#4");
3207                 Assert.AreEqual (new String ('a', 600) + "riginal", s1.Replace ("o", "aa"), "#5");
3208                 Assert.AreEqual (prev + "riginaaa", s1.Replace ("l", "aa"), "#6");
3209                 Assert.AreEqual (s1, s1.Replace ("o", "o"), "#7");
3210                 Assert.AreEqual (s1, s1.Replace ("l", "l"), "#8");
3211                 Assert.AreEqual (s1, s1.Replace (s1, s1), "#9");
3212                 Assert.AreEqual ("", s1.Replace (prev + "riginal", ""), "#10");
3213         }
3214
3215         [Test]
3216         public void ReplaceStringOffByOne ()
3217         {
3218                 Assert.AreEqual ("", new String ('o', 199).Replace ("o", ""), "#-1");
3219                 Assert.AreEqual ("", new String ('o', 200).Replace ("o", ""), "#0");
3220                 Assert.AreEqual ("", new String ('o', 201).Replace ("o", ""), "#+1");
3221         }
3222
3223         [Test]
3224         public void ReplaceStringCultureTests ()
3225         {
3226                 // LAMESPEC: According to MSDN Replace with String parameter is culture-senstive.
3227                 // However this does not currently seem to be the case. Otherwise following code should
3228                 // produce "check" instead of "AE"
3229
3230                 CultureInfo old = Thread.CurrentThread.CurrentCulture;
3231                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3232                 Assert.AreEqual ("AE", "AE".Replace ("\u00C6", "check"), "#1");
3233                 Thread.CurrentThread.CurrentCulture = old;
3234         }
3235
3236         [Test] // StartsWith (String)
3237         public void StartsWith1 ()
3238         {
3239                 string s1 = "original";
3240                 
3241                 Assert.IsTrue (s1.StartsWith ("o"), "#1");
3242                 Assert.IsTrue (s1.StartsWith ("orig"), "#2");
3243                 Assert.IsTrue (!s1.StartsWith ("rig"), "#3");
3244                 Assert.IsTrue (s1.StartsWith (String.Empty), "#4");
3245                 Assert.IsTrue (String.Empty.StartsWith (String.Empty), "#5");
3246                 Assert.IsTrue (!String.Empty.StartsWith ("rig"), "#6");
3247         }
3248
3249         [Test] // StartsWith (String)
3250         public void StartsWith1_Value_Null ()
3251         {
3252                 try {
3253                         "A".StartsWith (null);
3254                         Assert.Fail ("#1");
3255                 } catch (ArgumentNullException ex) {
3256                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3257                         Assert.IsNull (ex.InnerException, "#3");
3258                         Assert.IsNotNull (ex.Message, "#4");
3259                         Assert.AreEqual ("value", ex.ParamName, "#5");
3260                 }
3261         }
3262
3263         [Test] // StartsWith (String, StringComparison)
3264         public void StartsWith2_ComparisonType_Invalid ()
3265         {
3266                 try {
3267                         "ABC".StartsWith ("A", (StringComparison) 80);
3268                         Assert.Fail ("#1");
3269                 } catch (ArgumentException ex) {
3270                         // The string comparison type passed in is currently
3271                         // not supported
3272                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
3273                         Assert.IsNull (ex.InnerException, "#3");
3274                         Assert.IsNotNull (ex.Message, "#4");
3275                         Assert.AreEqual ("comparisonType", ex.ParamName, "#5");
3276                 }
3277         }
3278
3279         [Test] // StartsWith (String, StringComparison)
3280         public void StartsWith2_Value_Null ()
3281         {
3282                 try {
3283                         "A".StartsWith (null, StringComparison.CurrentCulture);
3284                         Assert.Fail ("#1");
3285                 } catch (ArgumentNullException ex) {
3286                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
3287                         Assert.IsNull (ex.InnerException, "#3");
3288                         Assert.IsNotNull (ex.Message, "#4");
3289                         Assert.AreEqual ("value", ex.ParamName, "#5");
3290                 }
3291         }
3292
3293         [Test] // StartsWith (String, Boolean, CultureInfo)
3294         public void StartsWith3_Culture_Null ()
3295         {
3296                 // This should not crash
3297                 string s = "boo";
3298
3299                 s.StartsWith ("this", true, null);
3300         }
3301
3302         [Test] // SubString (Int32)
3303         public void Substring1 ()
3304         {
3305                 string s = "original";
3306
3307                 Assert.AreEqual ("inal", s.Substring (4), "#1");
3308                 Assert.AreEqual (string.Empty, s.Substring (s.Length), "#2");
3309                 Assert.AreSame (s, s.Substring (0), "#3");
3310         }
3311
3312         [Test] // SubString (Int32)
3313         public void SubString1_StartIndex_Negative ()
3314         {
3315                 string s = "original";
3316
3317                 try {
3318                         s.Substring (-1);
3319                         Assert.Fail ("#1");
3320                 } catch (ArgumentOutOfRangeException ex) {
3321                         // StartIndex cannot be less than zero
3322                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3323                         Assert.IsNull (ex.InnerException, "#3");
3324                         Assert.IsNotNull (ex.Message, "#4");
3325                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3326                 }
3327         }
3328
3329         [Test] // SubString (Int32)
3330         public void SubString1_StartIndex_Overflow ()
3331         {
3332                 string s = "original";
3333
3334                 try {
3335                         s.Substring (s.Length + 1);
3336                         Assert.Fail ("#1");
3337                 } catch (ArgumentOutOfRangeException ex) {
3338                         // startIndex cannot be larger than length of string
3339                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3340                         Assert.IsNull (ex.InnerException, "#3");
3341                         Assert.IsNotNull (ex.Message, "#4");
3342                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3343                 }
3344         }
3345
3346         [Test] // SubString (Int32, Int32)
3347         public void Substring2 ()
3348         {
3349                 string s = "original";
3350
3351                 Assert.AreEqual ("igin", s.Substring (2, 4), "#1");
3352                 Assert.AreEqual (string.Empty, s.Substring (s.Length, 0), "#2");
3353                 Assert.AreEqual ("origina", s.Substring (0, s.Length - 1), "#3");
3354                 Assert.AreEqual (s, s.Substring (0, s.Length), "#4");
3355                 Assert.AreSame (s, s.Substring (0, s.Length), "#5");
3356         }
3357
3358         [Test] // SubString (Int32, Int32)
3359         public void SubString2_Length_Negative ()
3360         {
3361                 string s = "original";
3362
3363                 try {
3364                         s.Substring (1, -1);
3365                         Assert.Fail ("#1");
3366                 } catch (ArgumentOutOfRangeException ex) {
3367                         // Length cannot be less than zero
3368                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3369                         Assert.IsNull (ex.InnerException, "#3");
3370                         Assert.IsNotNull (ex.Message, "#4");
3371                         Assert.AreEqual ("length", ex.ParamName, "#5");
3372                 }
3373         }
3374         
3375         [Test] // SubString (Int32, Int32)
3376         public void Substring2_Length_Overflow ()
3377         {
3378                 string s = "original";
3379
3380                 try {
3381                         s.Substring (s.Length, 1);
3382                         Assert.Fail ("#A1");
3383                 } catch (ArgumentOutOfRangeException ex) {
3384                         // Index and length must refer to a location within
3385                         // the string
3386                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3387                         Assert.IsNull (ex.InnerException, "#A3");
3388                         Assert.IsNotNull (ex.Message, "#A4");
3389                         Assert.AreEqual ("length", ex.ParamName, "#A5");
3390                 }
3391
3392                 try {
3393                         s.Substring (1, s.Length);
3394                         Assert.Fail ("#B1");
3395                 } catch (ArgumentOutOfRangeException ex) {
3396                         // Index and length must refer to a location within
3397                         // the string
3398                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3399                         Assert.IsNull (ex.InnerException, "#B3");
3400                         Assert.IsNotNull (ex.Message, "#B4");
3401                         Assert.AreEqual ("length", ex.ParamName, "#B5");
3402                 }
3403
3404                 try {
3405                         s.Substring (1, Int32.MaxValue);
3406                         Assert.Fail ("#C1");
3407                 } catch (ArgumentOutOfRangeException ex) {
3408                         // Index and length must refer to a location within
3409                         // the string
3410                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#C2");
3411                         Assert.IsNull (ex.InnerException, "#C3");
3412                         Assert.IsNotNull (ex.Message, "#C4");
3413                         Assert.AreEqual ("length", ex.ParamName, "#C5");
3414                 }
3415         }
3416
3417         [Test] // SubString (Int32, Int32)
3418         public void SubString2_StartIndex_Negative ()
3419         {
3420                 string s = "original";
3421
3422                 try {
3423                         s.Substring (-1, 1);
3424                         Assert.Fail ("#1");
3425                 } catch (ArgumentOutOfRangeException ex) {
3426                         // StartIndex cannot be less than zero
3427                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3428                         Assert.IsNull (ex.InnerException, "#3");
3429                         Assert.IsNotNull (ex.Message, "#4");
3430                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3431                 }
3432         }
3433
3434         [Test] // SubString (Int32, Int32)
3435         public void Substring2_StartIndex_Overflow ()
3436         {
3437                 string s = "original";
3438
3439                 try {
3440                         s.Substring (s.Length + 1, 0);
3441                         Assert.Fail ("#A1");
3442                 } catch (ArgumentOutOfRangeException ex) {
3443                         // startIndex cannot be larger than length of string
3444                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3445                         Assert.IsNull (ex.InnerException, "#A3");
3446                         Assert.IsNotNull (ex.Message, "#A4");
3447                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
3448                 }
3449
3450                 try {
3451                         "Mono".Substring (Int32.MaxValue, 1);
3452                         Assert.Fail ("#B1");
3453                 } catch (ArgumentOutOfRangeException ex) {
3454                         // startIndex cannot be larger than length of string
3455                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3456                         Assert.IsNull (ex.InnerException, "#B3");
3457                         Assert.IsNotNull (ex.Message, "#B4");
3458                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
3459                 }
3460         }
3461
3462         [Test]
3463         public void ToCharArray ()
3464         {
3465                 const string s = "original";
3466                 char [] c;
3467
3468                 c = s.ToCharArray ();
3469                 Assert.AreEqual (s.Length, c.Length, "#A1");
3470                 Assert.AreEqual (s, new String (c), "#A2");
3471
3472                 c = s.ToCharArray (0, s.Length);
3473                 Assert.AreEqual (s.Length, c.Length, "#B1");
3474                 Assert.AreEqual (s, new String (c), "#B2");
3475
3476                 c = s.ToCharArray (1, s.Length - 1);
3477                 Assert.AreEqual (7, c.Length, "#C1");
3478                 Assert.AreEqual ("riginal", new String (c), "#C2");
3479
3480                 c = s.ToCharArray (0, 3);
3481                 Assert.AreEqual (3, c.Length, "#D1");
3482                 Assert.AreEqual ("ori", new String (c), "#D2");
3483
3484                 c = s.ToCharArray (2, 0);
3485                 Assert.AreEqual (0, c.Length, "#E1");
3486                 Assert.AreEqual (string.Empty, new String (c), "#E2");
3487
3488                 c = s.ToCharArray (3, 2);
3489                 Assert.AreEqual (2, c.Length, "#F1");
3490                 Assert.AreEqual ("gi", new String (c), "#F2");
3491
3492                 c = s.ToCharArray (s.Length, 0);
3493                 Assert.AreEqual (0, c.Length, "#G1");
3494                 Assert.AreEqual (string.Empty, new String (c), "#G2");
3495         }
3496
3497         [Test]
3498         public void ToCharArray_Length_Negative ()
3499         {
3500                 const string s = "original";
3501
3502                 try {
3503                         s.ToCharArray (1, -1);
3504                         Assert.Fail ("#1");
3505                 } catch (ArgumentOutOfRangeException ex) {
3506                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3507                         Assert.IsNull (ex.InnerException, "#3");
3508                         Assert.IsNotNull (ex.Message, "#4");
3509                         Assert.AreEqual ("length", ex.ParamName, "#5");
3510                 }
3511         }
3512
3513         [Test]
3514         public void ToCharArray_Length_Overflow ()
3515         {
3516                 const string s = "original";
3517
3518                 try {
3519                         s.ToCharArray (1, s.Length);
3520                         Assert.Fail ("#A1");
3521                 } catch (ArgumentOutOfRangeException ex) {
3522                         // Index was out of range. Must be non-negative and
3523                         // less than the size of the collection
3524                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3525                         Assert.IsNull (ex.InnerException, "#A3");
3526                         Assert.IsNotNull (ex.Message, "#A4");
3527                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
3528                 }
3529
3530                 try {
3531                         s.ToCharArray (1, Int32.MaxValue);
3532                         Assert.Fail ("#B1");
3533                 } catch (ArgumentOutOfRangeException ex) {
3534                         // Index was out of range. Must be non-negative and
3535                         // less than the size of the collection
3536                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3537                         Assert.IsNull (ex.InnerException, "#B3");
3538                         Assert.IsNotNull (ex.Message, "#B4");
3539                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
3540                 }
3541         }
3542
3543         [Test]
3544         public void ToCharArray_StartIndex_Negative ()
3545         {
3546                 const string s = "original";
3547
3548                 try {
3549                         s.ToCharArray (-1, 1);
3550                         Assert.Fail ("#1");
3551                 } catch (ArgumentOutOfRangeException ex) {
3552                         // Index was out of range. Must be non-negative and
3553                         // less than the size of the collection
3554                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3555                         Assert.IsNull (ex.InnerException, "#3");
3556                         Assert.IsNotNull (ex.Message, "#4");
3557                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3558                 }
3559         }
3560
3561         [Test]
3562         public void ToCharArray_StartIndex_Overflow ()
3563         {
3564                 const string s = "original";
3565
3566                 try {
3567                         s.ToCharArray (s.Length, 1);
3568                         Assert.Fail ("#A1");
3569                 } catch (ArgumentOutOfRangeException ex) {
3570                         // Index was out of range. Must be non-negative and
3571                         // less than the size of the collection
3572                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
3573                         Assert.IsNull (ex.InnerException, "#A3");
3574                         Assert.IsNotNull (ex.Message, "#A4");
3575                         Assert.AreEqual ("startIndex", ex.ParamName, "#A5");
3576                 }
3577
3578                 try {
3579                         s.ToCharArray (Int32.MaxValue, 1);
3580                         Assert.Fail ("#B1");
3581                 } catch (ArgumentOutOfRangeException ex) {
3582                         // Index was out of range. Must be non-negative and
3583                         // less than the size of the collection
3584                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
3585                         Assert.IsNull (ex.InnerException, "#B3");
3586                         Assert.IsNotNull (ex.Message, "#B4");
3587                         Assert.AreEqual ("startIndex", ex.ParamName, "#B5");
3588                 }
3589         }
3590
3591         [Test] // ToLower ()
3592         public void ToLower1 ()
3593         {
3594                 string s = "OrIgInAli";
3595
3596                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
3597
3598                 Assert.AreEqual ("\u006f\u0072\u0131\u0067\u0131\u006e\u0061\u006c\u0069", s.ToLower(), "#1");
3599
3600                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3601
3602                 Assert.AreEqual ("originali", s.ToLower (), "#2");
3603         }
3604
3605         [Test] // ToLower (CultureInfo)
3606         public void ToLower2 ()
3607         {
3608                 string s = "OrIgInAli";
3609
3610                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
3611
3612                 Assert.AreEqual ("originali", s.ToLower (new CultureInfo ("en-US")), "#A1");
3613                 Assert.AreEqual ("\u006f\u0072\u0131\u0067\u0131\u006e\u0061\u006c\u0069", s.ToLower (new CultureInfo ("tr-TR")), "#A2");
3614                 Assert.AreEqual (string.Empty, string.Empty.ToLower (new CultureInfo ("en-US")), "#A3");
3615                 Assert.AreEqual (string.Empty, string.Empty.ToLower (new CultureInfo ("tr-TR")), "#A4");
3616
3617                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3618
3619                 Assert.AreEqual ("originali", s.ToLower (new CultureInfo ("en-US")), "#B1");
3620                 Assert.AreEqual ("\u006f\u0072\u0131\u0067\u0131\u006e\u0061\u006c\u0069", s.ToLower (new CultureInfo ("tr-TR")), "#B2");
3621                 Assert.AreEqual (string.Empty, string.Empty.ToLower (new CultureInfo ("en-US")), "#B3");
3622                 Assert.AreEqual (string.Empty, string.Empty.ToLower (new CultureInfo ("tr-TR")), "#B4");
3623         }
3624
3625         [Test] // ToLower (CultureInfo)
3626         public void ToLower2_Culture_Null ()
3627         {
3628                 string s = "OrIgInAl";
3629
3630                 try {
3631                         s.ToLower ((CultureInfo) null);
3632                         Assert.Fail ("#A1");
3633                 } catch (ArgumentNullException ex) {
3634                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
3635                         Assert.IsNull (ex.InnerException, "#A3");
3636                         Assert.IsNotNull (ex.Message, "#A4");
3637                         Assert.AreEqual ("culture", ex.ParamName, "#A5");
3638                 }
3639
3640                 try {
3641                         string.Empty.ToLower ((CultureInfo) null);
3642                         Assert.Fail ("#B1");
3643                 } catch (ArgumentNullException ex) {
3644                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
3645                         Assert.IsNull (ex.InnerException, "#B3");
3646                         Assert.IsNotNull (ex.Message, "#B4");
3647                         Assert.AreEqual ("culture", ex.ParamName, "#B5");
3648                 }
3649         }
3650
3651         [Test]
3652         public void TestToString ()
3653         {
3654                 string s1 = "OrIgInAli";
3655                 Assert.AreEqual (s1, s1.ToString(), "ToString failed!");
3656         }
3657
3658         [Test] // ToUpper ()
3659         public void ToUpper1 ()
3660         {
3661                 string s = "OrIgInAli";
3662
3663                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
3664
3665                 Assert.AreEqual ("ORIGINAL\u0130", s.ToUpper (), "#1");
3666
3667                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3668
3669                 Assert.AreEqual ("ORIGINALI", s.ToUpper (), "#2");
3670         }
3671
3672         [Test] // ToUpper (CultureInfo)
3673         public void ToUpper2 ()
3674         {
3675                 string s = "OrIgInAli";
3676
3677                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("tr-TR");
3678
3679                 Assert.AreEqual ("ORIGINALI", s.ToUpper (new CultureInfo ("en-US")), "#A1");
3680                 Assert.AreEqual ("ORIGINAL\u0130", s.ToUpper (new CultureInfo ("tr-TR")), "#A2");
3681                 Assert.AreEqual (string.Empty, string.Empty.ToUpper (new CultureInfo ("en-US")), "#A3");
3682                 Assert.AreEqual (string.Empty, string.Empty.ToUpper (new CultureInfo ("tr-TR")), "#A4");
3683
3684                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
3685
3686                 Assert.AreEqual ("ORIGINALI", s.ToUpper (new CultureInfo ("en-US")), "#B1");
3687                 Assert.AreEqual ("ORIGINAL\u0130", s.ToUpper (new CultureInfo ("tr-TR")), "#B2");
3688                 Assert.AreEqual (string.Empty, string.Empty.ToUpper (new CultureInfo ("en-US")), "#B3");
3689                 Assert.AreEqual (string.Empty, string.Empty.ToUpper (new CultureInfo ("tr-TR")), "#B4");
3690         }
3691
3692         [Test] // ToUpper (CultureInfo)
3693         public void ToUpper2_Culture_Null ()
3694         {
3695                 string s = "OrIgInAl";
3696
3697                 try {
3698                         s.ToUpper ((CultureInfo) null);
3699                         Assert.Fail ("#A1");
3700                 } catch (ArgumentNullException ex) {
3701                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
3702                         Assert.IsNull (ex.InnerException, "#A3");
3703                         Assert.IsNotNull (ex.Message, "#A4");
3704                         Assert.AreEqual ("culture", ex.ParamName, "#A5");
3705                 }
3706
3707                 try {
3708                         string.Empty.ToUpper ((CultureInfo) null);
3709                         Assert.Fail ("#B1");
3710                 } catch (ArgumentNullException ex) {
3711                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
3712                         Assert.IsNull (ex.InnerException, "#B3");
3713                         Assert.IsNotNull (ex.Message, "#B4");
3714                         Assert.AreEqual ("culture", ex.ParamName, "#B5");
3715                 }
3716         }
3717
3718         [Test]
3719         public void TestTrim ()
3720         {
3721                 string s1 = "  original\t\n";
3722                 Assert.AreEqual ("original", s1.Trim(), "basic trim failed");
3723                 Assert.AreEqual ("original", s1.Trim(null), "basic trim failed");
3724
3725                 s1 = "original";
3726                 Assert.AreEqual ("original", s1.Trim(), "basic trim failed");
3727                 Assert.AreEqual ("original", s1.Trim(null), "basic trim failed");
3728
3729                 s1 = "   \t \n  ";
3730                 Assert.AreEqual (string.Empty, s1.Trim(), "empty trim failed");
3731                 Assert.AreEqual (string.Empty, s1.Trim(null), "empty trim failed");
3732
3733                 s1 = "aaaoriginalbbb";
3734                 char[] delims = {'a', 'b'};
3735                 Assert.AreEqual ("original", s1.Trim(delims), "custom trim failed");
3736
3737                 Assert.AreEqual ("original", "\u2028original\u2029".Trim (), "net_2_0 additional char#1");
3738                 Assert.AreEqual ("original", "\u0085original\u1680".Trim (), "net_2_0 additional char#2");
3739
3740 #if NET_4_0
3741                 Assert.AreEqual ("", "\x9\xa\xb\xc\xd\x20\x85\xa0\x1680\x180e\x2000\x2001\x2002\x2003\x2004\x2005\x2006\x2007\x2008\x2009\x200a\x2028\x2029\x202f\x205f\x3000".Trim (), "net_4_0 changes #1");
3742 #endif
3743         }
3744
3745         [Test]
3746         public void TestTrimEnd ()
3747         {
3748                 string s1 = "  original\t\n";
3749                 Assert.AreEqual ("  original", s1.TrimEnd(null), "basic TrimEnd failed");
3750
3751                 s1 = "  original";
3752                 Assert.AreEqual ("  original", s1.TrimEnd(null), "basic TrimEnd failed");
3753
3754                 s1 = "  \t  \n  \n    ";
3755                 Assert.AreEqual (string.Empty, s1.TrimEnd(null), "empty TrimEnd failed");
3756
3757                 s1 = "aaaoriginalbbb";
3758                 char[] delims = {'a', 'b'};
3759                 Assert.AreEqual ("aaaoriginal", s1.TrimEnd(delims), "custom TrimEnd failed");
3760         }
3761
3762         [Test]
3763         public void TestTrimStart ()
3764         {
3765                 string s1 = "  original\t\n";
3766                 Assert.AreEqual ("original\t\n", s1.TrimStart(null), "basic TrimStart failed");
3767
3768                 s1 = "original\t\n";
3769                 Assert.AreEqual ("original\t\n", s1.TrimStart(null), "basic TrimStart failed");
3770
3771                 s1 = "    \t \n \n  ";
3772                 Assert.AreEqual (string.Empty, s1.TrimStart(null), "empty TrimStart failed");
3773
3774                 s1 = "aaaoriginalbbb";
3775                 char[] delims = {'a', 'b'};
3776                 Assert.AreEqual ("originalbbb", s1.TrimStart(delims), "custom TrimStart failed");
3777         }
3778
3779         [Test]
3780         public void TestChars ()
3781         {
3782                 string s;
3783
3784                 s = string.Empty;
3785                 try {
3786                         char c = s [0];
3787                         Assert.Fail ("#A1:" + c);
3788                 } catch (IndexOutOfRangeException ex) {
3789                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
3790                         Assert.IsNull (ex.InnerException, "#A3");
3791                         Assert.IsNotNull (ex.Message, "#A4");
3792                 }
3793
3794                 s = "A";
3795                 try {
3796                         char c = s [-1];
3797                         Assert.Fail ("#B1:" + c);
3798                 } catch (IndexOutOfRangeException ex) {
3799                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
3800                         Assert.IsNull (ex.InnerException, "#B3");
3801                         Assert.IsNotNull (ex.Message, "#B4");
3802                 }
3803         }
3804
3805         [Test]
3806         public void TestComparePeriod ()
3807         {
3808                 // according to bug 63981, this behavior is for all cultures
3809                 Assert.AreEqual (-1, String.Compare ("foo.obj", "foobar.obj", false), "#1");
3810         }
3811
3812         [Test]
3813         public void LastIndexOfAnyBounds1 ()
3814         {
3815                 string mono = "Mono";
3816                 char [] k = { 'M' };
3817                 try {
3818                         mono.LastIndexOfAny (k, mono.Length, 1);
3819                         Assert.Fail ("#1");
3820                 } catch (ArgumentOutOfRangeException ex) {
3821                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3822                         Assert.IsNull (ex.InnerException, "#3");
3823                         Assert.IsNotNull (ex.Message, "#4");
3824                         Assert.AreEqual ("startIndex", ex.ParamName, "#5");
3825                 }
3826         }
3827
3828         [Test]
3829         public void TestSplit ()
3830         {
3831                 string s1 = "abcdefghijklm";
3832                 char[] c1 = {'q', 'r'};
3833                 Assert.AreEqual (s1, (s1.Split(c1))[0], "No splitters");
3834
3835                 char[] c2 = {'a', 'e', 'i', 'o', 'u'};
3836                 string[] chunks = s1.Split(c2);
3837                 Assert.AreEqual (string.Empty, chunks[0], "First chunk");
3838                 Assert.AreEqual ("bcd", chunks[1], "Second chunk");
3839                 Assert.AreEqual ("fgh", chunks[2], "Third chunk");
3840                 Assert.AreEqual ("jklm", chunks[3], "Fourth chunk");
3841
3842                 {
3843                         bool errorThrown = false;
3844                         try {
3845                                 chunks = s1.Split(c2, -1);
3846                         } catch (ArgumentOutOfRangeException) {
3847                                 errorThrown = true;
3848                         }
3849                         Assert.IsTrue (errorThrown, "Split out of range");
3850                 }
3851
3852                 chunks = s1.Split(c2, 2);
3853                 Assert.AreEqual (2, chunks.Length, "Limited chunk");
3854                 Assert.AreEqual (string.Empty, chunks[0], "First limited chunk");
3855                 Assert.AreEqual ("bcdefghijklm", chunks[1], "Second limited chunk");
3856
3857                 string s3 = "1.0";
3858                 char[] c3 = {'.'};
3859                 chunks = s3.Split(c3,2);
3860                 Assert.AreEqual (2, chunks.Length, "1.0 split length");
3861                 Assert.AreEqual ("1", chunks[0], "1.0 split first chunk");
3862                 Assert.AreEqual ("0", chunks[1], "1.0 split second chunk");
3863
3864                 string s4 = "1.0.0";
3865                 char[] c4 = {'.'};
3866                 chunks = s4.Split(c4,2);
3867                 Assert.AreEqual (2, chunks.Length, "1.0.0 split length");
3868                 Assert.AreEqual ("1", chunks[0], "1.0.0 split first chunk");
3869                 Assert.AreEqual ("0.0", chunks[1], "1.0.0 split second chunk");
3870
3871                 string s5 = ".0.0";
3872                 char[] c5 = {'.'};
3873                 chunks = s5.Split (c5, 2);
3874                 Assert.AreEqual (2, chunks.Length, ".0.0 split length");
3875                 Assert.AreEqual (string.Empty, chunks[0], ".0.0 split first chunk");
3876                 Assert.AreEqual ("0.0", chunks[1], ".0.0 split second chunk");
3877
3878                 string s6 = ".0";
3879                 char[] c6 = {'.'};
3880                 chunks = s6.Split (c6, 2);
3881                 Assert.AreEqual (2, chunks.Length, ".0 split length");
3882                 Assert.AreEqual (string.Empty, chunks[0], ".0 split first chunk");
3883                 Assert.AreEqual ("0", chunks[1], ".0 split second chunk");
3884
3885                 string s7 = "0.";
3886                 char[] c7 = {'.'};
3887                 chunks = s7.Split (c7, 2);
3888                 Assert.AreEqual (2, chunks.Length, "0. split length");
3889                 Assert.AreEqual ("0", chunks[0], "0. split first chunk");
3890                 Assert.AreEqual (string.Empty, chunks[1], "0. split second chunk");
3891
3892                 string s8 = "0.0000";
3893                 char[] c8 = {'.'};
3894                 chunks = s8.Split (c8, 2);
3895                 Assert.AreEqual (2, chunks.Length, "0.0000/2 split length");
3896                 Assert.AreEqual ("0", chunks[0], "0.0000/2 split first chunk");
3897                 Assert.AreEqual ("0000", chunks[1], "0.0000/2 split second chunk");
3898
3899                 chunks = s8.Split (c8, 3);
3900                 Assert.AreEqual (2, chunks.Length, "0.0000/3 split length");
3901                 Assert.AreEqual ("0", chunks[0], "0.0000/3 split first chunk");
3902                 Assert.AreEqual ("0000", chunks[1], "0.0000/3 split second chunk");
3903
3904                 chunks = s8.Split (c8, 1);
3905                 Assert.AreEqual (1, chunks.Length, "0.0000/1 split length");
3906                 Assert.AreEqual ("0.0000", chunks[0], "0.0000/1 split first chunk");
3907
3908                 chunks = s1.Split(c2, 1);
3909                 Assert.AreEqual (1, chunks.Length, "Single split");
3910                 Assert.AreEqual (s1, chunks[0], "Single chunk");
3911
3912                 chunks = s1.Split(c2, 0);
3913                 Assert.AreEqual (0, chunks.Length, "Zero split");
3914
3915 #if NET_4_0
3916                 Assert.AreEqual (0, "\x9\xa\xb\xc\xd\x20\x85\xa0\x1680\x180e\x2000\x2001\x2002\x2003\x2004\x2005\x2006\x2007\x2008\x2009\x200a\x2028\x2029\x202f\x205f\x3000".Split ((char[]) null, StringSplitOptions.RemoveEmptyEntries).Length, "net_4_0 changes");
3917 #endif
3918         }
3919
3920         [Test]
3921         public void MoreSplit ()
3922         {
3923                 string test = "123 456 789";
3924                 string [] st = test.Split ();
3925                 Assert.AreEqual ("123", st [0], "#01");
3926                 st = test.Split (null);
3927                 Assert.AreEqual ("123", st [0], "#02");
3928
3929                 Assert.AreEqual (1, "encyclopædia".Split (new[] { "ae" }, StringSplitOptions.None).Length, "#03");
3930         }
3931
3932         [Test] // Split (Char [], StringSplitOptions)
3933         public void Split3_Options_Invalid ()
3934         {
3935                 try {
3936                         "A B".Split (new Char [] { 'A' }, (StringSplitOptions) 4096);
3937                         Assert.Fail ("#1");
3938                 } catch (ArgumentException ex) {
3939                         // Illegal enum value: 4096
3940                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
3941                         Assert.IsNull (ex.InnerException, "#3");
3942                         Assert.IsNotNull (ex.Message, "#4");
3943                         Assert.IsTrue (ex.Message.IndexOf ("4096") != 1, "#5");
3944                         Assert.IsNull (ex.ParamName, "#6");
3945                 }
3946         }
3947
3948         [Test] // Split (Char [], StringSplitOptions)
3949         public void Split4_Options_Invalid ()
3950         {
3951                 try {
3952                         "A B".Split (new String [] { "A" }, (StringSplitOptions) 4096);
3953                         Assert.Fail ("#1");
3954                 } catch (ArgumentException ex) {
3955                         // Illegal enum value: 4096
3956                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
3957                         Assert.IsNull (ex.InnerException, "#3");
3958                         Assert.IsNotNull (ex.Message, "#4");
3959                         Assert.IsTrue (ex.Message.IndexOf ("4096") != 1, "#5");
3960                         Assert.IsNull (ex.ParamName, "#6");
3961                 }
3962         }
3963
3964         [Test] // Split (Char [], StringSplitOptions)
3965         public void Split5_Options_Invalid ()
3966         {
3967                 try {
3968                         "A B".Split (new Char [] { 'A' }, 0, (StringSplitOptions) 4096);
3969                         Assert.Fail ("#1");
3970                 } catch (ArgumentException ex) {
3971                         // Illegal enum value: 4096
3972                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
3973                         Assert.IsNull (ex.InnerException, "#3");
3974                         Assert.IsNotNull (ex.Message, "#4");
3975                         Assert.IsTrue (ex.Message.IndexOf ("4096") != 1, "#5");
3976                         Assert.IsNull (ex.ParamName, "#6");
3977                 }
3978         }
3979
3980         [Test] // Split (String [], Int32, StringSplitOptions)
3981         public void Split6_Count_Negative ()
3982         {
3983                 try {
3984                         "A B".Split (new String [] { "A" }, -1, StringSplitOptions.None);
3985                         Assert.Fail ("#1");
3986                 } catch (ArgumentOutOfRangeException ex) {
3987                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
3988                         Assert.IsNull (ex.InnerException, "#3");
3989                         Assert.IsNotNull (ex.Message, "#4");
3990                         Assert.AreEqual ("count", ex.ParamName, "#5");
3991                 }
3992         }
3993
3994         [Test] // Split (String [], Int32, StringSplitOptions)
3995         public void Split6_Options_Invalid ()
3996         {
3997                 try {
3998                         "A B".Split (new String [] { "A" }, 0, (StringSplitOptions) 4096);
3999                         Assert.Fail ("#1");
4000                 } catch (ArgumentException ex) {
4001                         // Illegal enum value: 4096
4002                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
4003                         Assert.IsNull (ex.InnerException, "#3");
4004                         Assert.IsNotNull (ex.Message, "#4");
4005                         Assert.IsTrue (ex.Message.IndexOf ("4096") != 1, "#5");
4006                         Assert.IsNull (ex.ParamName, "#6");
4007                 }
4008         }
4009
4010         [Test]
4011         public void SplitString ()
4012         {
4013                 String[] res;
4014                 
4015                 // count == 0
4016                 res = "A B C".Split (new String [] { "A" }, 0, StringSplitOptions.None);
4017                 Assert.AreEqual (0, res.Length);
4018
4019                 // empty and RemoveEmpty
4020                 res = string.Empty.Split (new String [] { "A" }, StringSplitOptions.RemoveEmptyEntries);
4021                 Assert.AreEqual (0, res.Length);
4022
4023                 // Not found
4024                 res = "A B C".Split (new String [] { "D" }, StringSplitOptions.None);
4025                 Assert.AreEqual (1, res.Length);
4026                 Assert.AreEqual ("A B C", res [0]);
4027
4028                 // A normal test
4029                 res = "A B C DD E".Split (new String[] { "B", "D" }, StringSplitOptions.None);
4030                 Assert.AreEqual (4, res.Length);
4031                 Assert.AreEqual ("A ", res [0]);
4032                 Assert.AreEqual (" C ", res [1]);
4033                 Assert.AreEqual (string.Empty, res [2]);
4034                 Assert.AreEqual (" E", res [3]);
4035
4036                 // Same with RemoveEmptyEntries
4037                 res = "A B C DD E".Split (new String[] { "B", "D" }, StringSplitOptions.RemoveEmptyEntries);
4038                 Assert.AreEqual (3, res.Length);
4039                 Assert.AreEqual ("A ", res [0]);
4040                 Assert.AreEqual (" C ", res [1]);
4041                 Assert.AreEqual (" E", res [2]);
4042
4043                 // Delimiter matches once at the beginning of the string
4044                 res = "A B".Split (new String [] { "A" }, StringSplitOptions.RemoveEmptyEntries);
4045                 Assert.AreEqual (1, res.Length);
4046                 Assert.AreEqual (" B", res [0]);
4047
4048                 // Delimiter at the beginning and at the end
4049                 res = "B C DD B".Split (new String[] { "B" }, StringSplitOptions.None);
4050                 Assert.AreEqual (3, res.Length);
4051                 Assert.AreEqual (string.Empty, res [0]);
4052                 Assert.AreEqual (" C DD ", res [1]);
4053                 Assert.AreEqual (string.Empty, res [2]);
4054
4055                 res = "B C DD B".Split (new String[] { "B" }, StringSplitOptions.RemoveEmptyEntries);
4056                 Assert.AreEqual (1, res.Length);
4057                 Assert.AreEqual (" C DD ", res [0]);
4058
4059                 // count
4060                 res = "A B C DD E".Split (new String[] { "B", "D" }, 2, StringSplitOptions.None);
4061                 Assert.AreEqual (2, res.Length);
4062                 Assert.AreEqual ("A ", res [0]);
4063                 Assert.AreEqual (" C DD E", res [1]);
4064
4065                 // Ordering
4066                 res = "ABCDEF".Split (new String[] { "EF", "BCDE" }, StringSplitOptions.None);
4067                 Assert.AreEqual (2, res.Length);
4068                 Assert.AreEqual ("A", res [0]);
4069                 Assert.AreEqual ("F", res [1]);
4070
4071                 res = "ABCDEF".Split (new String[] { "BCD", "BC" }, StringSplitOptions.None);
4072                 Assert.AreEqual (2, res.Length);
4073                 Assert.AreEqual ("A", res [0]);
4074                 Assert.AreEqual ("EF", res [1]);
4075
4076                 // Whitespace
4077                 res = "A B\nC".Split ((String[])null, StringSplitOptions.None);
4078                 Assert.AreEqual (3, res.Length);
4079                 Assert.AreEqual ("A", res [0]);
4080                 Assert.AreEqual ("B", res [1]);
4081                 Assert.AreEqual ("C", res [2]);
4082
4083                 res = "A B\nC".Split (new String [0], StringSplitOptions.None);
4084                 Assert.AreEqual (3, res.Length);
4085                 Assert.AreEqual ("A", res [0]);
4086                 Assert.AreEqual ("B", res [1]);
4087                 Assert.AreEqual ("C", res [2]);
4088         }
4089         
4090         [Test]
4091         public void SplitStringChars ()
4092         {
4093                 String[] res;
4094
4095                 // empty
4096                 res = string.Empty.Split (new Char [] { 'A' });
4097                 Assert.AreEqual (1, res.Length);
4098                 Assert.AreEqual (string.Empty, res [0]);
4099
4100                 // empty and RemoveEmpty
4101                 res = string.Empty.Split (new Char [] { 'A' }, StringSplitOptions.RemoveEmptyEntries);
4102                 Assert.AreEqual (0, res.Length);
4103
4104                 // count == 0
4105                 res = "..A..B..".Split (new Char[] { '.' }, 0, StringSplitOptions.None);
4106                 Assert.AreEqual (0, res.Length, "#01-01");
4107
4108                 // count == 1
4109                 res = "..A..B..".Split (new Char[] { '.' }, 1, StringSplitOptions.None);
4110                 Assert.AreEqual (1, res.Length, "#02-01");
4111                 Assert.AreEqual ("..A..B..", res [0], "#02-02");
4112
4113                 // count == 1 + RemoveEmpty
4114                 res = "..A..B..".Split (new Char[] { '.' }, 1, StringSplitOptions.RemoveEmptyEntries);
4115                 Assert.AreEqual (1, res.Length, "#03-01");
4116                 Assert.AreEqual ("..A..B..", res [0], "#03-02");
4117                 
4118                 // Strange Case A+B A
4119                 res = "...".Split (new Char[] { '.' }, 1, StringSplitOptions.RemoveEmptyEntries);
4120                 Assert.AreEqual (1, res.Length, "#ABA-01");
4121                 Assert.AreEqual ("...", res [0], "#ABA-02");
4122
4123                 // Strange Case A+B B
4124                 res = "...".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4125                 Assert.AreEqual (0, res.Length, "#ABB-01");
4126
4127                 // Keeping Empties and multipe split chars
4128                 res = "..A;.B.;".Split (new Char[] { '.', ';' }, StringSplitOptions.None);
4129                 Assert.AreEqual (7, res.Length, "#04-01");
4130                 Assert.AreEqual (string.Empty, res [0], "#04-02");
4131                 Assert.AreEqual (string.Empty, res [1], "#04-03");
4132                 Assert.AreEqual ("A", res [2], "#04-04");
4133                 Assert.AreEqual (string.Empty, res [3], "#04-05");
4134                 Assert.AreEqual ("B", res [4], "#04-06");
4135                 Assert.AreEqual (string.Empty, res [5], "#04-07");
4136                 Assert.AreEqual (string.Empty, res [6], "#04-08");
4137
4138                 // Trimming (3 tests)
4139                 res = "..A".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4140                 Assert.AreEqual (1, res.Length, "#05-01");
4141                 Assert.AreEqual ("A", res [0], "#05-02");
4142                 
4143                 res = "A..".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4144                 Assert.AreEqual (1, res.Length, "#06-01");
4145                 Assert.AreEqual ("A", res [0], "#06-02");
4146                 
4147                 res = "..A..".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4148                 Assert.AreEqual (1, res.Length, "#07-01");
4149                 Assert.AreEqual ("A", res [0], "#07-02");
4150
4151                 // Lingering Tail
4152                 res = "..A..B..".Split (new Char[] { '.' }, 2, StringSplitOptions.RemoveEmptyEntries);
4153                 Assert.AreEqual (2, res.Length, "#08-01");
4154                 Assert.AreEqual ("A", res [0], "#08-02");
4155                 Assert.AreEqual ("B..", res [1], "#08-03");
4156
4157                 // Whitespace and Long split chain (removing empty chars)
4158                 res = "  A\tBC\n\rDEF    GHI  ".Split ((Char[])null, StringSplitOptions.RemoveEmptyEntries);
4159                 Assert.AreEqual (4, res.Length, "#09-01");
4160                 Assert.AreEqual ("A", res [0], "#09-02");
4161                 Assert.AreEqual ("BC", res [1], "#09-03");
4162                 Assert.AreEqual ("DEF", res [2], "#09-04");
4163                 Assert.AreEqual ("GHI", res [3], "#09-05");
4164
4165                 // Nothing but separators
4166                 res = "..,.;.,".Split (new Char[]{'.',',',';'},2,StringSplitOptions.RemoveEmptyEntries);
4167                 Assert.AreEqual (0, res.Length, "#10-01");
4168
4169                 // Complete testseries
4170                 char[] dash = new Char[] { '/' };
4171                 StringSplitOptions o = StringSplitOptions.RemoveEmptyEntries;
4172                 Assert.AreEqual ("hi", "hi".Split (dash, o)[0], "#11-01");
4173                 Assert.AreEqual ("hi", "hi/".Split (dash, o)[0], "#11-02");
4174                 Assert.AreEqual ("hi", "/hi".Split (dash, o)[0], "#11-03");
4175
4176                 Assert.AreEqual ("hi..", "hi../".Split (dash, o)[0], "#11-04-1");
4177                 Assert.AreEqual ("hi..", "/hi..".Split (dash, o)[0], "#11-04-2");
4178
4179                 res = "/hi/..".Split (dash, o);
4180                 Assert.AreEqual ("hi", res[0], "#11-05-1");
4181                 Assert.AreEqual ("..", res[1], "#11-05-2");
4182                 Assert.AreEqual (2, res.Length, "#11-09-3");
4183
4184                 res = "hi/..".Split (dash, o);
4185                 Assert.AreEqual ("hi", res[0], "#11-06-1");
4186                 Assert.AreEqual ("..", res[1], "#11-06-2");
4187                 Assert.AreEqual (2, res.Length, "#11-09-3");
4188
4189                 res = "hi/../".Split (dash, o);
4190                 Assert.AreEqual ("hi", res[0], "#11-07-1");
4191                 Assert.AreEqual ("..", res[1], "#11-07-2");
4192                 Assert.AreEqual (2, res.Length, "#11-07-3");
4193
4194                 res = "/hi../".Split (dash, o);
4195                 Assert.AreEqual ("hi..", res[0], "#11-08-1");
4196                 Assert.AreEqual (1, res.Length, "#11-08-2");
4197
4198                 res = "/hi/../".Split (dash, o);
4199                 Assert.AreEqual ("hi", res[0], "#11-09-1");
4200                 Assert.AreEqual ("..", res[1], "#11-09-2");
4201                 Assert.AreEqual (2, res.Length, "#11-09-3");
4202
4203                 Assert.AreEqual (0, "    ".Split ((char[]) null, 2, StringSplitOptions.RemoveEmptyEntries).Length, "#12-00-0");
4204                 
4205                 res = "not found".Split (new char[2]);
4206                 Assert.AreEqual ("not found", res[0], "#12-04-27");
4207                 Assert.AreEqual (1, res.Length, "#12-04-27-A");
4208         }
4209         
4210         [Test]
4211         public void SplitStringStrings ()
4212         {
4213                 String[] res;
4214
4215                 // count == 0
4216                 res = "..A..B..".Split (new String[] { "." }, 0, StringSplitOptions.None);
4217                 Assert.AreEqual (0, res.Length, "#01-01");
4218
4219                 // count == 1
4220                 res = "..A..B..".Split (new String[] { "." }, 1, StringSplitOptions.None);
4221                 Assert.AreEqual (1, res.Length, "#02-01");
4222                 Assert.AreEqual ("..A..B..", res [0], "#02-02");
4223
4224                 // count == 1 + RemoveEmpty
4225                 res = "..A..B..".Split (new String[] { "." }, 1, StringSplitOptions.RemoveEmptyEntries);
4226                 Assert.AreEqual (1, res.Length, "#03-01");
4227                 Assert.AreEqual ("..A..B..", res [0], "#03-02");
4228                 
4229                 // Strange Case A+B A
4230                 res = "...".Split (new String[] { "." }, 1, StringSplitOptions.RemoveEmptyEntries);
4231                 Assert.AreEqual (1, res.Length, "#ABA-01");
4232                 Assert.AreEqual ("...", res [0], "#ABA-02");
4233
4234                 // Strange Case A+B B
4235                 res = "...".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4236                 Assert.AreEqual (0, res.Length, "#ABB-01");
4237
4238                 // Keeping Empties and multipe split chars
4239                 res = "..A;.B.;".Split (new String[] { ".", ";" }, StringSplitOptions.None);
4240                 Assert.AreEqual (7, res.Length, "#04-01");
4241                 Assert.AreEqual (string.Empty, res [0], "#04-02");
4242                 Assert.AreEqual (string.Empty, res [1], "#04-03");
4243                 Assert.AreEqual ("A", res [2], "#04-04");
4244                 Assert.AreEqual (string.Empty, res [3], "#04-05");
4245                 Assert.AreEqual ("B", res [4], "#04-06");
4246                 Assert.AreEqual (string.Empty, res [5], "#04-07");
4247                 Assert.AreEqual (string.Empty, res [6], "#04-08");
4248
4249                 // Trimming (3 tests)
4250                 res = "..A".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4251                 Assert.AreEqual (1, res.Length, "#05-01");
4252                 Assert.AreEqual ("A", res [0], "#05-02");
4253                 
4254                 res = "A..".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4255                 Assert.AreEqual (1, res.Length, "#06-01");
4256                 Assert.AreEqual ("A", res [0], "#06-02");
4257                 
4258                 res = "..A..".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4259                 Assert.AreEqual (1, res.Length, "#07-01");
4260                 Assert.AreEqual ("A", res [0], "#07-02");
4261
4262                 // Lingering Tail
4263                 res = "..A..B..".Split (new String[] { "." }, 2, StringSplitOptions.RemoveEmptyEntries);
4264                 Assert.AreEqual (2, res.Length, "#08-01");
4265                 Assert.AreEqual ("A", res [0], "#08-02");
4266                 Assert.AreEqual ("B..", res [1], "#08-03");
4267
4268                 // Whitespace and Long split chain (removing empty chars)
4269                 res = "  A\tBC\n\rDEF    GHI  ".Split ((String[])null, StringSplitOptions.RemoveEmptyEntries);
4270                 Assert.AreEqual (4, res.Length, "#09-01");
4271                 Assert.AreEqual ("A", res [0], "#09-02");
4272                 Assert.AreEqual ("BC", res [1], "#09-03");
4273                 Assert.AreEqual ("DEF", res [2], "#09-04");
4274                 Assert.AreEqual ("GHI", res [3], "#09-05");
4275
4276                 // Nothing but separators
4277                 res = "..,.;.,".Split (new String[]{".",",",";"},2,StringSplitOptions.RemoveEmptyEntries);
4278                 Assert.AreEqual (0, res.Length, "#10-01");
4279
4280                 // Complete testseries
4281                 String[] dash = new String[] { "/" };
4282                 StringSplitOptions o = StringSplitOptions.RemoveEmptyEntries;
4283                 Assert.AreEqual ("hi", "hi".Split (dash, o)[0], "#11-01");
4284                 Assert.AreEqual ("hi", "hi/".Split (dash, o)[0], "#11-02");
4285                 Assert.AreEqual ("hi", "/hi".Split (dash, o)[0], "#11-03");
4286
4287                 Assert.AreEqual ("hi..", "hi../".Split (dash, o)[0], "#11-04-1");
4288                 Assert.AreEqual ("hi..", "/hi..".Split (dash, o)[0], "#11-04-2");
4289
4290                 res = "/hi/..".Split (dash, o);
4291                 Assert.AreEqual ("hi", res[0], "#11-05-1");
4292                 Assert.AreEqual ("..", res[1], "#11-05-2");
4293                 Assert.AreEqual (2, res.Length, "#11-09-3");
4294
4295                 res = "hi/..".Split (dash, o);
4296                 Assert.AreEqual ("hi", res[0], "#11-06-1");
4297                 Assert.AreEqual ("..", res[1], "#11-06-2");
4298                 Assert.AreEqual (2, res.Length, "#11-09-3");
4299
4300                 res = "hi/../".Split (dash, o);
4301                 Assert.AreEqual ("hi", res[0], "#11-07-1");
4302                 Assert.AreEqual ("..", res[1], "#11-07-2");
4303                 Assert.AreEqual (2, res.Length, "#11-07-3");
4304
4305                 res = "/hi../".Split (dash, o);
4306                 Assert.AreEqual ("hi..", res[0], "#11-08-1");
4307                 Assert.AreEqual (1, res.Length, "#11-08-2");
4308
4309                 res = "/hi/../".Split (dash, o);
4310                 Assert.AreEqual ("hi", res[0], "#11-09-1");
4311                 Assert.AreEqual ("..", res[1], "#11-09-2");
4312                 Assert.AreEqual (2, res.Length, "#11-09-3");
4313         }
4314
4315         [Test]
4316         [Category ("NotDotNet")]
4317         public void Normalize1 ()
4318         {
4319                 // .NET does not combine them into U+1F80
4320                 // seealso: http://demo.icu-project.org/icu-bin/nbrowser?t=\u03B1\u0313\u0345
4321                 string s = "\u03B1\u0313\u0345";
4322                 Assert.IsTrue (!s.IsNormalized (NormalizationForm.FormC), "#1");
4323                 Assert.IsTrue (!s.IsNormalized (NormalizationForm.FormKC), "#2");
4324                 Assert.AreEqual ("\u1F80", s.Normalize (NormalizationForm.FormC), "#3");
4325                 Assert.AreEqual ("\u1F80", s.Normalize (NormalizationForm.FormKC), "#4");
4326         }
4327
4328         [Test]
4329         [Category ("NotDotNet")]
4330         public void Normalize2 ()
4331         {
4332                 string s1 = "\u0061\u0301bc";
4333                 string s2 = "\u00e1bc";
4334                 // .NET does not combine \u0061\0301 into \u00E1
4335                 // seealso: http://demo.icu-project.org/icu-bin/nbrowser?t=\u0061\u0301bc
4336                 Assert.AreEqual (s2, s1.Normalize (NormalizationForm.FormC), "#1");
4337                 Assert.AreEqual (s2, s1.Normalize (NormalizationForm.FormKC), "#2");
4338         }
4339
4340         [Test]
4341         public void Normalize3 ()
4342         {
4343                 var s = new string (new char [] { '\u064A', '\u064F', '\u0648', '\u0654', '\u0652', '\u064A', '\u064F', '\u0648', '\u0654' });
4344
4345                 var formC = new string (new char [] { '\u064A', '\u064F', '\u0624', '\u0652', '\u064a', '\u064f', '\u0624' });
4346                 var formD = new string (new char [] { '\u064A', '\u064F', '\u0648', '\u0652', '\u0654', '\u064a', '\u064f', '\u0648', '\u0654' });
4347                 var formKC = new string (new char [] { '\u064A', '\u064F', '\u0624', '\u0652', '\u064a', '\u064f', '\u0624' });
4348                 var formKD = new string (new char [] { '\u064A', '\u064F', '\u0648', '\u0652', '\u0654', '\u064a', '\u064f', '\u0648', '\u0654' });
4349
4350                 Assert.AreEqual (formD, s.Normalize (NormalizationForm.FormD), "#1");
4351                 Assert.AreEqual (formC, s.Normalize (NormalizationForm.FormC), "#2");
4352                 Assert.AreEqual (formKD, s.Normalize (NormalizationForm.FormKD), "#3");
4353                 Assert.AreEqual (formKC, s.Normalize (NormalizationForm.FormKC), "#4");
4354         }
4355
4356         [Test] // bug #480152, test cases by David Mitchell
4357         public void NormalizeFormD ()
4358         {
4359                 Assert.AreEqual ("\u212B".Normalize (NormalizationForm.FormD), "\u0041\u030A", "#1");
4360                 Assert.AreEqual ("\u1E69".Normalize (NormalizationForm.FormD), "\u0073\u0323\u0307", "#2");
4361                 Assert.AreEqual ("\u1e4e".Normalize (NormalizationForm.FormD), "\u004f\u0303\u0308", "#3");
4362                 Assert.AreEqual ("\u1e2f".Normalize (NormalizationForm.FormD), "\u0069\u0308\u0301", "#4");
4363         }
4364
4365         [Test] // bug #480152, test cases by David Mitchell
4366         public void NormalizeFormC ()
4367         {
4368                 Assert.AreEqual ("\u0041\u030a\u0061\u030a".Normalize (NormalizationForm.FormC), "\u00c5\u00e5", "#1");
4369                 Assert.AreEqual ("\u006E\u0303".Normalize (NormalizationForm.FormC), "\u00F1", "#2");
4370                 Assert.AreEqual ("\u03B7\u0313\u0300\u0345".Normalize (NormalizationForm.FormC), "\u1F92", "#3");
4371         }
4372
4373         [Test] // bug #480152, test cases by Tom Philpot
4374         public void NormalizeFormCCrashers ()
4375         {
4376                 string[][] entries = new string[][] {
4377                         new string[] { "\u05d0\u0307\u05dc", "#1" },
4378                         new string[] { "\u05d0\u0307\u05dc\u05d9\u05d9\u05df", "#2" },
4379                         new string[] { "\u05d4\u05d0\u0307\u05dc\u0307\u05d9\u0307\u05df\u0307", "#3" },
4380                         new string[] { "\u05d9\u05e9\u05de\u05e2\u0307\u05d0\u0307\u05dc\u0307", "#4" },
4381                         new string[] { "\u05d9\u05e9\u05e8\u05d0\u0307\u05dc\u0307", "#5" },
4382                 };
4383
4384                 foreach (string[] entry in entries)
4385                         entry [0].Normalize (NormalizationForm.FormC);
4386         }
4387
4388         [Test]
4389         public void NormalizeFormCHangul ()
4390         {
4391                 Assert.AreEqual ("\u1100\u116C".Normalize (NormalizationForm.FormC), "\uAD34", "#1");
4392                 Assert.AreEqual ("\u1100\u116B\u11C2".Normalize (NormalizationForm.FormC), "\uAD33", "#2");
4393                 Assert.AreEqual ("\u1100!".Normalize (NormalizationForm.FormC), "\u1100!", "#3");
4394                 Assert.AreEqual ("\u1100\u116B!".Normalize (NormalizationForm.FormC), "\uAD18\u0021", "#4");
4395                 Assert.AreEqual ("!\u116C".Normalize (NormalizationForm.FormC), "!\u116C", "#5");
4396                 Assert.AreEqual ("!\u116B\u11C2".Normalize (NormalizationForm.FormC), "!\u116B\u11C2", "#6");
4397         }
4398
4399         [Test]
4400         public void MoreNormalizeFormC ()
4401         {
4402                 Assert.AreEqual ("\u1E0A\u0323".Normalize (NormalizationForm.FormC), "\u1E0C\u0307", "#1");
4403                 Assert.AreEqual ("\u0044\u0323\u0307".Normalize (NormalizationForm.FormC), "\u1E0C\u0307", "#2");
4404         }
4405
4406         [Test]
4407         public void Emptiness ()
4408         {
4409                 // note: entries using AreEqual are in reality AreNotSame on MS FX
4410                 // but I prefer Mono implementation ;-) and it minimize the changes
4411                 Assert.AreSame (String.Empty, "", "Empty");
4412
4413                 Assert.AreSame (String.Empty, String.Concat ((object) null), "Concat(null)");
4414                 Assert.AreSame (String.Empty, String.Concat ((object) String.Empty), "Concat(empty)");
4415                 Assert.AreSame (String.Empty, String.Concat ((object) String.Empty, (object) String.Empty), "Concat(object,object)");
4416                 Assert.AreSame (String.Empty, String.Concat (String.Empty, String.Empty), "Concat(string,string)");
4417                 Assert.AreEqual (String.Empty, String.Concat (String.Empty, String.Empty, String.Empty), "Concat(string,string,string)");
4418                 Assert.AreEqual (String.Empty, String.Concat ((object) null, (object) (object) null, (object) null, (object) null), "Concat(null,null,null,null)-object");
4419                 Assert.AreSame (String.Empty, String.Concat ((string) null, (string) (string) null, (string) null, (string) null), "Concat(null,null,null,null)-string");
4420                 Assert.AreNotSame (String.Empty, String.Concat (String.Empty, String.Empty, String.Empty, String.Empty), "Concat(string,string,string,string)");
4421                 Assert.AreEqual (String.Empty, String.Concat (new object [] { String.Empty, String.Empty }), "Concat(object[])");
4422                 Assert.AreEqual (String.Empty, String.Concat (new string [] { String.Empty, String.Empty }), "Concat(string[])");
4423
4424                 Assert.AreNotSame (String.Empty, String.Copy (String.Empty), "Copy");
4425
4426                 Assert.AreEqual (String.Empty, "".Insert (0, String.Empty), "Insert(Empty)");
4427                 Assert.AreEqual (String.Empty, String.Empty.Insert (0, ""), "Empty.Insert");
4428
4429                 Assert.AreSame (String.Empty, String.Empty.PadLeft (0), "PadLeft(int)");
4430                 Assert.AreSame (String.Empty, String.Empty.PadLeft (0, '.'), "PadLeft(int.char)");
4431                 Assert.AreSame (String.Empty, String.Empty.PadRight (0), "PadRight(int)");
4432                 Assert.AreSame (String.Empty, String.Empty.PadRight (0, '.'), "PadRight(int.char)");
4433
4434                 Assert.AreSame (String.Empty, "".Substring (0), "Substring(int)");
4435                 Assert.AreSame (String.Empty, "ab".Substring (1, 0), "Substring(int,int)");
4436
4437                 Assert.AreSame (String.Empty, "".ToLower (), "ToLower");
4438                 Assert.AreSame (String.Empty, "".ToUpper (), "ToUpper");
4439                 Assert.AreSame (String.Empty, "".ToLower (CultureInfo.CurrentCulture), "ToLower(CultureInfo)");
4440                 Assert.AreSame (String.Empty, "".ToUpper (CultureInfo.CurrentCulture), "ToUpper(CultureInfo)");
4441                 Assert.AreSame (String.Empty, "".ToLowerInvariant (), "ToLowerInvariant");
4442                 Assert.AreSame (String.Empty, "".ToUpperInvariant (), "ToUpperInvariant");
4443
4444                 Assert.AreSame (String.Empty, "".Trim (), "Trim()");
4445                 Assert.AreSame (String.Empty, "a".Trim ('a'), "Trim(char)");
4446                 Assert.AreSame (String.Empty, "a".TrimEnd ('a'), "TrimEnd(char)");
4447                 Assert.AreSame (String.Empty, "a".TrimStart ('a'), "TrimStart(char)");
4448         }
4449         
4450         [Test]
4451         public void LastIndexOfAndEmptiness () {
4452                 Assert.AreEqual (-1, "".LastIndexOf('.'), "#1");
4453                 Assert.AreEqual (-1, "".LastIndexOf('.', -1), "#2");
4454                 Assert.AreEqual (-1, "".LastIndexOf('.', -1, -1), "#3");
4455                 Assert.AreEqual (0, "x".LastIndexOf('x', 0), "#4");
4456                 Assert.AreEqual (0 , "x".LastIndexOf('x', 0, 1), "#5");
4457                 Assert.AreEqual (-1 , "x".LastIndexOf('z', 0, 1), "#6");
4458
4459                 try {
4460                         "".LastIndexOf(null);
4461                         Assert.Fail ("#7");
4462                 } catch (ArgumentNullException) {}
4463
4464                 Assert.AreEqual (0, "".LastIndexOf(""), "#8");
4465                 Assert.AreEqual (0, "".LastIndexOf("", -1), "#9");
4466                 Assert.AreEqual (0, "".LastIndexOf("", -1, 1), "#10");
4467                 Assert.AreEqual (0, "".LastIndexOf("", StringComparison.Ordinal), "#11");
4468                 Assert.AreEqual (0, "".LastIndexOf("", -1, StringComparison.Ordinal), "#12");
4469                 Assert.AreEqual (0, "".LastIndexOf("", -1, -1, StringComparison.Ordinal), "#13");
4470                 Assert.AreEqual (0, "x".LastIndexOf(""), "#14");
4471
4472                 Assert.AreEqual (0, "x".LastIndexOf("x", 0), "#15");
4473                 Assert.AreEqual (0, "x".LastIndexOf("", 0), "#16");
4474                 Assert.AreEqual (0, "xxxx".LastIndexOf("", 0), "#17");
4475                 Assert.AreEqual (1, "xxxx".LastIndexOf("", 1), "#18");
4476
4477                 Assert.AreEqual (1, "xy".LastIndexOf(""), "#19");
4478                 Assert.AreEqual (2, "xyz".LastIndexOf(""), "#20");
4479                 Assert.AreEqual (1, "xy".LastIndexOf(""), "#21");
4480                 Assert.AreEqual (1, "xy".LastIndexOf("", 2), "#22");
4481                 Assert.AreEqual (2, "xyz".LastIndexOf("", 2), "#23");
4482                 Assert.AreEqual (2, "xyz".LastIndexOf("", 2, 2), "#24");
4483                 Assert.AreEqual (2, "xyz".LastIndexOf("", 3, 3), "#25");
4484
4485                 try {
4486                         "xy".LastIndexOf("", 29);
4487                         Assert.Fail ("#26");
4488                 }catch (ArgumentOutOfRangeException){}
4489
4490                 Assert.AreEqual (-1, "".LastIndexOf("x"), "#27");
4491                 Assert.AreEqual (-1, "".LastIndexOf("x", -1), "#28");
4492                 Assert.AreEqual (-1, "".LastIndexOf("x", -1), "#29");
4493                 Assert.AreEqual (-1, "".LastIndexOf("x", StringComparison.Ordinal), "#30");
4494                 Assert.AreEqual (-1, "".LastIndexOf("x", -1, StringComparison.Ordinal), "#31");
4495                 Assert.AreEqual (-1, "".LastIndexOf("x", -1, -1, StringComparison.Ordinal), "#32");
4496
4497                 Assert.AreEqual (1, "xx".LastIndexOf("", StringComparison.Ordinal), "#33");
4498                 Assert.AreEqual (1, "xx".LastIndexOf("", 2, StringComparison.Ordinal), "#34");
4499                 Assert.AreEqual (1, "xx".LastIndexOf("", 2, 2, StringComparison.Ordinal), "#35");
4500
4501                 Assert.AreEqual (3, "xxxx".LastIndexOf("", StringComparison.Ordinal), "#36");
4502                 Assert.AreEqual (2, "xxxx".LastIndexOf("", 2, StringComparison.Ordinal), "#37");
4503                 Assert.AreEqual (2, "xxxx".LastIndexOf("", 2, 2, StringComparison.Ordinal), "#38");
4504
4505                 Assert.AreEqual (3, "xxxx".LastIndexOf("", 3, StringComparison.Ordinal), "#39");
4506                 Assert.AreEqual (3, "xxxx".LastIndexOf("", 3, 3, StringComparison.Ordinal), "#40");
4507         }
4508         
4509         
4510         [Test]
4511         public void LastIndexOfAnyAndEmptiness () {
4512                 Assert.AreEqual (-1, "".LastIndexOfAny(new char[] {'.', 'x'}), "#1");
4513                 Assert.AreEqual (-1, "".LastIndexOfAny(new char[] {'.', 'x'}, -1), "#2");
4514                 Assert.AreEqual (-1, "".LastIndexOfAny(new char[] {'.', 'x'}, -1, -1), "#3");
4515         }
4516 }
4517
4518 }