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