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