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