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