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