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