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